internal VirtualMachineData(ResourceIdentifier id, string name, ResourceType type, SystemData systemData, IDictionary <string, string> tags, AzureLocation location, ExtendedLocation extendedLocation, string kind, SystemAssignedServiceIdentity identity, string resourcePoolId, string templateId, string vCenterId, PlacementProfile placementProfile, OSProfile osProfile, HardwareProfile hardwareProfile, NetworkProfile networkProfile, StorageProfile storageProfile, GuestAgentProfile guestAgentProfile, string moRefId, string inventoryItemId, string moName, string folderPath, string instanceUuid, string smbiosUuid, FirmwareType?firmwareType, string powerState, string customResourceName, string uuid, IReadOnlyList <ResourceStatus> statuses, string provisioningState, string vmId) : base(id, name, type, systemData, tags, location)
 {
     ExtendedLocation   = extendedLocation;
     Kind               = kind;
     Identity           = identity;
     ResourcePoolId     = resourcePoolId;
     TemplateId         = templateId;
     VCenterId          = vCenterId;
     PlacementProfile   = placementProfile;
     OSProfile          = osProfile;
     HardwareProfile    = hardwareProfile;
     NetworkProfile     = networkProfile;
     StorageProfile     = storageProfile;
     GuestAgentProfile  = guestAgentProfile;
     MoRefId            = moRefId;
     InventoryItemId    = inventoryItemId;
     MoName             = moName;
     FolderPath         = folderPath;
     InstanceUuid       = instanceUuid;
     SmbiosUuid         = smbiosUuid;
     FirmwareType       = firmwareType;
     PowerState         = powerState;
     CustomResourceName = customResourceName;
     Uuid               = uuid;
     Statuses           = statuses;
     ProvisioningState  = provisioningState;
     VmId               = vmId;
 }
예제 #2
0
        public async Task Exists()
        {
            var vmName = Recording.GenerateAssetName("testvm");
            var _virtualMachineCollection = await GetVirtualMachineCollectionAsync();

            var _extendedLocation = new ExtendedLocation()
            {
                Name = CustomLocationId,
                ExtendedLocationType = EXTENDED_LOCATION_TYPE
            };
            var _placementProfile = new PlacementProfile()
            {
                ResourcePoolId = _resourcePoolId
            };
            var virtualMachineBody = new VirtualMachineData(DefaultLocation);

            virtualMachineBody.VCenterId        = VcenterId;
            virtualMachineBody.ExtendedLocation = _extendedLocation;
            virtualMachineBody.PlacementProfile = _placementProfile;
            virtualMachineBody.TemplateId       = _vmTemplateId;
            // create virtual machine
            VirtualMachine vm1 = (await _virtualMachineCollection.CreateOrUpdateAsync(WaitUntil.Completed, vmName, virtualMachineBody)).Value;

            Assert.IsNotNull(vm1);
            Assert.AreEqual(vm1.Id.Name, vmName);
            // check for exists virtual machine
            vm1 = await _virtualMachineCollection.GetIfExistsAsync(vmName);

            Assert.AreEqual(vm1.Id.Name, vmName);
        }
        public async Task GetAll()
        {
            var vmName = Recording.GenerateAssetName("testvm");
            var _virtualMachineCollection = await GetVirtualMachineCollectionAsync();

            var _extendedLocation = new ExtendedLocation()
            {
                Name = CustomLocationId,
                Type = EXTENDED_LOCATION_TYPE
            };
            var _placementProfile = new PlacementProfile()
            {
                ResourcePoolId = _resourcePoolId
            };
            var virtualMachineBody = new VirtualMachineData(DefaultLocation);

            virtualMachineBody.VCenterId        = VcenterId;
            virtualMachineBody.ExtendedLocation = _extendedLocation;
            virtualMachineBody.PlacementProfile = _placementProfile;
            virtualMachineBody.TemplateId       = _vmTemplateId;
            // create virtual machine
            VirtualMachine vm1 = (await _virtualMachineCollection.CreateOrUpdateAsync(true, vmName, virtualMachineBody)).Value;

            Assert.IsNotNull(vm1);
            Assert.AreEqual(vm1.Id.Name, vmName);
            int count = 0;

            await foreach (var vm in _virtualMachineCollection.GetAllAsync())
            {
                count++;
            }
            Assert.GreaterOrEqual(count, 1);
        }
