private void ProcessReplicateImageParameterSet()
 {
     if (isVMImage)
     {
         ExecuteClientActionNewSM(
             null,
             CommandRuntime.ToString(),
             () =>
         {
             this.ComputeClient.VirtualMachineVMImages.GetDetails(this.ImageName);
             ValidateTargetLocations();
             return(this.ComputeClient.VirtualMachineVMImages.Replicate(
                        this.ImageName,
                        new Management.Compute.Models.VirtualMachineVMImageReplicateParameters
             {
                 TargetLocations = this.ReplicaLocations == null ? null : this.ReplicaLocations.ToList()
             }));
         });
     }
     else
     {
         ExecuteClientActionNewSM(
             null,
             CommandRuntime.ToString(),
             () =>
         {
             this.ComputeClient.VirtualMachineOSImages.Get(this.ImageName);
             ValidateTargetLocations();
             return(this.ComputeClient.VirtualMachineOSImages.Replicate(this.ImageName, new Management.Compute.Models.VirtualMachineOSImageReplicateParameters
             {
                 TargetLocations = this.ReplicaLocations == null ? null : this.ReplicaLocations.ToList()
             }));
         });
     }
 }
Ejemplo n.º 2
0
 private void ProcessShareImageParameterSet()
 {
     if (isVMImage)
     {
         ExecuteClientActionNewSM(
             null,
             CommandRuntime.ToString(),
             () =>
         {
             this.ComputeClient.VirtualMachineVMImages.GetDetails(this.ImageName);
             return(this.ComputeClient.VirtualMachineVMImages.Share(this.ImageName, this.Permission));
         });
     }
     else
     {
         ExecuteClientActionNewSM(
             null,
             CommandRuntime.ToString(),
             () =>
         {
             this.ComputeClient.VirtualMachineOSImages.GetDetails(this.ImageName);
             return(this.ComputeClient.VirtualMachineOSImages.Share(this.ImageName, this.Permission));
         });
     }
 }
