public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();
            ExecuteClientAction(() =>
            {
                string resourceGroupName    = this.ResourceGroupName;
                string containerServiceName = this.Name;

                if (!string.IsNullOrEmpty(resourceGroupName) && !string.IsNullOrEmpty(containerServiceName))
                {
                    var result   = ContainerServicesClient.Get(resourceGroupName, containerServiceName);
                    var psObject = new PSContainerService();
                    ComputeAutomationAutoMapperProfile.Mapper.Map <ContainerService, PSContainerService>(result, psObject);
                    WriteObject(psObject);
                }
                else if (!string.IsNullOrEmpty(resourceGroupName))
                {
                    var result       = ContainerServicesClient.ListByResourceGroup(resourceGroupName);
                    var resultList   = result.ToList();
                    var nextPageLink = result.NextPageLink;
                    while (!string.IsNullOrEmpty(nextPageLink))
                    {
                        var pageResult = ContainerServicesClient.ListByResourceGroupNext(nextPageLink);
                        foreach (var pageItem in pageResult)
                        {
                            resultList.Add(pageItem);
                        }
                        nextPageLink = pageResult.NextPageLink;
                    }
                    var psObject = new List <PSContainerServiceList>();
                    foreach (var r in resultList)
                    {
                        psObject.Add(ComputeAutomationAutoMapperProfile.Mapper.Map <ContainerService, PSContainerServiceList>(r));
                    }
                    WriteObject(psObject, true);
                }
                else
                {
                    var result       = ContainerServicesClient.List();
                    var resultList   = result.ToList();
                    var nextPageLink = result.NextPageLink;
                    while (!string.IsNullOrEmpty(nextPageLink))
                    {
                        var pageResult = ContainerServicesClient.ListNext(nextPageLink);
                        foreach (var pageItem in pageResult)
                        {
                            resultList.Add(pageItem);
                        }
                        nextPageLink = pageResult.NextPageLink;
                    }
                    var psObject = new List <PSContainerServiceList>();
                    foreach (var r in resultList)
                    {
                        psObject.Add(ComputeAutomationAutoMapperProfile.Mapper.Map <ContainerService, PSContainerServiceList>(r));
                    }
                    WriteObject(psObject, true);
                }
            });
        }
        protected void ExecuteContainerServiceGetMethod(object[] invokeMethodInputParameters)
        {
            string resourceGroupName    = (string)ParseParameter(invokeMethodInputParameters[0]);
            string containerServiceName = (string)ParseParameter(invokeMethodInputParameters[1]);

            if (!string.IsNullOrEmpty(resourceGroupName) && !string.IsNullOrEmpty(containerServiceName))
            {
                var result   = ContainerServicesClient.Get(resourceGroupName, containerServiceName);
                var psObject = new PSContainerService();
                Mapper.Map <ContainerService, PSContainerService>(result, psObject);
                WriteObject(psObject);
            }
            else if (!string.IsNullOrEmpty(resourceGroupName))
            {
                var result       = ContainerServicesClient.ListByResourceGroup(resourceGroupName);
                var resultList   = result.ToList();
                var nextPageLink = result.NextPageLink;
                while (!string.IsNullOrEmpty(nextPageLink))
                {
                    var pageResult = ContainerServicesClient.ListByResourceGroupNext(nextPageLink);
                    foreach (var pageItem in pageResult)
                    {
                        resultList.Add(pageItem);
                    }
                    nextPageLink = pageResult.NextPageLink;
                }
                var psObject = new List <PSContainerServiceList>();
                foreach (var r in resultList)
                {
                    psObject.Add(Mapper.Map <ContainerService, PSContainerServiceList>(r));
                }
                WriteObject(psObject, true);
            }
            else
            {
                var result       = ContainerServicesClient.List();
                var resultList   = result.ToList();
                var nextPageLink = result.NextPageLink;
                while (!string.IsNullOrEmpty(nextPageLink))
                {
                    var pageResult = ContainerServicesClient.ListNext(nextPageLink);
                    foreach (var pageItem in pageResult)
                    {
                        resultList.Add(pageItem);
                    }
                    nextPageLink = pageResult.NextPageLink;
                }
                var psObject = new List <PSContainerServiceList>();
                foreach (var r in resultList)
                {
                    psObject.Add(Mapper.Map <ContainerService, PSContainerServiceList>(r));
                }
                WriteObject(psObject, true);
            }
        }
        public override void ExecuteCmdlet()
        {
            ExecuteClientAction(() =>
            {
                if (ShouldProcess(this.Name, VerbsData.Update))
                {
                    string resourceGroupName    = this.ResourceGroupName;
                    string containerServiceName = this.Name;
                    ContainerService parameters = new ContainerService();
                    ComputeAutomationAutoMapperProfile.Mapper.Map <PSContainerService, ContainerService>(this.ContainerService, parameters);

                    var result   = ContainerServicesClient.CreateOrUpdate(resourceGroupName, containerServiceName, parameters);
                    var psObject = new PSContainerService();
                    ComputeAutomationAutoMapperProfile.Mapper.Map <ContainerService, PSContainerService>(result, psObject);
                    WriteObject(psObject);
                }
            });
        }
