Exemple #1
0
        public async Task CreateVirtualMachineAsync(CloudProvider provider,
                                                    string infrastructureName, VirtualMachineType dbType,
                                                    string name, Dictionary <string, string> options)
        {
            var parentDirectory = Helpers.Helpers.GetParentDirectory();
            var providerName    = Helpers.Helpers.GetProviderName(provider);

            var infrastructurePath = $"{parentDirectory}/{providerName}/{infrastructureName}";
            var fileName           = $"{infrastructurePath}/VirtualMachine/{name}.json";

            if (!Directory.Exists(infrastructurePath))
            {
                throw new Exception("Infrastructure does not exist");
            }
            else
            {
                if (File.Exists(fileName))
                {
                    throw new Exception("File exists with the same name");
                }
                else
                {
                    using (FileStream fs = File.Create(fileName, 1024))
                    {
                        byte[] info = new UTF8Encoding(true).GetBytes(Helpers.Helpers.ConvertDictionaryToJson(options));
                        await fs.WriteAsync(info, 0, info.Length);
                    }
                }
            }
        }
Exemple #2
0
        public void SetVmType(DbVirtualMachine vm, VirtualMachineType type)
        {
            vm.VmType = (int)type;
            // !! It is important to normalize thngs with ToUpper()
            var node = Directory[vm.Host].Children.Find(x => x.Type == NodeType.VirtualMachines && x.Uuid.ToUpper() == vm.Uuid.ToString().ToUpper());

            node.VmType = new NodeVirtualMachineType(type);
            Update(vm, x => x.Uuid);
        }
Exemple #3
0
        public List <VirtualMachine> GetVm(VirtualMachineType type)
        {
            List <VirtualMachine> res = new List <VirtualMachine>();

            foreach (var c in Directory.Values)
            {
                c.Children.Where(x => x.VmType?.Value == type && x.Type == NodeType.VirtualMachines)
                .ToList().ForEach(x => res.Add((VirtualMachine)x));
            }
            return(res);
        }
        internal static string ToSerializedValue(this VirtualMachineType value)
        {
            switch (value)
            {
            case VirtualMachineType.User:
                return("User");

            case VirtualMachineType.Template:
                return("Template");
            }
            return(null);
        }
 /// <summary>
 /// Converts the <see cref="sourceValue" /> parameter to the <see cref="destinationType" /> parameter using <see cref="formatProvider"
 /// /> and <see cref="ignoreCase" />
 /// </summary>
 /// <param name="sourceValue">the <see cref="System.Object"/> to convert from</param>
 /// <param name="destinationType">the <see cref="System.Type" /> to convert to</param>
 /// <param name="formatProvider">not used by this TypeConverter.</param>
 /// <param name="ignoreCase">when set to <c>true</c>, will ignore the case when converting.</param>
 /// <returns>
 /// an instance of <see cref="VirtualMachineType" />, or <c>null</c> if there is no suitable conversion.
 /// </returns>
 public override object ConvertFrom(object sourceValue, global::System.Type destinationType, global::System.IFormatProvider formatProvider, bool ignoreCase) => VirtualMachineType.CreateFrom(sourceValue);
Exemple #6
0
 public NodeVirtualMachineType(VirtualMachineType type)
 {
     this.Value = type;
 }