Ejemplo n.º 3
0
        public void ExecuteCommand()
        {
            ValidateParameters();
            ExecuteClientActionNewSM(
                null,
                CommandRuntime.ToString(),
                () => this.ComputeClient.HostedServices.ListExtensions(this.ServiceName),
                (s, r) =>
            {
                var extensionRoleList = (from dr in Deployment.Roles
                                         select new ExtensionRole(dr.RoleName)).ToList().Union(new ExtensionRole[] { new ExtensionRole() });

                return(from role in extensionRoleList
                       from extension in r.Extensions
                       where ExtensionManager.CheckNameSpaceType(extension, ProviderNamespace, ExtensionName) &&
                       ExtensionManager.GetBuilder(Deployment.ExtensionConfiguration).Exist(role, extension.Id)
                       select new DiagnosticExtensionContext
                {
                    OperationId = s.Id,
                    OperationDescription = CommandRuntime.ToString(),
                    OperationStatus = s.Status.ToString(),
                    Extension = extension.Type,
                    ProviderNameSpace = extension.ProviderNamespace,
                    Id = extension.Id,
                    Role = role,
                    StorageAccountName = GetPublicConfigValue(extension, StorageNameElemStr),
                    WadCfg = GetPublicConfigValue(extension, WadCfgElemStr)
                });
            });
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Removes a new firewall rule on the specified server.
        /// </summary>
        /// <param name="serverName">
        /// The name of the server containing the firewall rule.
        /// </param>
        /// <param name="ruleName">
        /// The name of the firewall rule to remove.
        /// </param>
        /// <returns>The context to this operation.</returns>
        internal SqlDatabaseServerOperationContext RemoveAzureSqlDatabaseServerFirewallRuleProcess(string serverName, string ruleName)
        {
            // Do nothing if force is not specified and user cancelled the operation
            if (!Force.IsPresent &&
                !ShouldProcess(
                    string.Format(CultureInfo.InvariantCulture, Resources.RemoveAzureSqlDatabaseServerFirewallRuleDescription, ruleName, serverName),
                    string.Format(CultureInfo.InvariantCulture, Resources.RemoveAzureSqlDatabaseServerFirewallRuleWarning, ruleName, serverName),
                    Resources.ShouldProcessCaption))
            {
                return(null);
            }

            // Get the SQL management client for the current subscription
            SqlManagementClient sqlManagementClient = GetCurrentSqlClient();

            // Delete the specified firewall rule.
            OperationResponse response = sqlManagementClient.FirewallRules.Delete(serverName, ruleName);

            SqlDatabaseServerOperationContext operationContext = new SqlDatabaseServerOperationContext()
            {
                OperationStatus      = Services.Constants.OperationSuccess,
                OperationDescription = CommandRuntime.ToString(),
                OperationId          = response.RequestId,
                ServerName           = serverName
            };

            return(operationContext);
        }
Ejemplo n.º 5
0
        public void RemoveVMImageProcess()
        {
            try
            {
                Uri mediaLink = null;
                if (this.DeleteVHD.IsPresent)
                {
                    // Get the location of the underlying VHD
                    using (new OperationContextScope(Channel.ToContextChannel()))
                    {
                        var image = this.RetryCall(s => this.Channel.GetOSImage(s, this.ImageName));
                        mediaLink = image.MediaLink;
                    }
                }

                // Remove the image from the image repository
                using (new OperationContextScope(Channel.ToContextChannel()))
                {
                    ExecuteClientAction(null, CommandRuntime.ToString(), s => this.Channel.DeleteOSImage(s, this.ImageName));
                }

                if (this.DeleteVHD.IsPresent)
                {
                    // Remove the underlying VHD from the blob storage
                    Disks.RemoveVHD(this.Channel, CurrentSubscription.SubscriptionId, mediaLink);
                }
            }
            catch (ServiceManagementClientException ex)
            {
                this.WriteErrorDetails(ex);
            }
        }
Ejemplo n.º 6
0
        public void ExecuteCommand()
        {
            ServiceManagementProfile.Initialize();

            var truePred = (Func <ExtensionImage, bool>)(s => true);

            Func <string, Func <ExtensionImage, string>,
                  Func <ExtensionImage, bool> > predFunc =
                (x, f) => string.IsNullOrEmpty(x) ? truePred : s => string.Equals(x, f(s), StringComparison.OrdinalIgnoreCase);

            var typePred      = predFunc(this.ExtensionName, s => s.Type);
            var nameSpacePred = predFunc(this.ProviderNamespace, s => s.ProviderNameSpace);
            var versionPred   = predFunc(this.Version, s => s.Version);

            ExecuteClientActionNewSM(null,
                                     CommandRuntime.ToString(),
                                     () =>
            {
                if (AllVersions.IsPresent || !string.IsNullOrEmpty(this.Version))
                {
                    return(this.ComputeClient.HostedServices.ListExtensionVersions(this.ProviderNamespace, this.ExtensionName));
                }
                else
                {
                    return(this.ComputeClient.HostedServices.ListAvailableExtensions());
                }
            },
                                     (op, response) => response.Where(typePred).Where(nameSpacePred).Where(versionPred).Select(
                                         extension => ContextFactory <ExtensionImage, ExtensionImageContext>(extension, op)));
        }
        protected override void OnProcessRecord()
        {
            ServiceManagementProfile.Initialize();

            if (this.Abort.IsPresent)
            {
                ExecuteClientActionNewSM(
                    null,
                    CommandRuntime.ToString(),
                    () => this.NetworkClient.Networks.AbortMigration(this.VirtualNetworkName));
            }
            else if (this.Commit.IsPresent)
            {
                ExecuteClientActionNewSM(
                    null,
                    CommandRuntime.ToString(),
                    () => this.NetworkClient.Networks.CommitMigration(this.VirtualNetworkName));
            }
            else
            {
                ExecuteClientActionNewSM(
                    null,
                    CommandRuntime.ToString(),
                    () => this.NetworkClient.Networks.PrepareMigration(this.VirtualNetworkName));
            }
        }
Ejemplo n.º 8
0
        private void CreateSite(WebSpace webspace, SiteWithWebSpace website)
        {
            try
            {
                InvokeInOperationContext(() => RetryCall(s => Channel.CreateSite(s, webspace.Name, website)));

                Cache.AddSite(CurrentSubscription.SubscriptionId, website);
                SiteConfig websiteConfiguration = null;
                InvokeInOperationContext(() =>
                {
                    websiteConfiguration = RetryCall(s => Channel.GetSiteConfig(s, website.WebSpace, website.Name));
                    WaitForOperation(CommandRuntime.ToString());
                });
                WriteObject(new SiteWithConfig(website, websiteConfiguration));
            }
            catch (ProtocolException ex)
            {
                // Handle site creating indepently so that cmdlet is idempotent.
                string message = ProcessException(ex, false);
                if (message.Equals(string.Format(Resources.WebsiteAlreadyExistsReplacement,
                                                 Name)) && (Git || GitHub))
                {
                    WriteWarning(message);
                }
                else if (message.Equals(Resources.DefaultHostnamesValidation))
                {
                    WriteExceptionError(new Exception(Resources.InvalidHostnameValidation));
                }
                else
                {
                    WriteExceptionError(new Exception(message));
                }
            }
        }
Ejemplo n.º 9
0
        protected T2 ContextFactory <T1, T2>(T1 source) where T2 : ManagementOperationContext
        {
            var context = Mapper.Map <T1, T2>(source);

            context.OperationDescription = CommandRuntime.ToString();
            return(context);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Creates a new firewall rule on the specified server.
        /// </summary>
        /// <param name="parameterSetName">The parameter set for the command.</param>
        /// <param name="serverName">The name of the server in which to create the firewall rule.</param>
        /// <param name="ruleName">The name of the new firewall rule.</param>
        /// <param name="startIpAddress">The starting IP address for the firewall rule.</param>
        /// <param name="endIpAddress">The ending IP address for the firewall rule.</param>
        /// <returns>The context to the newly created firewall rule.</returns>
        internal SqlDatabaseServerFirewallRuleContext NewAzureSqlDatabaseServerFirewallRuleProcess(
            string parameterSetName,
            string serverName,
            string ruleName,
            string startIpAddress,
            string endIpAddress)
        {
            // Get the SQL management client for the current subscription
            SqlManagementClient sqlManagementClient = SqlDatabaseCmdletBase.GetCurrentSqlClient();

            // Create the firewall rule
            FirewallRuleCreateResponse response = sqlManagementClient.FirewallRules.Create(
                serverName,
                new FirewallRuleCreateParameters()
            {
                Name           = ruleName,
                StartIPAddress = startIpAddress,
                EndIPAddress   = endIpAddress,
            });

            SqlDatabaseServerFirewallRuleContext operationContext = new SqlDatabaseServerFirewallRuleContext()
            {
                OperationDescription = CommandRuntime.ToString(),
                OperationStatus      = Services.Constants.OperationSuccess,
                OperationId          = response.RequestId,
                ServerName           = serverName,
                RuleName             = ruleName,
                StartIpAddress       = response.StartIPAddress,
                EndIpAddress         = response.EndIPAddress,
            };

            return(operationContext);
        }
Ejemplo n.º 11
0
        protected override void OnProcessRecord()
        {
            ServiceManagementProfile.Initialize();

            var parameters = new LoadBalancerCreateParameters
            {
                Name = this.InternalLoadBalancerName,
                FrontendIPConfiguration = new FrontendIPConfiguration
                {
                    Type       = FrontendIPConfigurationType.Private,
                    SubnetName = this.SubnetName,
                    StaticVirtualNetworkIPAddress = this.StaticVNetIPAddress == null ? null
                                                  : this.StaticVNetIPAddress.ToString()
                }
            };

            ExecuteClientActionNewSM(null,
                                     CommandRuntime.ToString(),
                                     () =>
            {
                var deploymentName = this.ComputeClient.Deployments.GetBySlot(
                    this.ServiceName,
                    DeploymentSlot.Production).Name;

                return(this.ComputeClient.LoadBalancers.Create(
                           this.ServiceName,
                           deploymentName,
                           parameters));
            });
        }
        private void ProcessRemoveAssociation()
        {
            ServiceManagementProfile.Initialize();

            var slotType = string.IsNullOrEmpty(this.Slot) ?
                           DeploymentSlot.Production :
                           (DeploymentSlot)Enum.Parse(typeof(DeploymentSlot), this.Slot, true);


            string deploymentName = this.ComputeClient.Deployments.GetBySlot(
                this.ServiceName,
                slotType).Name;

            ExecuteClientActionNewSM(
                null,
                CommandRuntime.ToString(),
                () =>
            {
                var parameters = new NetworkReservedIPMobilityParameters
                {
                    ServiceName    = this.ServiceName,
                    DeploymentName = deploymentName,
                    VirtualIPName  = this.VirtualIPName
                };

                return(this.NetworkClient.ReservedIPs.Disassociate(this.ReservedIPName, parameters));
            });
        }
        protected void ValidateThumbprint(bool uploadCert)
        {
            if (X509Certificate != null)
            {
                var operationDescription = string.Format(Resources.ServiceExtensionUploadingCertificate, CommandRuntime, X509Certificate.Thumbprint);
                if (uploadCert)
                {
                    var parameters = new ServiceCertificateCreateParameters
                    {
                        Data              = CertUtilsNewSM.GetCertificateData(X509Certificate),
                        Password          = null,
                        CertificateFormat = CertificateFormat.Pfx
                    };

                    ExecuteClientActionNewSM(
                        null,
                        CommandRuntime.ToString(),
                        () => this.ComputeClient.ServiceCertificates.Create(this.ServiceName, parameters));
                }

                CertificateThumbprint = X509Certificate.Thumbprint;
            }
            else
            {
                CertificateThumbprint = CertificateThumbprint ?? string.Empty;
            }

            ThumbprintAlgorithm = ThumbprintAlgorithm ?? string.Empty;
        }
Ejemplo n.º 14
0
        protected bool DoesCloudServiceExist(string serviceName)
        {
            bool isPresent = false;

            using (new OperationContextScope(Channel.ToContextChannel()))
            {
                try
                {
                    WriteVerboseWithTimestamp(string.Format("Begin Operation: {0}", CommandRuntime.ToString()));
                    AvailabilityResponse response = this.RetryCall(s => this.Channel.IsDNSAvailable(s, serviceName));
                    WriteVerboseWithTimestamp(string.Format("Completed Operation: {0}", CommandRuntime.ToString()));
                    isPresent = !response.Result;
                }
                catch (ServiceManagementClientException ex)
                {
                    if (ex.HttpStatus == HttpStatusCode.NotFound)
                    {
                        isPresent = false;
                    }
                    else
                    {
                        this.WriteErrorDetails(ex);
                    }
                }
            }

            return(isPresent);
        }
Ejemplo n.º 15
0
        protected override void ProcessRecord()
        {
            ServiceManagementProfile.Initialize();

            var dnsUpdateParameters = new DNSUpdateParameters()
            {
                Address = this.IPAddress,
                Name    = this.Name
            };

            ExecuteClientActionNewSM(null,
                                     CommandRuntime.ToString(),
                                     () =>
            {
                var deploymentName = this.ComputeClient.Deployments.GetBySlot(
                    this.ServiceName,
                    DeploymentSlot.Production).Name;

                return(this.ComputeClient.DnsServer.UpdateDNSServer(
                           this.ServiceName,
                           deploymentName,
                           dnsUpdateParameters.Name,
                           dnsUpdateParameters));
            });
        }
Ejemplo n.º 16
0
        protected override void OnProcessRecord()
        {
            ServiceManagementProfile.Initialize();
            string deploymentName = string.Empty;

            if (!string.IsNullOrEmpty(this.ServiceName))
            {
                var slotType = string.IsNullOrEmpty(this.Slot) ?
                               DeploymentSlot.Production :
                               (DeploymentSlot)Enum.Parse(typeof(DeploymentSlot), this.Slot, true);


                deploymentName = this.ComputeClient.Deployments.GetBySlot(
                    this.ServiceName,
                    slotType).Name;
            }

            ExecuteClientActionNewSM(
                null,
                CommandRuntime.ToString(),
                () =>
            {
                var parameters = new NetworkReservedIPCreateParameters
                {
                    Name           = this.ReservedIPName,
                    Label          = this.Label,
                    Location       = this.Location,
                    ServiceName    = this.ServiceName,
                    DeploymentName = deploymentName,
                    VirtualIPName  = this.VirtualIPName
                };

                return(this.NetworkClient.ReservedIPs.Create(parameters));
            });
        }
        protected override void OnProcessRecord()
        {
            ServiceManagementPlatformImageRepositoryProfile.Initialize();

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

                bool found      = ExtensionExists();
                var publishCnfm = Resources.ExtensionPublishingConfirmation;
                var publishCptn = Resources.ExtensionPublishingCaption;
                var upgradeCnfm = Resources.ExtensionUpgradingConfirmation;
                var upgradeCptn = Resources.ExtensionUpgradingCaption;

                this.IsInternalExtension = string.Equals(this.ExtensionMode, PublicModeStr) ? false
                                             : string.Equals(this.ExtensionMode, InternalModeStr) ? true
                                             : true;

                if (found && (this.Force.IsPresent || this.ShouldContinue(upgradeCnfm, upgradeCptn)))
                {
                    var parameters = Mapper.Map <ExtensionImageUpdateParameters>(this);
                    op             = this.ComputeClient.ExtensionImages.Update(parameters);
                }
                else if (!found && (this.Force.IsPresent || this.ShouldContinue(publishCnfm, publishCptn)))
                {
                    var parameters = Mapper.Map <ExtensionImageRegisterParameters>(this);
                    op             = this.ComputeClient.ExtensionImages.Register(parameters);
                }

                return(op);
            });
        }
