Esempio n. 1
0
        /// <summary>
        /// The process record method.
        /// </summary>
        protected override void ProcessRecord()
        {
            ServerWithBackupType 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
                    {
// if (e is HttpRequestException)
                        ThrowTerminatingError(new ErrorRecord(e, "-1", ErrorCategory.ConnectionError, Connection));
                    }

                    return(true);
                });
            }

            if (PassThru.IsPresent)
            {
                WriteObject(server);
            }
        }
Esempio n. 2
0
        public async Task <ServerDetailResponse> GetServerDetail([FromUri] string tenant_id, [FromUri] string server_id)
        {
            ServerWithBackupType caasServer = (await _computeClient.GetDeployedServers()).First(server => server.id == server_id);

            return
                (new ServerDetailResponse()
            {
                Server = CaaSServerToServerDetail(caasServer, tenant_id)
            });
        }
Esempio n. 3
0
 public BaseServer CaaSServerToServer(ServerWithBackupType server, string tenant_id)
 {
     return(new BaseServer()
     {
         Id = Guid.Parse(server.id),
         Name = server.name,
         Links = new RestLink[]
         {
             new RestLink(ServerController.GetServerUri(Request.RequestUri.Host, tenant_id, server.id), RestLink.Self)
         }
     });
 }
Esempio n. 4
0
 public ServerDetail CaaSServerToServerDetail(ServerWithBackupType server, string tenant_id)
 {
     return(new ServerDetail()
     {
         AccessIPv4 = server.privateIp,
         AccessIPv6 = "", // IPv6 not supported at present
         CreatedDate = server.created.ToString("s"),
         HostId = server.name,
         Id = Guid.Parse(server.id),
         Image = new ServerImage()
         {
             Id = server.sourceImageId,
             Links = new RestLink[]
             {
                 new RestLink(
                     UrlGenerator.GetImageUri(Request.RequestUri.Host, tenant_id, server.sourceImageId),
                     RestLink.Bookmark
                     )
             }
         },
         IpAddressCollection = new IPAddressCollection()
         {
             PrivateAddresses = new IPAddress[]
             {
                 new IPAddress(server.privateIp)
             },
             PublicAddresses = new IPAddress[]
             {
                 new IPAddress(server.publicIp)
             }
         },
         Flavor = new Flavor(),
         Name = server.name,
         Links = new RestLink[]
         {
             new RestLink(ServerController.GetServerUri(Request.RequestUri.Host, tenant_id, server.id), RestLink.Self)
         },
         UserId = Request.GetRequestContext().Principal.Identity.Name,
         TenantId = tenant_id,
         Metadata = new
         {
             MyServerName = server.name
         },                           // TODO: decide what metadata should be shown.
         Status = ServerStatus.Active // TODO : Map CaaS status.
     });
 }
Esempio n. 5
0
        /// <summary>
        /// The deploy server task.
        /// </summary>
        /// <returns>
        /// The <see cref="ServerWithBackupType"/>.
        /// </returns>
        private ServerWithBackupType DeployServerTask()
        {
            ServerWithBackupType server = null;
            string networkid            = ServerDetails.Network != null ? ServerDetails.Network.id : null;

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

                diskarray = disks.ToArray();
            }

            Status status =
                Connection.ApiClient.DeployServerWithDiskSpeedImageTask(
                    ServerDetails.Name,
                    ServerDetails.Description,
                    networkid,
                    ServerDetails.PrivateIp,
                    ServerDetails.Image.id,
                    ServerDetails.AdministratorPassword,
                    ServerDetails.IsStarted,
                    diskarray
                    ).Result;


// get the server id from status message
            AdditionalInformation statusadditionalInfo = status.additionalInformation.Single(info => info.name == "serverId");

            if (statusadditionalInfo != null)
            {
                IEnumerable <ServerWithBackupType> servers =
                    Connection.ApiClient.GetDeployedServers(statusadditionalInfo.value, null, null, null).Result;
                if (servers.Any())
                {
                    server = servers.First();
                }
            }

            if (status != null)
            {
                WriteDebug(
                    string.Format(
                        "{0} resulted in {1} ({2}): {3}",
                        status.operation,
                        status.result,
                        status.resultCode,
                        status.resultDetail));
            }
            return(server);
        }
