Ejemplo n.º 1
0
        protected override void OnProcessRecord()
        {
            ServiceManagementProfile.Initialize();

            this.ExecuteClientActionNewSM(
                    null,
                    this.CommandRuntime.ToString(),
                    () =>
                    {
                        OperationResponse op = null;

                        var imageType = new VirtualMachineImageHelper(this.ComputeClient).GetImageType(this.ImageName);
                        bool isOSImage = imageType.HasFlag(VirtualMachineImageType.OSImage);
                        bool isVMImage = imageType.HasFlag(VirtualMachineImageType.VMImage);

                        if (isOSImage && isVMImage)
                        {
                            WriteErrorWithTimestamp(
                                string.Format(Resources.DuplicateNamesFoundInBothVMAndOSImages, this.ImageName));
                        }
                        else if (isVMImage)
                        {
                            op = this.ComputeClient.VirtualMachineVMImages.Delete(this.ImageName, this.DeleteVHD.IsPresent);
                        }
                        else
                        {
                            // Remove the image from the image repository
                            op = this.ComputeClient.VirtualMachineOSImages.Delete(this.ImageName, this.DeleteVHD.IsPresent);
                        }

                        return op;
                    });
        }
Ejemplo n.º 2
0
        protected void GetAzureVMImageProcess()
        {
            ServiceManagementProfile.Initialize();

            if (string.IsNullOrEmpty(this.ImageName))
            {
                this.ExecuteClientActionNewSM(
                    null,
                    this.CommandRuntime.ToString(),
                    () => this.ComputeClient.VirtualMachineOSImages.List(),
                    (s, response) => response.Images.Select(
                        t => this.ContextFactory<VirtualMachineOSImageListResponse.VirtualMachineOSImage, OSImageContext>(t, s)));

                this.ExecuteClientActionNewSM(
                    null,
                    this.CommandRuntime.ToString(),
                    () => this.ComputeClient.VirtualMachineVMImages.List(),
                    (s, response) => response.VMImages.Select(
                        t => this.ContextFactory<VirtualMachineVMImageListResponse.VirtualMachineVMImage, VMImageContext>(t, s)));
            }
            else
            {
                var imageType = new VirtualMachineImageHelper(this.ComputeClient).GetImageType(this.ImageName);
                bool isOSImage = imageType.HasFlag(VirtualMachineImageType.OSImage);
                bool isVMImage = imageType.HasFlag(VirtualMachineImageType.VMImage);

                if (isOSImage || !isVMImage)
                {
                    this.ExecuteClientActionNewSM(
                        null,
                        this.CommandRuntime.ToString(),
                        () => this.ComputeClient.VirtualMachineOSImages.Get(this.ImageName),
                        (s, t) => this.ContextFactory<VirtualMachineOSImageGetResponse, OSImageContext>(t, s));
                }

                if (isVMImage)
                {
                    this.ExecuteClientActionNewSM(
                        null,
                        this.CommandRuntime.ToString(),
                        () => this.ComputeClient.VirtualMachineVMImages.List(),
                        (s, imgs) => imgs
                            .Where(t => string.Equals(t.Name, this.ImageName, StringComparison.OrdinalIgnoreCase))
                            .Select(t => this.ContextFactory<VirtualMachineVMImageListResponse.VirtualMachineVMImage, VMImageContext>(t, s)));
                }
            }
        }
        public void SetAzurePlatformVMImageProcess()
        {
            var imageType = new VirtualMachineImageHelper(this.ComputeClient).GetImageType(this.ImageName);
            isOSImage = imageType.HasFlag(VirtualMachineImageType.OSImage);
            isVMImage = imageType.HasFlag(VirtualMachineImageType.VMImage);

            if (isOSImage && isVMImage)
            {
                WriteErrorWithTimestamp(
                    string.Format(ServiceManagement.Properties.Resources.DuplicateNamesFoundInBothVMAndOSImages, this.ImageName));
            }

            if (this.ParameterSpecified("ReplicaLocations"))
            {
                ProcessReplicateImageParameterSet();
            }
            else if (this.ParameterSpecified("Permission"))
            {
                ProcessShareImageParameterSet();
            }
        }
        protected override void OnProcessRecord()
        {
            ServiceManagementProfile.Initialize();

            var imageType = new VirtualMachineImageHelper(this.ComputeClient).GetImageType(this.ImageName);
            bool isOSImage = imageType.HasFlag(VirtualMachineImageType.OSImage);
            bool isVMImage = imageType.HasFlag(VirtualMachineImageType.VMImage);

            if (isOSImage && isVMImage)
            {
                WriteErrorWithTimestamp(
                    string.Format(Resources.DuplicateNamesFoundInBothVMAndOSImages, this.ImageName));
            }
            else if (isOSImage || !isVMImage)
            {
                ExecuteClientActionNewSM(
                    null,
                    CommandRuntime.ToString(),
                    () =>
                    {
                        this.ComputeClient.VirtualMachineOSImages.Get(this.ImageName);
                        return this.ComputeClient.VirtualMachineOSImages.Unreplicate(this.ImageName);
                    });
            }
            else
            {
                ExecuteClientActionNewSM(
                    null,
                    CommandRuntime.ToString(),
                    () =>
                    {
                        this.ComputeClient.VirtualMachineVMImages.GetDetails(this.ImageName);
                        return this.ComputeClient.VirtualMachineVMImages.Unreplicate(this.ImageName);
                    });
            }
        }
        protected bool ValidateNoImageInOtherType(out Model.VirtualMachineImageType otherType)
        {
            var allTypes = new VirtualMachineImageHelper(this.ComputeClient).GetImageType(this.ImageName);

            otherType = string.IsNullOrEmpty(this.OSState) ? Model.VirtualMachineImageType.VMImage
                                                           : Model.VirtualMachineImageType.OSImage;

            return allTypes == Model.VirtualMachineImageType.None || !allTypes.HasFlag(otherType);
        }