Ejemplo n.º 18
0
 public void GetLocationsProcess()
 {
     ExecuteClientActionNewSM(null,
                              CommandRuntime.ToString(),
                              () => this.ManagementClient.Locations.List(),
                              (op, locations) => locations.Locations.Select(location => ContextFactory <LocationsListResponse.Location, LocationsContext>(location, op)));
 }
Ejemplo n.º 19
0
        protected override void OnProcessRecord()
        {
            Func <Operation, IEnumerable <AffinityGroup>, object> func = (operation, affinityGroups) =>
                                                                         affinityGroups.Select(affinityGroup => new AffinityGroupContext()
            {
                OperationId          = operation.OperationTrackingId,
                OperationDescription = CommandRuntime.ToString(),
                OperationStatus      = operation.Status,
                Name           = affinityGroup.Name,
                Label          = string.IsNullOrEmpty(affinityGroup.Label) ? null : affinityGroup.Label,
                Description    = affinityGroup.Description,
                Location       = affinityGroup.Location,
                HostedServices = affinityGroup.HostedServices != null ? affinityGroup.HostedServices.Select(p => new AffinityGroupContext.Service {
                    Url = p.Url, ServiceName = p.ServiceName
                }) : new AffinityGroupContext.Service[0],
                StorageServices = affinityGroup.StorageServices != null ? affinityGroup.StorageServices.Select(p => new AffinityGroupContext.Service {
                    Url = p.Url, ServiceName = p.ServiceName
                }) : new AffinityGroupContext.Service[0]
            });

            if (this.Name != null)
            {
                ExecuteClientActionInOCS(null, CommandRuntime.ToString(), s => this.Channel.GetAffinityGroup(s, this.Name), (operation, affinityGroups) => func(operation, new[] { affinityGroups }));
            }
            else
            {
                ExecuteClientActionInOCS(null, CommandRuntime.ToString(), s => this.Channel.ListAffinityGroups(s), (operation, affinityGroups) => func(operation, affinityGroups));
            }
        }