예제 #4
0
        internal static VirtualMachineData DeserializeVirtualMachineData(JsonElement element)
        {
            Optional <ExtendedLocation> extendedLocation      = default;
            Optional <string>           kind                  = default;
            Optional <SystemAssignedServiceIdentity> identity = default;
            IDictionary <string, string>             tags     = default;
            AzureLocation                location             = default;
            ResourceIdentifier           id                     = default;
            string                       name                   = default;
            ResourceType                 type                   = default;
            SystemData                   systemData             = default;
            Optional <string>            resourcePoolId         = default;
            Optional <string>            templateId             = default;
            Optional <string>            vCenterId              = default;
            Optional <PlacementProfile>  placementProfile       = default;
            Optional <OSProfile>         osProfile              = default;
            Optional <HardwareProfile>   hardwareProfile        = default;
            Optional <NetworkProfile>    networkProfile         = default;
            Optional <StorageProfile>    storageProfile         = default;
            Optional <GuestAgentProfile> guestAgentProfile      = default;
            Optional <string>            moRefId                = default;
            Optional <string>            inventoryItemId        = default;
            Optional <string>            moName                 = default;
            Optional <string>            folderPath             = default;
            Optional <string>            instanceUuid           = default;
            Optional <string>            smbiosUuid             = default;
            Optional <FirmwareType>      firmwareType           = default;
            Optional <string>            powerState             = default;
            Optional <string>            customResourceName     = default;
            Optional <string>            uuid                   = default;
            Optional <IReadOnlyList <ResourceStatus> > statuses = default;
            Optional <string> provisioningState                 = default;
            Optional <string> vmId = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("extendedLocation"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    extendedLocation = ExtendedLocation.DeserializeExtendedLocation(property.Value);
                    continue;
                }
                if (property.NameEquals("kind"))
                {
                    kind = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("identity"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    identity = JsonSerializer.Deserialize <SystemAssignedServiceIdentity>(property.Value.ToString());
                    continue;
                }
                if (property.NameEquals("tags"))
                {
                    Dictionary <string, string> dictionary = new Dictionary <string, string>();
                    foreach (var property0 in property.Value.EnumerateObject())
                    {
                        dictionary.Add(property0.Name, property0.Value.GetString());
                    }
                    tags = dictionary;
                    continue;
                }
                if (property.NameEquals("location"))
                {
                    location = new AzureLocation(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("id"))
                {
                    id = new ResourceIdentifier(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("name"))
                {
                    name = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("type"))
                {
                    type = new ResourceType(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("systemData"))
                {
                    systemData = JsonSerializer.Deserialize <SystemData>(property.Value.ToString());
                    continue;
                }
                if (property.NameEquals("properties"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    foreach (var property0 in property.Value.EnumerateObject())
                    {
                        if (property0.NameEquals("resourcePoolId"))
                        {
                            resourcePoolId = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("templateId"))
                        {
                            templateId = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("vCenterId"))
                        {
                            vCenterId = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("placementProfile"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            placementProfile = PlacementProfile.DeserializePlacementProfile(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("osProfile"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            osProfile = OSProfile.DeserializeOSProfile(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("hardwareProfile"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            hardwareProfile = HardwareProfile.DeserializeHardwareProfile(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("networkProfile"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            networkProfile = NetworkProfile.DeserializeNetworkProfile(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("storageProfile"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            storageProfile = StorageProfile.DeserializeStorageProfile(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("guestAgentProfile"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            guestAgentProfile = GuestAgentProfile.DeserializeGuestAgentProfile(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("moRefId"))
                        {
                            moRefId = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("inventoryItemId"))
                        {
                            inventoryItemId = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("moName"))
                        {
                            moName = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("folderPath"))
                        {
                            folderPath = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("instanceUuid"))
                        {
                            instanceUuid = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("smbiosUuid"))
                        {
                            smbiosUuid = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("firmwareType"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            firmwareType = new FirmwareType(property0.Value.GetString());
                            continue;
                        }
                        if (property0.NameEquals("powerState"))
                        {
                            powerState = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("customResourceName"))
                        {
                            customResourceName = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("uuid"))
                        {
                            uuid = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("statuses"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            List <ResourceStatus> array = new List <ResourceStatus>();
                            foreach (var item in property0.Value.EnumerateArray())
                            {
                                array.Add(ResourceStatus.DeserializeResourceStatus(item));
                            }
                            statuses = array;
                            continue;
                        }
                        if (property0.NameEquals("provisioningState"))
                        {
                            provisioningState = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("vmId"))
                        {
                            vmId = property0.Value.GetString();
                            continue;
                        }
                    }
                    continue;
                }
            }
            return(new VirtualMachineData(id, name, type, systemData, tags, location, extendedLocation.Value, kind.Value, identity, resourcePoolId.Value, templateId.Value, vCenterId.Value, placementProfile.Value, osProfile.Value, hardwareProfile.Value, networkProfile.Value, storageProfile.Value, guestAgentProfile.Value, moRefId.Value, inventoryItemId.Value, moName.Value, folderPath.Value, instanceUuid.Value, smbiosUuid.Value, Optional.ToNullable(firmwareType), powerState.Value, customResourceName.Value, uuid.Value, Optional.ToList(statuses), provisioningState.Value, vmId.Value));
        }