Ejemplo n.º 6
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();

            if (!string.IsNullOrEmpty(this.ImageName))
            {
                var imageType = new VirtualMachineImageHelper(this.ComputeClient).GetImageType(this.ImageName);
                _isOSImage = imageType.HasFlag(VirtualMachineImageType.OSImage);
                _isVMImage = imageType.HasFlag(VirtualMachineImageType.VMImage);

                if (_isOSImage && _isVMImage)
                {
                    var errorMsg = string.Format(Resources.DuplicateNamesFoundInBothVMAndOSImages, this.ImageName);
                    WriteError(new ErrorRecord(new Exception(errorMsg), string.Empty, ErrorCategory.CloseError, null));
                }
            }

            try
            {
                ServiceManagementProfile.Initialize();
                this.ValidateParameters();
                this.NewAzureVMProcess();
            }
            catch (Exception ex)
            {
                WriteError(new ErrorRecord(ex, string.Empty, ErrorCategory.CloseError, null));
            }
        }
        protected override void OnProcessRecord()
        {
            ServiceManagementProfile.Initialize();

            var imageType = new VirtualMachineImageHelper(this.ComputeClient).GetImageType(this.ImageName);
            bool isOSImage = imageType.HasFlag(VirtualMachineImageType.OSImage);
            bool isVMImage = imageType.HasFlag(VirtualMachineImageType.VMImage);

            if (isOSImage || !isVMImage)
            {
                ExecuteClientActionNewSM(
                    null,
                    CommandRuntime.ToString(),
                    () => this.ComputeClient.VirtualMachineOSImages.GetDetails(this.ImageName),
                    (operation, imageDetails) => imageDetails == null ? null : new OSImageDetailsContext
                    {
                        AffinityGroup = imageDetails.AffinityGroup,
                        Category = imageDetails.Category,
                        Label = imageDetails.Label,
                        Location = imageDetails.Location,
                        MediaLink = imageDetails.MediaLinkUri,
                        ImageName = imageDetails.Name,
                        OS = imageDetails.OperatingSystemType,
                        LogicalSizeInGB = (int)imageDetails.LogicalSizeInGB,
                        Eula = imageDetails.Eula,
                        Description = imageDetails.Description,
                        IconUri = imageDetails.IconUri,
                        ImageFamily = imageDetails.ImageFamily,
                        IsPremium = imageDetails.IsPremium,
                        PrivacyUri = imageDetails.PrivacyUri,
                        PublishedDate = imageDetails.PublishedDate,
                        RecommendedVMSize = imageDetails.RecommendedVMSize,
                        IsCorrupted = imageDetails.IsCorrupted,
                        SmallIconUri = imageDetails.SmallIconUri,
                        PublisherName = imageDetails.PublisherName,
                        ReplicationProgress = imageDetails.ReplicationProgress.Select(
                                               detail => new ReplicationProgressContext
                                               {
                                                   Location = detail.Location,
                                                   Progress = detail.Progress
                                               }).ToList(),
                        OperationId = operation.RequestId,
                        OperationDescription = CommandRuntime.ToString(),
                        OperationStatus = operation.Status.ToString()
                    });
            }

            if (isVMImage)
            {
                ExecuteClientActionNewSM(
                    null,
                    CommandRuntime.ToString(),
                    () => this.ComputeClient.VirtualMachineVMImages.GetDetails(this.ImageName),
                    (operation, imageDetails) => imageDetails == null ? null : new VMImageDetailsContext
                    {
                        AffinityGroup = imageDetails.AffinityGroup,
                        Location = imageDetails.Location,
                        Category = imageDetails.Category,
                        Label = imageDetails.Label,
                        ImageName = imageDetails.Name,
                        Eula = imageDetails.Eula,
                        Description = imageDetails.Description,
                        IconUri = imageDetails.IconUri,
                        ImageFamily = imageDetails.ImageFamily,
                        IsPremium = imageDetails.IsPremium,
                        PrivacyUri = imageDetails.PrivacyUri,
                        PublishedDate = imageDetails.PublishedDate,
                        RecommendedVMSize = imageDetails.RecommendedVMSize,
                        IsCorrupted = imageDetails.IsCorrupted,
                        SmallIconUri = imageDetails.SmallIconUri,
                        SharingStatus = imageDetails.SharingStatus,
                        PublisherName = imageDetails.PublisherName,
                        ReplicationProgress = imageDetails.ReplicationProgress.Select(
                                               detail => new ReplicationProgressContext
                                               {
                                                   Location = detail.Location,
                                                   Progress = detail.Progress
                                               }).ToList(),
                        OperationId = operation.RequestId,
                        OperationDescription = CommandRuntime.ToString(),
                        OperationStatus = operation.Status.ToString()
                    });
            }
        }