Ejemplo n.º 20
0
        protected override void OnProcessRecord()
        {
            ServiceManagementProfile.Initialize();

            if (this.ServiceName != null)
            {
                ExecuteClientActionNewSM(null,
                                         CommandRuntime.ToString(),
                                         () => this.ComputeClient.HostedServices.Get(this.ServiceName),
                                         (operation, service) =>
                {
                    var context = ContextFactory <HostedServiceGetResponse, HostedServiceDetailedContext>(service, operation);
                    Mapper.Map(service.Properties, context);
                    return(context);
                });
            }
            else
            {
                ExecuteClientActionNewSM(null,
                                         CommandRuntime.ToString(),
                                         () => this.ComputeClient.HostedServices.List(),
                                         (operation, services) => services.HostedServices.Select(
                                             service =>
                {
                    var context = ContextFactory <HostedServiceListResponse.HostedService, HostedServiceDetailedContext>(service, operation);
                    Mapper.Map(service.Properties, context);
                    return(context);
                }));
            }
        }
        public virtual void ExecuteCommand()
        {
            ServiceManagementProfile.Initialize();

            Func <VirtualMachineExtensionListResponse.ResourceExtension, bool> truePred = s => true;

            Func <string, Func <VirtualMachineExtensionListResponse.ResourceExtension, string>,
                  Func <VirtualMachineExtensionListResponse.ResourceExtension, bool> > predFunc =
                (x, f) => string.IsNullOrEmpty(x) ? truePred : s => string.Equals(x, f(s), StringComparison.OrdinalIgnoreCase);

            var typePred      = predFunc(this.ExtensionName, s => s.Name);
            var publisherPred = predFunc(this.Publisher, s => s.Publisher);
            var versionPred   = predFunc(this.Version, s => s.Version);

            ExecuteClientActionNewSM(null,
                                     CommandRuntime.ToString(),
                                     () =>
            {
                if (this.AllVersions.IsPresent || !string.IsNullOrEmpty(this.Version))
                {
                    return(this.ComputeClient.VirtualMachineExtensions.ListVersions(this.Publisher, this.ExtensionName));
                }
                else
                {
                    return(this.ComputeClient.VirtualMachineExtensions.List());
                }
            },
                                     (op, response) => response.Where(typePred).Where(publisherPred).Where(versionPred).Select(
                                         extension => ContextFactory <VirtualMachineExtensionListResponse.ResourceExtension, VirtualMachineExtensionImageContext>(extension, op)));
        }
