Esempio n. 1
0
        /// <summary>
        ///     The process record method.
        /// </summary>
        protected override void ProcessRecord()
        {
            Api.Contracts.Network20.ServerType server = null;
            base.ProcessRecord();
            try
            {
                server = DeployServerTask();
            }
            catch (AggregateException ae)
            {
                ae.Handle(
                    e =>
                {
                    if (e is ComputeApiException)
                    {
                        WriteError(new ErrorRecord(e, "-2", ErrorCategory.InvalidOperation, Connection));
                    }
                    else
                    {
                        ThrowTerminatingError(new ErrorRecord(e, "-1", ErrorCategory.ConnectionError, Connection));
                    }

                    return(true);
                });
            }

            if (PassThru.IsPresent)
            {
                WriteObject(server);
            }
        }
        /// <summary>
        ///     The process record method.
        /// </summary>
        protected override void ProcessRecord()
        {
            Api.Contracts.Network20.ServerType deployedServer = null;
            base.ProcessRecord();
            try
            {
                var primaryNic = new NewNicType
                {
                    vlanId             = PrimaryVlan != null ? PrimaryVlan.id : null,
                    privateIpv4        = PrimaryPrivateIp,
                    connected          = PrimaryNicConnected.Value,
                    connectedSpecified = PrimaryNicConnected.HasValue
                };

                var server = new DeployServerType
                {
                    name                  = Name,
                    description           = Description,
                    imageId               = ServerImage.id,
                    start                 = IsStarted,
                    administratorPassword = AdminPassword,
                    networkInfo           =
                        new DeployServerTypeNetworkInfo
                    {
                        networkDomainId =
                            NetworkDomain.id,
                        primaryNic = primaryNic
                    }
                };

                var response = Connection.ApiClient.ServerManagement.Server.DeployServer(server).Result;

                // get the server id from status message
                var serverInfo = response.info.Single(info => info.name == "serverId");
                if (serverInfo != null)
                {
                    deployedServer = Connection.ApiClient.ServerManagement.Server.GetServer(Guid.Parse(serverInfo.value)).Result;
                }
            }
            catch (AggregateException ae)
            {
                ae.Handle(
                    e =>
                {
                    if (e is ComputeApiException)
                    {
                        WriteError(new ErrorRecord(e, "-2", ErrorCategory.InvalidOperation, Connection));
                    }
                    else
                    {
                        // if (e is HttpRequestException)
                        ThrowTerminatingError(new ErrorRecord(e, "-1", ErrorCategory.ConnectionError, Connection));
                    }

                    return(true);
                });
            }

            if (PassThru.IsPresent)
            {
                WriteObject(deployedServer);
            }
        }
Esempio n. 3
0
        /// <summary>
        ///     The deploy server task.
        /// </summary>
        /// <returns>
        ///     The <see cref="ServerType" />.
        /// </returns>
        private Api.Contracts.Network20.ServerType DeployServerTask()
        {
            Api.Contracts.Network20.ServerType deployedServer    = null;
            DeployServerTypeNetwork            networkInfo       = null;
            DeployServerTypeNetworkInfo        networkDomainInfo = null;

            if (ServerDetails.NetworkDomain != null)
            {
                networkDomainInfo = new DeployServerTypeNetworkInfo
                {
                    networkDomainId = ServerDetails.NetworkDomain.id,
                    primaryNic      = new NewNicType
                    {
                        vlanId             = ServerDetails.PrimaryVlan != null ? ServerDetails.PrimaryVlan.id : null,
                        privateIpv4        = ServerDetails.PrivateIp,
                        connected          = ServerDetails.PrimaryNicConnected != null ? ServerDetails.PrimaryNicConnected.Value : true,
                        connectedSpecified = ServerDetails.PrimaryNicConnected.HasValue
                    }
                };
            }
            else
            {
                networkInfo = new DeployServerTypeNetwork
                {
                    networkId   = ServerDetails.Network != null ? ServerDetails.Network.id : null,
                    privateIpv4 = ServerDetails.PrivateIp
                };
            }

            // convert CaasServerDiskDetails to Disk[]
            DeployServerTypeDisk[] diskarray = null;
            if (ServerDetails.InternalDiskDetails != null &&
                ServerDetails.InternalDiskDetails.Count > 0)
            {
                var disks = new List <DeployServerTypeDisk>();
                foreach (CaasServerDiskDetails item in ServerDetails.InternalDiskDetails)
                {
                    var disk =
                        new DeployServerTypeDisk
                    {
                        id    = item.DiskId,
                        speed = item.SpeedId
                    };
                    disks.Add(disk);
                }

                diskarray = disks.ToArray();
            }
            ResponseType response = null;

            if (GuestOsCustomization.HasValue && GuestOsCustomization == false)
            {
                var server = new DeployUncustomizedServerType
                {
                    name              = ServerDetails.Name,
                    description       = ServerDetails.Description,
                    imageId           = ServerDetails.ImageId,
                    start             = ServerDetails.IsStarted,
                    networkInfo       = networkDomainInfo,
                    disk              = diskarray,
                    cpu               = ServerDetails.CpuDetails,
                    memoryGb          = ServerDetails.MemoryGb,
                    memoryGbSpecified = (ServerDetails.MemoryGb > 0),
                    clusterId         = ServerDetails.ClusterId
                };

                response = Connection.ApiClient.ServerManagement.Server.DeployUncustomizedServer(server).Result;
            }
            else
            {
                var server = new DeployServerType
                {
                    name                  = ServerDetails.Name,
                    description           = ServerDetails.Description,
                    imageId               = ServerDetails.ImageId,
                    start                 = ServerDetails.IsStarted,
                    administratorPassword = ServerDetails.AdministratorPassword,
                    network               = networkInfo,
                    networkInfo           = networkDomainInfo,
                    disk                  = diskarray,
                    cpu               = ServerDetails.CpuDetails,
                    primaryDns        = ServerDetails.PrimaryDns,
                    secondaryDns      = ServerDetails.SecondaryDns,
                    microsoftTimeZone = ServerDetails.MicrosoftTimeZone,
                    memoryGb          = ServerDetails.MemoryGb,
                    memoryGbSpecified = (ServerDetails.MemoryGb > 0),
                    clusterId         = ServerDetails.ClusterId
                };

                response = Connection.ApiClient.ServerManagement.Server.DeployServer(server).Result;
            }

            // get the server id from status message
            var serverInfo = response.info.Single(info => info.name == "serverId");

            if (serverInfo != null)
            {
                deployedServer = Connection.ApiClient.ServerManagement.Server.GetServer(Guid.Parse(serverInfo.value)).Result;
            }

            if (response != null)
            {
                WriteDebug(
                    string.Format(
                        "{0} resulted in {1} ({2}): requestId: {3}",
                        response.operation,
                        response.responseCode,
                        response.message,
                        response.requestId));
            }
            return(deployedServer);
        }