public void VolumeCreate() { Configure(); volume = new Volume { Properties = new VolumeProperties { Size = 4, Image = imageId, Type = "HDD", Name = ".Net V2 - Test " + DateTime.Now.ToShortTimeString(), SshKeys = new System.Collections.Generic.List <string> { "hQGOEJeFL91EG3+l9TtRbWNjzhDVHeLuL3NWee6bekA=" } } }; volume = volumeApi.Create(datacenter.Id, volume); bool isBusy = true; while (isBusy == true) { var dc = dcApi.FindById(datacenter.Id); if (dc.Metadata.State != "BUSY") { isBusy = false; } Thread.Sleep(1500); } Assert.IsNotNull(volume); }
protected override void BeginProcessing() { try { var volumeApi = new VolumeApi(Utilities.Configuration); if (string.IsNullOrEmpty(this.ImageId) && string.IsNullOrEmpty(this.ImageAlias) && string.IsNullOrEmpty(this.LicenceType)) { WriteWarning("Please provide ImageAlias, ImageId or LicenceType."); return; } var volume = new Volume { Properties = new VolumeProperties { Size = this.Size, Type = this.Type } }; if (!string.IsNullOrEmpty(this.Name)) { volume.Properties.Name = this.Name; } if (!string.IsNullOrEmpty(this.Bus)) { volume.Properties.Bus = this.Bus; } if (!string.IsNullOrEmpty(this.ImagePassword)) { volume.Properties.ImagePassword = this.ImagePassword; } if (!string.IsNullOrEmpty(this.ImageId)) { volume.Properties.Image = this.ImageId; } if (!string.IsNullOrEmpty(LicenceType)) { volume.Properties.LicenceType = LicenceType; } if (!string.IsNullOrEmpty(SshKey)) { volume.Properties.SshKeys = new List <string> { SshKey }; } if (!string.IsNullOrEmpty(AvailabilityZone)) { volume.Properties.AvailabilityZone = AvailabilityZone; } if (!string.IsNullOrEmpty(ImageAlias)) { volume.Properties.ImageAlias = ImageAlias; } var newVolume = volumeApi.Create(this.DataCenterId, volume); WriteObject(newVolume); } catch (Exception ex) { WriteError(new ErrorRecord(ex, "", ErrorCategory.NotSpecified, null)); } }
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)); } }
static void Main(string[] args) { var configuration = new Configuration { Username = "******", Password = "******", }; var dcApi = new DataCenterApi(configuration); var serverApi = new ServerApi(configuration); var volumeApi = new VolumeApi(configuration); var attachedVolumesApi = new AttachedVolumesApi(configuration); var nicApi = new NetworkInterfacesApi(configuration); // CreateDataCenterRequest. // The only required field is DataCenterName. // If location parameter is left empty data center will be created in the default region of the customer var datacenter = new Datacenter { Properties = new DatacenterProperties { Name = ".Net V2 - Test " + DateTime.Now.ToShortTimeString(), Description = "Unit test for .Net SDK PB REST V2", Location = "us/lasdev" } }; // Response will contain Id of a newly created data center. datacenter = dcApi.Create(datacenter); // CreateServer. // DataCenterId: Defines the data center wherein the server is to be created. // AvailabilityZone: Selects the zone in which the server is going to be created (AUTO, ZONE_1, ZONE_2). // Cores: Number of cores to be assigned to the specified server. Required field. // InternetAccess: Set to TRUE to connect the server to the Internet via the specified LAN ID. // OsType: Sets the OS type of the server. // Ram: Number of RAM memory (in MiB) to be assigned to the server. var server = new Server { Properties = new ServerProperties { Name = ".Net V2 - Test " + DateTime.Now.ToShortTimeString(), Cores = 1, Ram = 256 } }; // response will contain Id of a newly created server. server = serverApi.Create(datacenter.Id, server); // UpdateServer // ServerId: Id of the server to be updated. // ServerName: Renames target virtual server // Cores: Updates the amount of cores of the target virtual server // Ram: Updates the RAM memory (in MiB) of the target virtual server. The minimum RAM size is 256 MiB server = serverApi.PartialUpdate(datacenter.Id, server.Id, new ServerProperties { Name = server.Properties.Name + " -Updated" }); // CreateVolume // DataCenterId: Defines the data center wherein the storage is to be created. If left empty, the storage will be created in a new data center // Size: Storage size (in GiB). Required Field. // Type: SSD or HDD disk type, Required Field var volume = new Volume { Properties = new VolumeProperties { Size = 4, Image = "fbaae2b2-c899-11e5-aa10-52540005ab80", Type = "HDD", Name = ".Net V2 - Test " + DateTime.Now.ToShortTimeString(), SshKeys = new System.Collections.Generic.List <string> { "hQGOEJeFL91EG3+l9TtRbWNjzhDVHeLuL3NWee6bekA=" } } }; // Response will contain Id of a newly created volume. volume = volumeApi.Create(datacenter.Id, volume); // AttachVolume // ServerId: Identifier of the target virtual storage. Required field. // StorageId: Identifier of the virtual storage to be connected. Required field. // BusType: Bus type to which the storage will be connected attachedVolumesApi.AttachVolume(datacenter.Id, server.Id, new Volume { Id = volume.Id }); attachedVolumesApi.DetachVolume(datacenter.Id, server.Id, volume.Id); // Fetches list of all Data Centers var dcs = dcApi.FindAll(depth: 5); // Fetches list of all Servers var servers = serverApi.FindAll(datacenter.Id, depth: 5); // Fetches list of all Volumes var volumes = volumeApi.FindAll(datacenter.Id, depth: 5); // CreateNicRequest // Identifier of the target virtual server. Required field. // Nic: Names the NIC // Toggles usage of ProfitBricks DHCP // Lan var nic = new Nic { Properties = new NicProperties { Lan = 1, Dhcp = true, Name = "Nic name" } }; nic = nicApi.Create(datacenter.Id, server.Id, nic); }