Ejemplo n.º 22
0
        public void SetRoleInstanceCountProcess()
        {
            OperationStatusResponse operation;
            var currentDeployment = this.GetCurrentDeployment(out operation);

            if (currentDeployment == null)
            {
                return;
            }

            XNamespace ns            = "http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration";
            var        configuration = XDocument.Parse(currentDeployment.Configuration);
            var        role          = configuration.Root.Elements(ns + "Role").SingleOrDefault(p => string.Compare(p.Attribute("name").Value, this.RoleName, true) == 0);

            if (role != null)
            {
                role.Element(ns + "Instances").SetAttributeValue("count", this.Count);
            }

            var updatedConfigurationParameter = new DeploymentChangeConfigurationParameters
            {
                Configuration = configuration.ToString()
            };
            DeploymentSlot slot;

            if (!Enum.TryParse(this.Slot, out slot))
            {
                throw new ArgumentOutOfRangeException("Slot");
            }
            ExecuteClientActionNewSM(configuration,
                                     CommandRuntime.ToString(),
                                     () => this.ComputeClient.Deployments.ChangeConfigurationBySlot(this.ServiceName, slot, updatedConfigurationParameter));
        }
Ejemplo n.º 23
0
        internal void ExecuteCommand()
        {
            var disk = new Disk
            {
                Name  = this.DiskName,
                Label = this.Label
            };

            ExecuteClientActionInOCS(
                disk,
                CommandRuntime.ToString(),
                s => this.Channel.UpdateDisk(s, this.DiskName, disk),
                (op, responseDisk) => new DiskContext
            {
                DiskName             = responseDisk.Name,
                Label                = responseDisk.Label,
                IsCorrupted          = responseDisk.IsCorrupted,
                AffinityGroup        = responseDisk.AffinityGroup,
                OS                   = responseDisk.OS,
                Location             = responseDisk.Location,
                MediaLink            = responseDisk.MediaLink,
                DiskSizeInGB         = responseDisk.LogicalDiskSizeInGB,
                SourceImageName      = responseDisk.SourceImageName,
                AttachedTo           = CreateRoleReference(responseDisk.AttachedTo),
                OperationDescription = CommandRuntime.ToString(),
                OperationId          = op.OperationTrackingId,
                OperationStatus      = op.Status
            });
        }
        protected override void OnProcessRecord()
        {
            ServiceManagementPlatformImageRepositoryProfile.Initialize();

            ExecuteClientActionNewSM(
                null,
                CommandRuntime.ToString(),
                () =>
            {
                var publisherExtension = this.ComputeClient.HostedServices
                                         .ListPublisherExtensions()
                                         .FirstOrDefault(e => e.ProviderNameSpace.Equals(this.Publisher) &&
                                                         e.Type.Equals(this.ExtensionName) &&
                                                         e.Version.Equals(this.Version));

                if (publisherExtension != null)
                {
                    IsJsonExtension      = publisherExtension.IsJsonExtension;
                    IsInternalExtension  = publisherExtension.IsInternalExtension;
                    BlockRoleUponFailure = publisherExtension.BlockRoleUponFailure;
                }

                if (!string.IsNullOrEmpty(this.ExtensionMode))
                {
                    this.IsInternalExtension = this.ExtensionMode.Equals(InternalModeStr);
                }

                var parameters = Mapper.Map <ExtensionImageUpdateParameters>(this);

                return(this.ComputeClient.ExtensionImages.Update(parameters));
            });
        }
        protected override void OnProcessRecord()
        {
            ServiceManagementProfile.Initialize();

            if (!string.IsNullOrEmpty(this.StorageAccountName))
            {
                ExecuteClientActionNewSM(
                    null,
                    CommandRuntime.ToString(),
                    () => this.StorageClient.StorageAccounts.Get(this.StorageAccountName),
                    (s, response) =>
                {
                    var context = ContextFactory <StorageServiceGetResponse, StorageServicePropertiesOperationContext>(response, s);
                    Mapper.Map(response.Properties, context);
                    return(context);
                });
            }
            else
            {
                ExecuteClientActionNewSM(
                    null,
                    CommandRuntime.ToString(),
                    () => this.StorageClient.StorageAccounts.List(),
                    (s, storageServices) =>
                    storageServices.StorageServices.Select(r =>
                {
                    var context = ContextFactory <StorageServiceListResponse.StorageService, StorageServicePropertiesOperationContext>(r, s);
                    Mapper.Map(r.Properties, context);
                    return(context);
                }));
            }
        }
