コード例 #1
0
 private void Configure()
 {
     configuration = new Configuration
     {
         Username = "******",
         Password = "******",
     };
     ipApi = new IPBlocksApi(configuration);
 }
コード例 #2
0
        protected override void BeginProcessing()
        {
            try
            {
                var ipblockApi = new IPBlocksApi(Utilities.Configuration);

                var resp = ipblockApi.Delete(IpBlockId);

                WriteObject("IPBlock successfully removed ");
            }
            catch (Exception ex)
            {
                WriteError(new ErrorRecord(ex, "", ErrorCategory.NotSpecified, null));
            }
        }
コード例 #3
0
        protected override void BeginProcessing()
        {
            try
            {
                var ipblockApi = new IPBlocksApi(Utilities.Configuration);

                var newProps = new IpBlockProperties {
                    Size = this.Size, Location = this.Location
                };

                var ipblock = ipblockApi.Create(new IpBlock {
                    Properties = newProps
                }, depth: 5);
                WriteObject(ipblock);
            }
            catch (Exception ex)
            {
                WriteError(new ErrorRecord(ex, "", ErrorCategory.NotSpecified, null));
            }
        }
コード例 #4
0
        protected override void BeginProcessing()
        {
            try
            {
                var ipblockApi = new IPBlocksApi(Utilities.Configuration);

                if (!string.IsNullOrEmpty(IpBlockId))
                {
                    var ipblock = ipblockApi.FindById(IpBlockId, depth: 5);

                    WriteObject(ipblock);
                }
                else
                {
                    var ipblocks = ipblockApi.FindAll(depth: 5);
                    WriteObject(ipblocks.Items);
                }
            }
            catch (Exception ex)
            {
                WriteError(new ErrorRecord(ex, "", ErrorCategory.NotSpecified, null));
            }
        }
コード例 #5
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));
            }
        }