Esempio n. 6
0
 /// <summary>	Out of place restore. </summary>
 /// <param name="serverId">	    The server id. </param>
 /// <param name="backupClient">	The backup client. </param>
 /// <param name="asAtDate">	    The date and time to recover to. </param>
 /// <param name="targetServer">	Target client. </param>
 /// <returns>	A Status message from the API; </returns>
 /// <seealso cref="M:DD.CBU.Compute.Api.Client.Interfaces.Backup.IBackupAccessor.OutOfPlaceRestore(string,BackupClientDetailsType,DateTime,BackupClientDetailsType)"/>
 public async Task <Status> OutOfPlaceRestore(string serverId, BackupClientDetailsType backupClient, DateTime asAtDate, ServerWithBackupType targetServer)
 {
     return(await this.OutOfPlaceRestore(serverId, backupClient.id, asAtDate, targetServer.id));
 }
Esempio n. 7
0
        /// <summary>
        /// The process record.
        /// </summary>
        protected override void ProcessRecord()
        {
            DateTime starttime = DateTime.Now;

            try
            {
                bool operationInProgress    = false;
                bool waitingToStart         = true;
                ServerWithBackupType server = null;

                // initial loop to cover for any delay on the CaaS API, do while state of the server is normal (max 5 min)
                do
                {
                    IEnumerable <ServerWithBackupType> servers = GetDeployeServers(Server.id).Result;
                    if (servers != null)
                    {
                        server         = servers.First();
                        waitingToStart = server.state.Equals("normal", StringComparison.InvariantCultureIgnoreCase);
                        OperationProgressRecord.Activity          = "Waiting CaaS to start the operation...CaaS server state still NORMAL";
                        OperationProgressRecord.StatusDescription =
                            string.Format(
                                "If your operation does not change the server state do not use this cmdlet. Waiting another {0} minutes",
                                (starttime.AddMinutes(5) - DateTime.Now).Minutes);
                        OperationProgressRecord.RecordType = ProgressRecordType.Processing;

                        WriteProgress(OperationProgressRecord);
                    }

                    if (waitingToStart)
                    {
                        Thread.Sleep(3000);
                    }
                    if (starttime.AddMinutes(5) <= DateTime.Now)
                    {
                        WriteError(
                            new ErrorRecord(
                                new TimeoutException("The wait operation timeout, as CaaS did not change not start in 5 minutes"), "-1",
                                ErrorCategory.OperationTimeout, Connection));
                    }
                }while (waitingToStart);
                OperationProgressRecord.RecordType      = ProgressRecordType.Completed;
                OperationProgressRecord.PercentComplete = 100;
                WriteProgress(OperationProgressRecord);


// do while state of the server contains pending
                operationInProgress = true;
                do
                {
                    // query the API to get the server progress
                    IEnumerable <ServerWithBackupType> servers = GetDeployeServers(Server.id).Result;
                    if (servers != null)
                    {
                        server = servers.First();

                        if (server.status != null)
                        {
                            string activity                = server.status.action.Replace('_', ' ').ToTitleCase();
                            string stepname                = string.Empty;
                            string activitytemplate        = string.Empty;
                            string activitydescription     = "Provisioning...";
                            int    activityPercentComplete = 0;
                            if (server.status.step != null)
                            {
                                activity            = server.status.action.Replace('_', ' ').ToTitleCase();
                                stepname            = server.status.step.name.Replace('_', ' ').ToTitleCase();
                                activitytemplate    = "{0} - Step {1} of {2}";
                                activitydescription = string.Format(activitytemplate, stepname, server.status.step.number,
                                                                    server.status.numberOfSteps);
                                activityPercentComplete = server.status.step.percentComplete;
                            }

                            OperationProgressRecord.Activity          = activity;
                            OperationProgressRecord.StatusDescription = activitydescription;
                            OperationProgressRecord.PercentComplete   = activityPercentComplete;
                            OperationProgressRecord.RecordType        = ProgressRecordType.Processing;
                            WriteProgress(OperationProgressRecord);
                        }

                        operationInProgress = server.state.ToLower().Contains("pending");
                        if (operationInProgress)
                        {
                            Thread.Sleep(7000);
                        }
                    }
                }while (operationInProgress);
                OperationProgressRecord.PercentComplete = 100;
                OperationProgressRecord.RecordType      = ProgressRecordType.Completed;
                WriteProgress(OperationProgressRecord);


                WriteObject(server);
            }
            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);
                });
            }


            base.ProcessRecord();
        }