Ejemplo n.º 4
0
        protected override void ProcessRecord()
        {
            AutoMapper.Mapper.AddProfile <ComputeAutomationAutoMapperProfile>();
            ExecuteClientAction(() =>
            {
                if (ShouldProcess(this.Name, VerbsCommon.New))
                {
                    string resourceGroupName    = this.ResourceGroupName;
                    string containerServiceName = this.Name;
                    ContainerService parameters = new ContainerService();
                    Mapper.Map <PSContainerService, ContainerService>(this.ContainerService, parameters);

                    var result   = ContainerServicesClient.CreateOrUpdate(resourceGroupName, containerServiceName, parameters);
                    var psObject = new PSContainerService();
                    Mapper.Map <ContainerService, PSContainerService>(result, psObject);
                    WriteObject(psObject);
                }
            });
        }
        protected void ExecuteContainerServiceGetMethod(object[] invokeMethodInputParameters)
        {
            string resourceGroupName    = (string)ParseParameter(invokeMethodInputParameters[0]);
            string containerServiceName = (string)ParseParameter(invokeMethodInputParameters[1]);

            if (!string.IsNullOrEmpty(resourceGroupName) && !string.IsNullOrEmpty(containerServiceName))
            {
                var result   = ContainerServiceClient.Get(resourceGroupName, containerServiceName);
                var psObject = new PSContainerService();
                Mapper.Map <ContainerService, PSContainerService>(result, psObject);
                WriteObject(psObject);
            }
            else if (!string.IsNullOrEmpty(resourceGroupName))
            {
                var result   = ContainerServiceClient.List(resourceGroupName);
                var psObject = new List <PSContainerServiceList>();
                foreach (var r in result)
                {
                    psObject.Add(Mapper.Map <ContainerService, PSContainerServiceList>(r));
                }
                WriteObject(psObject);
            }
        }
        private void Run()
        {
            // OrchestratorProfile
            ContainerServiceOrchestratorProfile vOrchestratorProfile = null;

            // CustomProfile
            ContainerServiceCustomProfile vCustomProfile = null;

            // ServicePrincipalProfile
            ContainerServiceServicePrincipalProfile vServicePrincipalProfile = null;

            // MasterProfile
            ContainerServiceMasterProfile vMasterProfile = null;

            // WindowsProfile
            ContainerServiceWindowsProfile vWindowsProfile = null;

            // LinuxProfile
            ContainerServiceLinuxProfile vLinuxProfile = null;

            // DiagnosticsProfile
            ContainerServiceDiagnosticsProfile vDiagnosticsProfile = null;

            if (this.IsParameterBound(c => c.OrchestratorType))
            {
                if (vOrchestratorProfile == null)
                {
                    vOrchestratorProfile = new ContainerServiceOrchestratorProfile();
                }
                vOrchestratorProfile.OrchestratorType = this.OrchestratorType.Value;
            }

            if (this.IsParameterBound(c => c.CustomProfileOrchestrator))
            {
                if (vCustomProfile == null)
                {
                    vCustomProfile = new ContainerServiceCustomProfile();
                }
                vCustomProfile.Orchestrator = this.CustomProfileOrchestrator;
            }

            if (this.IsParameterBound(c => c.ServicePrincipalProfileClientId))
            {
                if (vServicePrincipalProfile == null)
                {
                    vServicePrincipalProfile = new ContainerServiceServicePrincipalProfile();
                }
                vServicePrincipalProfile.ClientId = this.ServicePrincipalProfileClientId;
            }

            if (this.IsParameterBound(c => c.ServicePrincipalProfileSecret))
            {
                if (vServicePrincipalProfile == null)
                {
                    vServicePrincipalProfile = new ContainerServiceServicePrincipalProfile();
                }
                vServicePrincipalProfile.Secret = this.ServicePrincipalProfileSecret;
            }

            if (this.IsParameterBound(c => c.MasterCount))
            {
                if (vMasterProfile == null)
                {
                    vMasterProfile = new ContainerServiceMasterProfile();
                }
                vMasterProfile.Count = this.MasterCount;
            }

            if (this.IsParameterBound(c => c.MasterDnsPrefix))
            {
                if (vMasterProfile == null)
                {
                    vMasterProfile = new ContainerServiceMasterProfile();
                }
                vMasterProfile.DnsPrefix = this.MasterDnsPrefix;
            }

            if (this.IsParameterBound(c => c.WindowsProfileAdminUsername))
            {
                if (vWindowsProfile == null)
                {
                    vWindowsProfile = new ContainerServiceWindowsProfile();
                }
                vWindowsProfile.AdminUsername = this.WindowsProfileAdminUsername;
            }

            if (this.IsParameterBound(c => c.WindowsProfileAdminPassword))
            {
                if (vWindowsProfile == null)
                {
                    vWindowsProfile = new ContainerServiceWindowsProfile();
                }
                vWindowsProfile.AdminPassword = this.WindowsProfileAdminPassword;
            }

            if (this.IsParameterBound(c => c.AdminUsername))
            {
                if (vLinuxProfile == null)
                {
                    vLinuxProfile = new ContainerServiceLinuxProfile();
                }
                vLinuxProfile.AdminUsername = this.AdminUsername;
            }


            if (this.IsParameterBound(c => c.SshPublicKey))
            {
                if (vLinuxProfile == null)
                {
                    vLinuxProfile = new ContainerServiceLinuxProfile();
                }
                if (vLinuxProfile.Ssh == null)
                {
                    vLinuxProfile.Ssh = new ContainerServiceSshConfiguration();
                }
                if (vLinuxProfile.Ssh.PublicKeys == null)
                {
                    vLinuxProfile.Ssh.PublicKeys = new List <ContainerServiceSshPublicKey>();
                }
                foreach (var element in this.SshPublicKey)
                {
                    var vPublicKeys = new ContainerServiceSshPublicKey();
                    vPublicKeys.KeyData = element;
                    vLinuxProfile.Ssh.PublicKeys.Add(vPublicKeys);
                }
            }

            if (vDiagnosticsProfile == null)
            {
                vDiagnosticsProfile = new ContainerServiceDiagnosticsProfile();
            }
            if (vDiagnosticsProfile.VmDiagnostics == null)
            {
                vDiagnosticsProfile.VmDiagnostics = new ContainerServiceVMDiagnostics();
            }

            vDiagnosticsProfile.VmDiagnostics.Enabled = this.VmDiagnosticsEnabled;

            var vContainerService = new PSContainerService
            {
                Location                = this.IsParameterBound(c => c.Location) ? this.Location : null,
                Tags                    = this.IsParameterBound(c => c.Tag) ? this.Tag.Cast <DictionaryEntry>().ToDictionary(ht => (string)ht.Key, ht => (string)ht.Value) : null,
                AgentPoolProfiles       = this.IsParameterBound(c => c.AgentPoolProfile) ? this.AgentPoolProfile : null,
                OrchestratorProfile     = vOrchestratorProfile,
                CustomProfile           = vCustomProfile,
                ServicePrincipalProfile = vServicePrincipalProfile,
                MasterProfile           = vMasterProfile,
                WindowsProfile          = vWindowsProfile,
                LinuxProfile            = vLinuxProfile,
                DiagnosticsProfile      = vDiagnosticsProfile,
            };

            WriteObject(vContainerService);
        }