Ejemplo n.º 8
0
        protected void ValidateParameters()
        {
            if (ParameterSetName.Equals("CreateService", StringComparison.OrdinalIgnoreCase))
            {
                if (string.IsNullOrEmpty(Location) && string.IsNullOrEmpty(AffinityGroup))
                {
                    throw new ArgumentException(Resources.LocationOrAffinityGroupRequiredWhenCreatingNewCloudService);
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(Location) && !string.IsNullOrEmpty(AffinityGroup))
                {
                    throw new ArgumentException(Resources.LocationOrAffinityGroupCanOnlyBeSpecifiedWhenNewCloudService);
                }
                if (!string.IsNullOrEmpty(ReverseDnsFqdn))
                {
                    throw new ArgumentException(Resources.ReverseDnsFqdnCanOnlyBeSpecifiedWhenNewCloudService);
                }
            }

            if (this.ParameterSetName.Equals("CreateService", StringComparison.OrdinalIgnoreCase) == true
             || this.ParameterSetName.Equals("CreateDeployment", StringComparison.OrdinalIgnoreCase) == true)
            {
                if (this.DnsSettings != null && string.IsNullOrEmpty(this.VNetName))
                {
                    throw new ArgumentException(Resources.VNetNameRequiredWhenSpecifyingDNSSettings);
                }
            }

            if (!string.IsNullOrEmpty(this.VNetName))
            {
                List<string> vmNames = new List<string>();
                foreach (Model.PersistentVM VM in this.VMs)
                {
                    Model.NetworkConfigurationSet networkConfig = VM.ConfigurationSets.OfType<Model.NetworkConfigurationSet>().SingleOrDefault();
                    if (networkConfig == null || networkConfig.SubnetNames == null ||
                        networkConfig.SubnetNames.Count == 0)
                    {
                        vmNames.Add(VM.RoleName);
                    }
                }

                if (vmNames.Count != 0)
                {
                    WriteWarning(string.Format(Resources.SubnetShouldBeSpecifiedIfVnetPresent, string.Join(", ", vmNames)));
                }
            }

            this.VMTuples = new Tuple<Model.PersistentVM, bool, bool>[this.VMs.Count()];
            int index = 0;
            foreach (var pVM in this.VMs)
            {
                bool isOSImage = false;
                bool isVMImage = false;

                if (pVM.OSVirtualHardDisk != null && !string.IsNullOrEmpty(pVM.OSVirtualHardDisk.SourceImageName))
                {
                    var imageType = new VirtualMachineImageHelper(this.ComputeClient).GetImageType(
                        pVM.OSVirtualHardDisk.SourceImageName);
                    isOSImage = imageType.HasFlag(Model.VirtualMachineImageType.OSImage);
                    isVMImage = imageType.HasFlag(Model.VirtualMachineImageType.VMImage);
                }

                if (isOSImage && isVMImage)
                {
                    throw new ArgumentException(
                        string.Format(Resources.DuplicateNamesFoundInBothVMAndOSImages, pVM.OSVirtualHardDisk.SourceImageName));
                }

                this.VMTuples[index++] = new Tuple<Model.PersistentVM, bool, bool>(pVM, isOSImage, isVMImage);

                var provisioningConfiguration = pVM.ConfigurationSets
                    .OfType<Model.ProvisioningConfigurationSet>()
                    .SingleOrDefault();
                
                if (isOSImage && provisioningConfiguration == null && pVM.OSVirtualHardDisk.SourceImageName != null)
                {
                    throw new ArgumentException(string.Format(Resources.VMMissingProvisioningConfiguration, pVM.RoleName));
                }
            }
        }