Ejemplo n.º 26
0
        public void ExecuteCommand()
        {
            var prodDeployment    = GetDeploymentBySlot(DeploymentSlotType.Production);
            var stagingDeployment = GetDeploymentBySlot(DeploymentSlotType.Staging);

            if (stagingDeployment == null && prodDeployment == null)
            {
                throw new ArgumentOutOfRangeException(String.Format(Resources.NoDeploymentInStagingOrProduction, ServiceName));
            }

            if (stagingDeployment == null && prodDeployment != null)
            {
                throw new ArgumentOutOfRangeException(String.Format(Resources.NoDeploymentInStaging, ServiceName));
            }

            if (prodDeployment == null)
            {
                this.WriteVerbose(string.Format(Resources.MovingDeploymentFromStagingToProduction, ServiceName));
            }
            else
            {
                this.WriteVerbose(string.Format(Resources.VIPSwapBetweenStagingAndProduction, ServiceName));
            }

            var swapDeploymentParams = new DeploymentSwapParameters
            {
                SourceDeployment     = stagingDeployment.Name,
                ProductionDeployment = prodDeployment == null ? null : prodDeployment.Name
            };

            ExecuteClientActionNewSM(
                swapDeploymentParams,
                CommandRuntime.ToString(),
                () => this.ComputeClient.Deployments.Swap(ServiceName, swapDeploymentParams));
        }
 public void ExecuteCommand()
 {
     ValidateParameters();
     ExecuteClientActionInOCS(null,
                              CommandRuntime.ToString(),
                              s => this.Channel.ListHostedServiceExtensions(CurrentSubscription.SubscriptionId, ServiceName),
                              (op, extensions) =>
     {
         var extensionRoleList = (from r in Deployment.RoleList
                                  select new ExtensionRole(r.RoleName)).ToList().Union(new ExtensionRole[] { new ExtensionRole() });
         return(from role in extensionRoleList
                from extension in extensions
                where ExtensionManager.CheckExtensionType(extension.Id, ExtensionNameSpace, ExtensionType) &&
                ExtensionManager.GetBuilder(Deployment.ExtensionConfiguration).Exist(role, extension.Id)
                select new RemoteDesktopExtensionContext
         {
             OperationId = op.OperationTrackingId,
             OperationDescription = CommandRuntime.ToString(),
             OperationStatus = op.Status,
             Extension = extension.Type,
             ProviderNameSpace = extension.ProviderNameSpace,
             Id = extension.Id,
             Role = role,
             UserName = GetPublicConfigValue(extension, UserNameElemStr),
             Expiration = GetPublicConfigValue(extension, ExpirationElemStr)
         });
     });
 }
