示例#1
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();

            if (!string.IsNullOrEmpty(this.ImageName))
            {
                _isOSImage = GetAzureVMImage.CheckImageType(this.ComputeClient, this.ImageName, ImageType.OSImage);
                _isVMImage = GetAzureVMImage.CheckImageType(this.ComputeClient, this.ImageName, ImageType.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));
            }
        }
示例#2
0
        internal bool ValidateImageType(ImageType againstImageType)
        {
            if (GetAzureVMImage.CheckImageType(this.ComputeClient, this.ImageName, againstImageType))
            {
                // If there is another type of image with the same name, WAPS will stop here to avoid duplicates and potential conflicts
                var errorMsg = string.Format(Resources.ErrorAnotherImageTypeFoundWithTheSameName, againstImageType, this.ImageName);
                WriteError(new ErrorRecord(new Exception(errorMsg), string.Empty, ErrorCategory.CloseError, null));

                return(false);
            }

            return(true);
        }
示例#3
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 (this.ParameterSetName.Equals("CreateService", StringComparison.OrdinalIgnoreCase) == true)
            {
                if (!string.IsNullOrEmpty(this.VNetName) && string.IsNullOrEmpty(this.AffinityGroup))
                {
                    throw new ArgumentException(Resources.MustSpecifySameAffinityGroupAsVirtualNetwork);
                }
            }

            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);
                }
            }

            this.VMTuples = new Tuple <PersistentVM, bool, bool> [this.VMs.Count()];
            int index = 0;

            foreach (var pVM in this.VMs)
            {
                bool isOSImage = false;
                bool isVMImage = false;

                if (!string.IsNullOrEmpty(pVM.OSVirtualHardDisk.SourceImageName))
                {
                    isOSImage = GetAzureVMImage.CheckImageType(this.ComputeClient, pVM.OSVirtualHardDisk.SourceImageName, ImageType.OSImage);
                    isVMImage = GetAzureVMImage.CheckImageType(this.ComputeClient, pVM.OSVirtualHardDisk.SourceImageName, ImageType.VMImage);
                }

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

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

                var provisioningConfiguration = pVM.ConfigurationSets
                                                .OfType <Model.PersistentVMModel.ProvisioningConfigurationSet>()
                                                .SingleOrDefault();

                if (isOSImage && provisioningConfiguration == null && pVM.OSVirtualHardDisk.SourceImageName != null)
                {
                    throw new ArgumentException(string.Format(Resources.VMMissingProvisioningConfiguration, pVM.RoleName));
                }
            }
        }