Ejemplo n.º 9
0
        protected override void OnProcessRecord()
        {
            ServiceManagementProfile.Initialize();

            var imageType = new VirtualMachineImageHelper(this.ComputeClient).GetImageType(this.ImageName);
            bool isOSImage = imageType.HasFlag(VirtualMachineImageType.OSImage);
            bool isVMImage = imageType.HasFlag(VirtualMachineImageType.VMImage);

            if (isOSImage && isVMImage)
            {
                WriteErrorWithTimestamp(
                    string.Format(Resources.DuplicateNamesFoundInBothVMAndOSImages, this.ImageName));
            }
            else if (isOSImage)
            {
                var parameters = new VirtualMachineOSImageUpdateParameters
                {
                    Label             = this.Label,
                    Eula              = this.Eula,
                    Description       = this.Description,
                    ImageFamily       = this.ImageFamily,
                    PublishedDate     = this.PublishedDate,
                    PrivacyUri        = this.PrivacyUri,
                    RecommendedVMSize = this.RecommendedVMSize,
                    Language          = this.Language,
                    IconUri           = this.IconUri,
                    SmallIconUri      = this.SmallIconUri,
                    ShowInGui         = this.DontShowInGui.IsPresent ? (bool?)false : null
                };

                this.ExecuteClientActionNewSM(
                    null,
                    this.CommandRuntime.ToString(),
                    () => this.ComputeClient.VirtualMachineOSImages.Update(this.ImageName, parameters),
                    (s, response) => this.ContextFactory<VirtualMachineOSImageUpdateResponse, OSImageContext>(response, s));
            }
            else
            {
                var osDiskConfig    = DiskConfig == null ? null : DiskConfig.OSDiskConfiguration;
                var dataDiskConfigs = DiskConfig == null ? null : DiskConfig.DataDiskConfigurations.ToList();

                var parameters = new VirtualMachineVMImageUpdateParameters
                {
                    Label                  = this.Label,
                    Eula                   = this.Eula,
                    Description            = this.Description,
                    ImageFamily            = this.ImageFamily,
                    PublishedDate          = this.PublishedDate,
                    PrivacyUri             = this.PrivacyUri,
                    RecommendedVMSize      = this.RecommendedVMSize,
                    OSDiskConfiguration    = Mapper.Map<OSDiskConfigurationUpdateParameters>(osDiskConfig),
                    DataDiskConfigurations = dataDiskConfigs == null ? null : dataDiskConfigs.Select(d => new DataDiskConfigurationUpdateParameters
                    {
                        HostCaching       = d.HostCaching,
                        LogicalUnitNumber = d.Lun,
                        Name              = d.Name
                    }).ToList(),
                    Language               = this.Language,
                    IconUri                = this.IconUri,
                    SmallIconUri           = this.SmallIconUri,
                    ShowInGui              = this.DontShowInGui.IsPresent ? (bool?)false : null
                };

                this.ExecuteClientActionNewSM(
                    null,
                    this.CommandRuntime.ToString(),
                    () => this.ComputeClient.VirtualMachineVMImages.Update(this.ImageName, parameters));
            }
        }
Ejemplo n.º 10
0
        public void ExecuteCommand()
        {
            var imageType = new VirtualMachineImageHelper(this.ComputeClient).GetImageType(this.ImageName);
            bool isOSImage = imageType.HasFlag(VirtualMachineImageType.OSImage);
            bool isVMImage = imageType.HasFlag(VirtualMachineImageType.VMImage);

            if (isVMImage)
            {
                // If there is another type of image with the same name,
                // WAPS will stop here to avoid duplicates and potential conflicts
                WriteErrorWithTimestamp(
                    string.Format(
                        Resources.ErrorAnotherImageTypeFoundWithTheSameName,
                        VirtualMachineImageType.VMImage,
                        this.ImageName));
            }
            else
            {
                var parameters = new VirtualMachineOSImageCreateParameters
                {
                    Name = this.ImageName,
                    MediaLinkUri = new Uri(this.MediaLocation),
                    Label = string.IsNullOrEmpty(this.Label) ? this.ImageName : this.Label,
                    OperatingSystemType = this.OS,
                    Eula = this.Eula,
                    Description = this.Description,
                    ImageFamily = this.ImageFamily,
                    PublishedDate = this.PublishedDate,
                    PrivacyUri = this.PrivacyUri,
                    RecommendedVMSize = this.RecommendedVMSize
                };

                this.ExecuteClientActionNewSM(
                    null,
                    this.CommandRuntime.ToString(),
                    () => this.ComputeClient.VirtualMachineOSImages.Create(parameters),
                    (s, response) => this.ContextFactory<VirtualMachineOSImageCreateResponse, OSImageContext>(response, s));
            }
        }