Ejemplo n.º 28
0
        public void RemoveDeploymentProcess()
        {
            ServiceManagementProfile.Initialize();

            var slotType = (DeploymentSlot)Enum.Parse(typeof(DeploymentSlot), this.Slot, true);

            DeploymentGetResponse deploymentGetResponse = this.ComputeClient.Deployments.GetBySlot(this.ServiceName, slotType);

            if (deploymentGetResponse != null && !string.IsNullOrEmpty(deploymentGetResponse.ReservedIPName))
            {
                WriteVerboseWithTimestamp(string.Format(Resources.ReservedIPNameNoLongerInUseByDeploymentButStillBeingReserved, deploymentGetResponse.ReservedIPName));
            }
            if (DeleteVHD.IsPresent)
            {
                ExecuteClientActionNewSM(
                    null,
                    CommandRuntime.ToString(),
                    () => this.ComputeClient.Deployments.DeleteByName(this.ServiceName, deploymentGetResponse.Name, DeleteVHD.IsPresent));
            }
            else
            {
                ExecuteClientActionNewSM(
                    null,
                    CommandRuntime.ToString(),
                    () => this.ComputeClient.Deployments.DeleteBySlot(this.ServiceName, slotType));
            }
        }
Ejemplo n.º 29
0
        public void ExecuteCommand()
        {
            var prodDeployment    = GetDeploymentBySlot(DeploymentSlotType.Production);
            var stagingDeployment = GetDeploymentBySlot(DeploymentSlotType.Staging);

            if (stagingDeployment == null && prodDeployment == null)
            {
                throw new ArgumentOutOfRangeException(String.Format("No deployment found in Staging or Production: {0}", ServiceName));
            }

            if (stagingDeployment == null && prodDeployment != null)
            {
                throw new ArgumentOutOfRangeException(String.Format("No deployment found in Staging: {0}", ServiceName));
            }

            if (prodDeployment == null)
            {
                this.WriteVerbose(string.Format("Moving deployment from Staging to Production:{0}", ServiceName));
            }
            else
            {
                this.WriteVerbose(string.Format("VIP Swap is taking place between Staging and Production deployments.:{0}", ServiceName));
            }

            var swapDeploymentInput = new SwapDeploymentInput
            {
                SourceDeployment = stagingDeployment.Name,
                Production       = prodDeployment == null ? null : prodDeployment.Name
            };

            ExecuteClientActionInOCS(swapDeploymentInput, CommandRuntime.ToString(), s => this.Channel.SwapDeployment(s, this.ServiceName, swapDeploymentInput));
        }
Ejemplo n.º 30
0
        internal override void ExecuteCommand()
        {
            ServiceManagementProfile.Initialize();

            base.ExecuteCommand();
            if (CurrentDeploymentNewSM == null)
            {
                return;
            }

            DeploymentGetResponse deploymentResponse = this.ComputeClient.Deployments.GetBySlot(this.ServiceName, DeploymentSlot.Production);

            if (deploymentResponse.Roles.FirstOrDefault(r => r.RoleName.Equals(Name, StringComparison.InvariantCultureIgnoreCase)) == null)
            {
                throw new ArgumentOutOfRangeException(String.Format(Resources.RoleInstanceCanNotBeFoundWithName, Name));
            }

            if (deploymentResponse.RoleInstances.Count > 1)
            {
                ExecuteClientActionNewSM(
                    null,
                    CommandRuntime.ToString(),
                    () => this.ComputeClient.VirtualMachines.Delete(this.ServiceName, CurrentDeploymentNewSM.Name, Name));
            }
            else
            {
                ExecuteClientActionNewSM(
                    null,
                    CommandRuntime.ToString(),
                    () => this.ComputeClient.Deployments.DeleteBySlot(this.ServiceName, DeploymentSlot.Production));
            }
        }