Ejemplo n.º 7
0
        private void Run()
        {
            // OrchestratorProfile
            Microsoft.Azure.Management.Compute.Models.ContainerServiceOrchestratorProfile vOrchestratorProfile = null;

            // CustomProfile
            Microsoft.Azure.Management.Compute.Models.ContainerServiceCustomProfile vCustomProfile = null;

            // ServicePrincipalProfile
            Microsoft.Azure.Management.Compute.Models.ContainerServiceServicePrincipalProfile vServicePrincipalProfile = null;

            // MasterProfile
            Microsoft.Azure.Management.Compute.Models.ContainerServiceMasterProfile vMasterProfile = null;

            // WindowsProfile
            Microsoft.Azure.Management.Compute.Models.ContainerServiceWindowsProfile vWindowsProfile = null;

            // LinuxProfile
            Microsoft.Azure.Management.Compute.Models.ContainerServiceLinuxProfile vLinuxProfile = null;

            // DiagnosticsProfile
            Microsoft.Azure.Management.Compute.Models.ContainerServiceDiagnosticsProfile vDiagnosticsProfile = null;

            if (this.OrchestratorType.HasValue)
            {
                if (vOrchestratorProfile == null)
                {
                    vOrchestratorProfile = new Microsoft.Azure.Management.Compute.Models.ContainerServiceOrchestratorProfile();
                }
                vOrchestratorProfile.OrchestratorType = this.OrchestratorType.Value;
            }

            if (this.CustomProfileOrchestrator != null)
            {
                if (vCustomProfile == null)
                {
                    vCustomProfile = new Microsoft.Azure.Management.Compute.Models.ContainerServiceCustomProfile();
                }
                vCustomProfile.Orchestrator = this.CustomProfileOrchestrator;
            }

            if (this.ServicePrincipalProfileClientId != null)
            {
                if (vServicePrincipalProfile == null)
                {
                    vServicePrincipalProfile = new Microsoft.Azure.Management.Compute.Models.ContainerServiceServicePrincipalProfile();
                }
                vServicePrincipalProfile.ClientId = this.ServicePrincipalProfileClientId;
            }

            if (this.ServicePrincipalProfileSecret != null)
            {
                if (vServicePrincipalProfile == null)
                {
                    vServicePrincipalProfile = new Microsoft.Azure.Management.Compute.Models.ContainerServiceServicePrincipalProfile();
                }
                vServicePrincipalProfile.Secret = this.ServicePrincipalProfileSecret;
            }

            if (this.MasterCount != null)
            {
                if (vMasterProfile == null)
                {
                    vMasterProfile = new Microsoft.Azure.Management.Compute.Models.ContainerServiceMasterProfile();
                }
                vMasterProfile.Count = this.MasterCount;
            }

            if (this.MasterDnsPrefix != null)
            {
                if (vMasterProfile == null)
                {
                    vMasterProfile = new Microsoft.Azure.Management.Compute.Models.ContainerServiceMasterProfile();
                }
                vMasterProfile.DnsPrefix = this.MasterDnsPrefix;
            }

            if (this.WindowsProfileAdminUsername != null)
            {
                if (vWindowsProfile == null)
                {
                    vWindowsProfile = new Microsoft.Azure.Management.Compute.Models.ContainerServiceWindowsProfile();
                }
                vWindowsProfile.AdminUsername = this.WindowsProfileAdminUsername;
            }

            if (this.WindowsProfileAdminPassword != null)
            {
                if (vWindowsProfile == null)
                {
                    vWindowsProfile = new Microsoft.Azure.Management.Compute.Models.ContainerServiceWindowsProfile();
                }
                vWindowsProfile.AdminPassword = this.WindowsProfileAdminPassword;
            }

            if (this.AdminUsername != null)
            {
                if (vLinuxProfile == null)
                {
                    vLinuxProfile = new Microsoft.Azure.Management.Compute.Models.ContainerServiceLinuxProfile();
                }
                vLinuxProfile.AdminUsername = this.AdminUsername;
            }


            if (this.SshPublicKey != null)
            {
                if (vLinuxProfile == null)
                {
                    vLinuxProfile = new Microsoft.Azure.Management.Compute.Models.ContainerServiceLinuxProfile();
                }
                if (vLinuxProfile.Ssh == null)
                {
                    vLinuxProfile.Ssh = new Microsoft.Azure.Management.Compute.Models.ContainerServiceSshConfiguration();
                }
                if (vLinuxProfile.Ssh.PublicKeys == null)
                {
                    vLinuxProfile.Ssh.PublicKeys = new List <Microsoft.Azure.Management.Compute.Models.ContainerServiceSshPublicKey>();
                }
                foreach (var element in this.SshPublicKey)
                {
                    var vPublicKeys = new Microsoft.Azure.Management.Compute.Models.ContainerServiceSshPublicKey();
                    vPublicKeys.KeyData = element;
                    vLinuxProfile.Ssh.PublicKeys.Add(vPublicKeys);
                }
            }

            if (vDiagnosticsProfile == null)
            {
                vDiagnosticsProfile = new Microsoft.Azure.Management.Compute.Models.ContainerServiceDiagnosticsProfile();
            }
            if (vDiagnosticsProfile.VmDiagnostics == null)
            {
                vDiagnosticsProfile.VmDiagnostics = new Microsoft.Azure.Management.Compute.Models.ContainerServiceVMDiagnostics();
            }

            vDiagnosticsProfile.VmDiagnostics.Enabled = this.VmDiagnosticsEnabled;

            var vContainerService = new PSContainerService
            {
                Location                = this.Location,
                Tags                    = (this.Tag == null) ? null : this.Tag.Cast <DictionaryEntry>().ToDictionary(ht => (string)ht.Key, ht => (string)ht.Value),
                AgentPoolProfiles       = this.AgentPoolProfile,
                OrchestratorProfile     = vOrchestratorProfile,
                CustomProfile           = vCustomProfile,
                ServicePrincipalProfile = vServicePrincipalProfile,
                MasterProfile           = vMasterProfile,
                WindowsProfile          = vWindowsProfile,
                LinuxProfile            = vLinuxProfile,
                DiagnosticsProfile      = vDiagnosticsProfile,
            };

            WriteObject(vContainerService);
        }