コード例 #1
0
        public void ServerGet()
        {
            Configure();
            DoWait(server.Request);

            var oldServer = serverApi.FindById(datacenter.Id, server.Id);

            Assert.AreEqual(oldServer.Id, server.Id);
            Assert.AreEqual(oldServer.Properties.Name, server.Properties.Name);
        }
コード例 #2
0
        protected override void BeginProcessing()
        {
            try
            {
                var serverApi = new ServerApi(Utilities.Configuration);

                if (string.IsNullOrEmpty(ServerId))
                {
                    var servers = serverApi.FindAll(DataCenterId, depth: 5);
                    WriteObject(servers.Items);
                }
                else
                {
                    var server = serverApi.FindById(DataCenterId, ServerId, depth: 5);
                    WriteObject(server);
                }
            }
            catch (Exception ex)
            {
                WriteError(new ErrorRecord(ex, "", ErrorCategory.NotSpecified, null));
            }
        }
コード例 #3
0
        protected override void BeginProcessing()
        {
            try
            {
                var dcApi              = new DataCenterApi(Utilities.Configuration);
                var serverApi          = new ServerApi(Utilities.Configuration);
                var volumeApi          = new VolumeApi(Utilities.Configuration);
                var attachedVolumesApi = new AttachedVolumesApi(Utilities.Configuration);

                var datacenter = dcApi.FindById(DataCenterId, depth: 5);

                var server = new Server
                {
                    Properties = new ServerProperties
                    {
                        Name      = this.Name,
                        Cores     = this.Cores,
                        Ram       = (int)(this.Ram / 1024 / 1024),
                        CpuFamily = this.CpuFamily
                    }
                };

                var newServer = serverApi.Create(this.DataCenterId, server);

                WriteVerbose("Creating the server...");

                Utilities.DoWait(newServer.Request);

                if (!string.IsNullOrEmpty(this.AvailabilityZone))
                {
                    server.Properties.AvailabilityZone = this.AvailabilityZone;
                }

                if (!string.IsNullOrEmpty(this.BootVolume))
                {
                    server.Properties.BootVolume = new ResourceReference {
                        Id = this.BootVolume
                    };
                }

                if (!string.IsNullOrEmpty(this.BootCDRom))
                {
                    server.Properties.BootCdrom = new ResourceReference {
                        Id = this.BootCDRom
                    };
                }

                long size = Size;
                size = size == 0 ? 21474836480 : Size;

                var volume = new Volume
                {
                    Properties = new VolumeProperties
                    {
                        Size = (int)(size / 1024 / 1024 / 1024),
                        Type = (string.IsNullOrEmpty(DiskType) ? "HDD" : DiskType),
                        Name = Name,
                    }
                };

                if (!string.IsNullOrEmpty(ImageId))
                {
                    volume.Properties.Image = ImageId;
                }

                if (!string.IsNullOrEmpty(ImageAlias))
                {
                    volume.Properties.ImageAlias = ImageAlias;
                }

                if (!string.IsNullOrEmpty(SshKey))
                {
                    volume.Properties.SshKeys = new List <string> {
                        SshKey
                    };
                }

                if (!string.IsNullOrEmpty(Password))
                {
                    volume.Properties.ImagePassword = Password;
                }

                WriteVerbose("Creating the volume...");
                volume = volumeApi.Create(this.DataCenterId, volume);

                Utilities.DoWait(volume.Request);

                var attachedVol = attachedVolumesApi.AttachVolume(DataCenterId, newServer.Id, new Volume {
                    Id = volume.Id
                });



                if (this.PublicIp)
                {
                    var nic = new Nic
                    {
                        Properties = new NicProperties
                        {
                            Lan = 1,
                        }
                    };
                    var nicApi = new NetworkInterfacesApi(Utilities.Configuration);

                    if (this.StaticIp)
                    {
                        var ipblockApi = new IPBlocksApi(Utilities.Configuration);

                        var ipblock = new IpBlock
                        {
                            Properties = new IpBlockProperties
                            {
                                Location = datacenter.Properties.Location,
                                Size     = 1
                            }
                        };
                        WriteVerbose("Creating the static IP address...");
                        ipblock = ipblockApi.Create(ipblock);


                        Utilities.DoWait(ipblock.Request);
                        nic.Properties.Ips = ipblock.Properties.Ips;
                    }

                    WriteVerbose("Creating the nic...");
                    nic = nicApi.Create(DataCenterId, newServer.Id, nic);

                    Utilities.DoWait(nic.Request);
                }

                server = serverApi.FindById(datacenter.Id, newServer.Id, depth: 5);

                datacenter = dcApi.FindById(DataCenterId, depth: 5);

                server = serverApi.FindById(datacenter.Id, newServer.Id, depth: 5);


                WriteObject(server);
            }
            catch (Exception ex)
            {
                WriteError(new ErrorRecord(ex, "", ErrorCategory.NotSpecified, null));
            }
        }