Version: profitbricks-sdk-net 4.1.0
- Description
- Getting Started
- Reference
- Examples
- Support
- Testing
- Contributing
This .NET library wraps the ProfitBricks Cloud API. All API operations are performed over a SSL/TLS secured connection and authenticated using your ProfitBricks portal credentials. The Cloud API can be accessed over the public Internet from any application that can send an HTTPS request and receive an HTTPS response.
This guide will show you how to programmatically perform common management tasks using the .NET SDK for the ProfitBricks Cloud API.
.NET is a software framework developed by Microsoft that primarily runs on the Microsoft Windows operating system.
Before you begin you will need to have signed-up for a ProfitBricks account. The credentials you setup during sign-up will be used to authenticate against the Cloud API.
The official .NET library is available from the ProfitBricks GitHub account. You can download the latest stable version by cloning the repository and then adding the project to your solution.
Or you can add the SDK by using nuget
:
Install-Package ProfitBricksSDK
Connecting to ProfitBricks is handled by first setting up your authentication credentials.
To setup your credentials you will have to provide an instance of the Configuration class provided with your username and password
public static Configuration Configuration
{
get
{
return new Configuration
{
Username = Environment.GetEnvironmentVariable("PROFITBRICKS_USERNAME"),
Password = Environment.GetEnvironmentVariable("PROFITBRICKS_PASSWORD"),
};
}
}
You can choose to read them from the environment variables like in the example above, or just provide the strting value for Username and Password.
You can now use create an instance of any API class and pass the Configuration property for any future request.
LocationApi locApi = new LocationApi(Configuration);
This section provides details on all the available operations and the parameters they accept. Brief code snippets demonstrating usage are also included.
Virtual data centers (VDCs) are the foundation of the ProfitBricks platform. VDCs act as logical containers for all other objects you will be creating, e.g., servers. You can provision as many VDCs as you want. VDCs have their own private network and are logically segmented from each other to create isolation.
Create an instace of the api class:
DataCenterApi dcApi = new DataCenterApi(Configuration);
This operation will list all currently provisioned VDCs that your account credentials provide access to.
The optional depth
parameter defines the level, one being the least and five being the most, of information returned with the response.
var list = dcApi.FindAll(depth: 5);
Use this to retrieve details about a specific VDC.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
DatacenterId | yes | string | The ID of the VDC. |
depth | no | int | The level of details returned. |
var dc = dcApi.FindById(DatacenterId, depth: 5);
Use this operation to create a new VDC. You can create a "simple" VDC by supplying just the required name and location parameters. This operation also has the capability of provisioning a "complex" VDC by supplying additional parameters for servers, volumes, LANs, and/or load balancers.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
Name | yes | string | The name of the data center. |
Location | yes | string | The physical ProfitBricks location where the VDC will be created. |
Description | no | string | A description for the data center, e.g. staging, production. |
Servers | no | collection | Details about creating one or more servers. See create a server. |
Volumes | no | collection | Details about creating one or more volumes. See create a volume. |
Lans | no | collection | Details about creating one or more LANs. See create a lan. |
Loadbalancers | no | collection | Details about creating one or more load balancers. See [create a load balancer](#create-a-load- balancer). |
The following table outlines the locations currently supported:
Value | Country | City |
---|---|---|
us/las | United States | Las Vegas |
us/ewr | United States | Newark |
de/fra | Germany | Frankfurt |
de/fkb | Germany | Karlsruhe |
NOTES:
- The value for
Name
cannot contain the following characters: (@, /, , |, ‘’, ‘). - You cannot change the virtual data center
Location
once it has been provisioned.
var datacenter = new Datacenter
{
Properties = new DatacenterProperties
{
Name = ".Net V2 - DC Test " + DateTime.Now.ToShortTimeString(),
Description = "Unit test for .Net SDK PB REST V2",
Location = "us/las"
},
Entities = new DatacenterEntities
{
Servers = new Servers
{
Items = new List<Server>
{
new Server
{
Properties = new ServerProperties
{
Name = "Test Server",
Cores = 1,
Ram = 1024
}
}
}
}
}
};
datacenter = dcApi.Create(datacenter);
After retrieving a data center, either by getting it by id, or as a create response object, you can change its properties by calling the PartialUpdate
or the Update
method. Some parameters may not be changed using either of the update methods.
The following table describes the available request arguments:
Name | Required | Type | Description |
---|---|---|---|
DatacenterId | yes | string | The ID of the VDC. |
Name | no | string | The new name of the VDC. |
Description | no | string | The new description of the VDC. |
var resp = dcApi.PartialUpdate(DatacenterId, new DatacenterProperties { Name ="tes update"});
NOTE: You may also use Update()
instead of PartialUpdate()
. For an Update()
operation you will need to supply values for all the parameters.
This will remove all objects within the virtual data center AND remove the virtual data center object itself.
NOTE: This is a highly destructive operation which should be used with extreme caution!
The following table describes the available request arguments:
Name | Required | Type | Description |
---|---|---|---|
DatacenterId | yes | string | The ID of the VDC that you want to delete. |
var resp = dcApi.Delete(DatacenterId);
Locations are the physical ProfitBricks data centers where you can provision your VDCs.
Create an instace of the api class:
LocationApi locApi = new LocationApi(Configuration);
This operation will return the list of currently available locations.
The optional depth
parameter defines the level, one being the least and five being the most, of information returned with the response.
var locations = locApi.FindAll();
Retrieves the attributes of a specific location.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
LocationId | yes | string | The ID consisting of country/city. |
Location loc = locApi.FindById(locationId);
Create an instace of these api classes:
ServerApi serverApi = new ServerApi(Configuration);
AttachedCDROMsApi attachCDROMApi = new AttachedCDROMsApi(Configuration);
AttachedVolumesApi attachedVolumesApi = new AttachedVolumesApi(Configuration);
You can retrieve a list of all the servers provisioned inside a specific VDC.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
DatacenterId | yes | string | The ID of the VDC. |
depth | no | int | The level of details returned. |
var list = serverApi.FindAll(DatacenterId);
Returns information about a specific server such as its configuration, provisioning status, etc.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
DatacenterId | yes | string | The ID of the VDC. |
ServerId | yes | string | The ID of the server. |
depth | no | int | The level of details returned. |
var server = serverApi.FindById(DatacenterId, ServerId);
Creates a server within an existing VDC. You can configure additional properties such as specifying a boot volume and connecting the server to a LAN.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
DatacenterId | yes | string | The ID of the VDC. |
Name | yes | string | The name of the server. |
Cores | yes | int | The total number of cores for the server. |
Ram | yes | int | The amount of memory for the server in MB, e.g. 2048. Size must be specified in multiples of 256 MB with a minimum of 256 MB; however, if you set ram_hot_plug to True then you must use a minimum of 1024 MB. |
AvailabilityZone | no | string | The availability zone in which the server should exist. |
CpuFamily | no | string | Sets the CPU type. "AMD_OPTERON" or "INTEL_XEON". Defaults to "AMD_OPTERON". |
BootVolume | no | object | Reference to a volume used for booting. If not null then BootCdrom has to be null. |
BootCdrom | no | object | Reference to a CD-ROM used for booting. If not null then BootVolume has to be null. |
Volumes | no | object | A collection of volume objects that you want to create and attach to the server. |
Nics | no | object | A collection of NICs you wish to create at the time the server is provisioned. |
The following table outlines the server availability zones currently supported:
Availability Zone | Comment |
---|---|
AUTO | Automatically Selected Zone |
ZONE_1 | Fire Zone 1 |
ZONE_2 | Fire Zone 2 |
var server = new Server
{
Properties = new ServerProperties
{
Name = "Test Server",
Cores = 1,
Ram = 1024,
}
};
serverApi.Create(DatacenterId, server);
Perform updates to the attributes of a server.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
DatacenterId | yes | string | The ID of the VDC. |
ServerId | yes | string | The ID of the server. |
Name | no | string | The name of the server. |
Cores | no | int | The number of cores for the server. |
Ram | no | int | The amount of memory in the server. |
AvailabilityZone | no | string | The new availability zone for the server. |
CpuFamily | no | string | Sets the CPU type. "AMD_OPTERON" or "INTEL_XEON". Defaults to "AMD_OPTERON". |
BootVolume | no | object | Reference to a volume used for booting. If not null then BootCdrom has to be null |
BootCdrom | no | object | Reference to a CD-ROM used for booting. If not null then BootVolume has to be null. |
After retrieving a server, either by getting it by id, or as a create response object, you can change its properties and call the PartialUpdate
method:
var updated = serverApi.PartialUpdate(DatacenterId, ServerId, new ServerProperties { Name ="Updated" });
NOTE: You can also use Update()
, for that operation you will update all the properties.
This will remove a server from a data center. NOTE: This will not automatically remove the storage volume(s) attached to a server. A separate operation is required to delete a storage volume.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
DatacenterId | yes | string | The ID of the VDC. |
ServerId | yes | string | The ID of the server. |
After retrieving a server, either by getting it by id, or as a create response object, you can call the Delete
method directly:
var response = serverApi.Delete(DatacenterId, ServerId);
Retrieves a list of volumes attached to the server.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
DatacenterId | yes | string | The ID of the VDC. |
ServerId | yes | string | The ID of the server. |
depth | no | int | The level of details returned. |
After retrieving a server, either by getting it by id, or as a create response object, you can call the FindAll
method directly:
var all = attachedVolumesApi.FindAll(DatacenterId, ServerId);
This will attach a pre-existing storage volume to the server.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
DatacenterId | yes | string | The ID of the VDC. |
ServerId | yes | string | The ID of the server. |
VolumeId | yes | string | The ID of a storage volume. |
After retrieving a server, either by getting it by id, or as a create response object, you can call the AttachVolume
method directly.
var resp = attachedVolumesApi.AttachVolume(DatacenterId, ServerId, new Volume { Id = VolumeId });
This will retrieve the properties of an attached volume.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
DatacenterId | yes | string | The ID of the VDC. |
ServerId | yes | string | The ID of the server. |
VolumeId | yes | string | The ID of the attached volume. |
depth | no | int | The level of details returned. |
After retrieving a server, either by getting it by id, or as a create response object, you can call the FindById
method directly.
var attachedVol = attachedVolumesApi.FindById(DatacenterId, ServerId, VolumeId);
This will detach the volume from the server. Depending on the volume hot_unplug
settings, this may result in the server being rebooted.
This will NOT delete the volume from your virtual data center. You will need to make a separate request to delete a volume.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
DatacenterId | yes | string | The ID of the VDC. |
ServerId | yes | string | The ID of the server. |
VolumeId | yes | string | The ID of the attached volume. |
After retrieving a server, either by getting it by id, or as a create response object, you can call the DetachVolume
method directly.
var resp = attachedVolumesApi.DetachVolume(DatacenterId,ServerId, VolumeId);
Retrieves a list of CD-ROMs attached to a server.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
DatacenterId | yes | string | The ID of the VDC. |
ServerId | yes | string | The ID of the server. |
depth | no | int | The level of details returned. |
After retrieving a server, either by getting it by id, or as a create response object, you can call the FindAll
method directly.
var listAttached = attachCDROMApi.FindAll(DatacenterId, ServerId);
You can attach a CD-ROM to an existing server.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
DatacenterId | yes | string | The ID of the VDC. |
ServerId | yes | string | The ID of the server. |
CdRomImageId | yes | string | The ID of a CD-ROM. |
After retrieving a server, either by getting it by id, or as a create response object, you can call the Attach
method directly.
var attached = attachCDROMApi.Attach(DatacenterId, ServerId, new Image { Id=CdRomImageId});
You can retrieve a specific CD-ROM attached to the server.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
DatacenterId | yes | string | The ID of the VDC. |
ServerId | yes | string | The ID of the server. |
CdRomImageId | yes | string | The ID of the attached CD-ROM. |
depth | no | int | The level of details returned. |
After retrieving a server, either by getting it by id, or as a create response object, you can call the FindById
method directly.
var getAttached = attachCDROMApi.FindById(DatacenterId, ServerId, CdRomImageId);
This will detach a CD-ROM from the server.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
DatacenterId | yes | string | The ID of the VDC. |
ServerId | yes | string | The ID of the server. |
CdRomImageId | yes | string | The ID of the attached CD-ROM. |
After retrieving a server, either by getting it by id, or as a create response object, you can call the Detach
method directly.
var removed = attachCDROMApi.Detach(DatacenterId, ServerId, CdRomImageId);
This will force a hard reboot of the server. Do not use this method if you want to gracefully reboot the machine. This is the equivalent of powering off the machine and turning it back on.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
DatacenterId | yes | string | The ID of the VDC. |
ServerId | yes | string | The ID of the server. |
After retrieving a server, either by getting it by id, or as a create response object, you can call the Reboot
method directly.
var resp = serverApi.Reboot(DatacenterId, ServerId);
This will start a server. If the server's public IP was deallocated then a new IP will be assigned.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
DatacenterId | yes | string | The ID of the VDC. |
ServerId | yes | string | The ID of the server. |
After retrieving a server, either by getting it by id, or as a create response object, you can call the Start
method directly.
var start = serverApi.Start(DatacenterId, ServerId);
This will stop a server. The machine will be forcefully powered off, billing will cease, and the public IP, if one is allocated, will be deallocated.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
DatacenterId | yes | string | The ID of the VDC. |
ServerId | yes | string | The ID of the server. |
After retrieving a server, either by getting it by id, or as a create response object, you can call the Stop
method directly.
var error = serverApi.Stop(DatacenterId, ServerId);
Create an instace of the api class:
ImageApi imageApi = new ImageApi(Configuration);
Retrieve a list of images.
The optional depth
parameter defines the level, one being the least and five being the most, of information returned with the response.
var list = imageApi.FindAll();
Retrieves the attributes of a specific image.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
ImageId | yes | string | The ID of the image. |
depth | no | int | The level of details returned. |
var img = imageApi.FindById(ImageId);
Create an instace of the api class:
AttachedVolumesApi attachedVolumesApi = new AttachedVolumesApi(Configuration);
Retrieve a list of volumes within the virtual data center. If you want to retrieve a list of volumes attached to a server please see the List Attached Volumes entry in the Server section for details.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
DatacenterId | yes | string | The ID of the VDC. |
depth | no | int | The level of details returned. |
var list = volumeApi.FindAll(DatacenterId);
Retrieves the attributes of a given volume.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
DatacenterId | yes | string | The ID of the VDC. |
VolumeId | yes | string | The ID of the volume. |
depth | no | int | The level of details returned. |
var volume = volumeApi.FindById(DatacenterId, VolumeId);
Creates a volume within the virtual data center. This will NOT attach the volume to a server. Please see the Attach a Volume entry in the Server section for details on how to attach storage volumes.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
DatacenterId | yes | string | The ID of the VDC. |
Name | no | string | The name of the volume. |
Size | yes | int | The size of the volume in GB. |
Bus | no | string | The bus type of the volume (VIRTIO or IDE). Default: VIRTIO. |
Image | yes | string | The image or snapshot ID. |
ImageAlias | yes | string | The alias of the image. |
Type | yes | string | The volume type, HDD or SSD. |
LicenceType | yes | string | The licence type of the volume. Options: LINUX, WINDOWS, WINDOWS2016, UNKNOWN, OTHER |
ImagePassword | yes | string | One-time password is set on the Image for the appropriate root or administrative account. This field may only be set in creation requests. When reading, it always returns null. The password has to contain 8-50 characters. Only these characters are allowed: [abcdefghjkmnpqrstuvxABCDEFGHJKLMNPQRSTUVX23456789] |
SshKeys | yes | string | SSH keys to allow access to the volume via SSH. |
AvailabilityZone | no | string | The storage availability zone assigned to the volume. Valid values: AUTO, ZONE_1, ZONE_2, or ZONE_3. This only applies to HDD volumes. Leave blank or set to AUTO when provisioning SSD volumes. |
The following table outlines the various licence types you can define:
Licence Type | Comment |
---|---|
WINDOWS2016 | Use this for the Microsoft Windows Server 2016 operating system. |
WINDOWS | Use this for the Microsoft Windows Server 2008 and 2012 operating systems. |
LINUX | Use this for Linux distributions such as CentOS, Ubuntu, Debian, etc. |
OTHER | Use this for any volumes that do not match one of the other licence types. |
UNKNOWN | This value may be inherited when you've uploaded an image and haven't set the license type. Use one of the options above instead. |
The following table outlines the storage availability zones currently supported:
Availability Zone | Comment |
---|---|
AUTO | Automatically Selected Zone |
ZONE_1 | Fire Zone 1 |
ZONE_2 | Fire Zone 2 |
ZONE_3 | Fire Zone 3 |
Note: You will need to provide either the Image
, ImageAlias
or the LicenceType
parameters. LicenceType
is required, but if Image
or ImageAlias
is supplied, it is already set and cannot be changed. You can obtain a valid image alias via List Locations operation.
Similarly either the ImagePassword
or SshKeys
parameters need to be supplied when creating a volume. We recommend setting a valid value for image_password
even when using SshKeys
so that it is possible to authenticate using the remote console feature of the DCD.
var volume = new Volume
{
Properties = new VolumeProperties
{
Size = 4,
LicenceType = "UNKNOWN",
Type = "HDD",
Name = ".Net V2 - Test " + DateTime.Now.ToShortTimeString(),
AvailabilityZone = "ZONE_3"
}
};
volume = volumeApi.Create(DatacenterId, volume, depth: 5);
You can update -- in full or partially -- various attributes on the volume; however, some restrictions are in place:
You can increase the size of an existing storage volume. You cannot reduce the size of an existing storage volume. The volume size will be increased without requiring a reboot if the relevant hot plug settings have been set to true. The additional capacity is not added automatically added to any partition, therefore you will need to handle that inside the OS afterwards. Once you have increased the volume size you cannot decrease the volume size.
Since an existing volume is being modified, none of the request parameters are specifically required as long as the changes being made satisfy the requirements for creating a volume.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
DatacenterId | yes | string | The ID of the VDC. |
VolumeId | yes | string | The ID of the volume. |
Name | no | string | The name of the volume. |
Size | no | int | The size of the volume in GB. Only increase when updating. |
Bus | no | string | The bus type of the volume (VIRTIO or IDE). Default: VIRTIO. |
Image | no | string | The image or snapshot ID. |
Type | no | string | The volume type, HDD or SSD. |
LicenceType | no | string | The licence type of the volume. Options: LINUX, WINDOWS, WINDOWS2016, UNKNOWN, OTHER |
AvailabilityZone | no | string | The storage availability zone assigned to the volume. Valid values: AUTO, ZONE_1, ZONE_2, or ZONE_3. This only applies to HDD volumes. Leave blank or set to AUTO when provisioning SSD volumes. |
After retrieving a volume, either by getting it by id, or as a create response object, you can change its properties and call the PartialUpdate
method:
var newVolume = volumeApi.PartialUpdate(DatacenterId, VolumeId, new VolumeProperties { Size = volume.Properties.Size + 1 });
NOTE: You can also use Update()
, for that operation you will update all the properties.
Deletes the specified volume. This will result in the volume being removed from your data center. Use this with caution.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
DatacenterId | yes | string | The ID of the VDC. |
VolumeId | yes | string | The ID of the volume. |
After retrieving a volume, either by getting it by id, or as a create response object, you can call the Delete
method directly.
var response = volumeApi.Delete(DatacenterId, VolumeId);
Creates a snapshot of a volume within the virtual data center. You can use a snapshot to create a new storage volume or to restore a storage volume.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
DatacenterId | yes | string | The ID of the VDC. |
VolumeId | yes | string | The ID of the volume. |
Name | no | string | The name of the snapshot. |
Description | no | string | The description of the snapshot. |
After retrieving a volume, either by getting it by id, or as a create response object, you can call the CreateSnapshot
method directly.
var resp = volumeApi.CreateSnapshot(DatacenterId, VolumeId, Name, Description);
This will restore a snapshot onto a volume. A snapshot is created as just another image that can be used to create new volumes or to restore an existing volume.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
DatacenterId | yes | string | The ID of the VDC. |
SnapshotId | yes | string | The ID of the snapshot. |
After retrieving a volume, either by getting it by id, or as a create response object, you can call the RestoreSnapshot
method directly.
var resp = volumeApi.RestoreSnapshot(DatacenterId, SnapshotId);
Create an instace of the api class:
SnapshotApi snapshotApi = new SnapshotApi(Configuration);
You can retrieve a list of all available snapshots.
The optional depth
parameter defines the level, one being the least and five being the most, of information returned with the response.
var list = snapshotApi.FindAll(depth: 5);
Retrieves the attributes of a specific snapshot.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
SnapshotId | yes | string | The ID of the snapshot. |
depth | no | int | The level of details returned. |
var snapshot = snapshotApi.FindById(SnapshotId);
Perform updates to attributes of a snapshot.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
SnapshotId | yes | string | The ID of the snapshot. |
Name | no | string | The name of the snapshot. |
Description | no | string | The description of the snapshot. |
LicenceType | no | string | The snapshot's licence type: LINUX, WINDOWS, WINDOWS2016, or OTHER. |
CpuHotPlug | no | bool | This volume is capable of CPU hot plug (no reboot required) |
CpuHotUnplug | no | bool | This volume is capable of CPU hot unplug (no reboot required) |
RamHotPlug | no | bool | This volume is capable of memory hot plug (no reboot required) |
RamHotUnplug | no | bool | This volume is capable of memory hot unplug (no reboot required) |
NicHotPlug | no | bool | This volume is capable of NIC hot plug (no reboot required) |
NicHotUnplug | no | bool | This volume is capable of NIC hot unplug (no reboot required) |
DiscVirtioHotPlug | no | bool | This volume is capable of VirtIO drive hot plug (no reboot required) |
DiscVirtioHotUnplug | no | bool | This volume is capable of VirtIO drive hot unplug (no reboot required) |
DiscScsiHotPlug | no | bool | This volume is capable of SCSI drive hot plug (no reboot required) |
DiscScsiHotUnplug | no | bool | This volume is capable of SCSI drive hot unplug (no reboot required) |
After retrieving a snapshot, either by getting it by id, or as a create response object, you can change its properties and call the PartialUpdate
method:
var updated = snapshotApi.PartialUpdate(SnapshotId, new SnapshotProperties { Name ="Updated" });
NOTE: You can also use Update()
, for that operation you will update all the properties.
Deletes the specified snapshot.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
SnapshotId | yes | string | The ID of the snapshot. |
After retrieving a snapshot, either by getting it by id, or as a create response object, you can call the Delete
method directly.
var resp = snapshotApi.Delete(SnapshotId);
The IP block operations assist with managing reserved /static public IP addresses.
Create an instace of the api class:
IPBlocksApi ipApi = new IPBlocksApi(Configuration);
Retrieve a list of available IP blocks.
The optional depth
parameter defines the level, one being the least and five being the most, of information returned with the response.
var list = ipApi.FindAll();
Retrieves the attributes of a specific IP block.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
IpBlockId | yes | string | The ID of the IP block. |
depth | no | int | The level of details returned. |
var ip = ipApi.FindById(IpBlockId);
Creates an IP block. IP blocks are attached to a location, so you must specify a valid location
along with a size
parameter indicating the number of IP addresses you want to reserve in the IP block. Servers or other resources using an IP address from an IP block must be in the same location
.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
Location | yes | string | This must be one of the locations: us/las, us/ewr, de/fra, de/fkb. |
Size | yes | int | The size of the IP block you want. |
Name | no | string | A descriptive name for the IP block |
The following table outlines the locations currently supported:
Value | Country | City |
---|---|---|
us/las | United States | Las Vegas |
us/ewr | United States | Newark |
de/fra | Germany | Frankfurt |
de/fkb | Germany | Karlsruhe |
To create an IP block, establish the parameters and then call reserve_ipblock
.
var ipBlock = new IpBlock { Properties = new IpBlockProperties { Location = "us/las", Size = 1 } };
ipBlock = ipApi.Create(ipBlock);
Deletes the specified IP Block.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
IpBlockId | yes | string | The ID of the IP block. |
After retrieving an IP block, either by getting it by id, or as a create response object, you can call the Delete
method directly.
var resp = ipApi.Delete(IpBlockId);
Retrieve a list of LANs within the virtual data center.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
DatacenterId | yes | string | The ID of the VDC. |
depth | no | int | The level of details returned. |
var list = lanApi.FindAll(DatacenterId);
Creates a LAN within a virtual data center.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
DatacenterId | yes | string | The ID of the VDC. |
Name | no | string | The name of your LAN. |
Public | Yes | bool | Boolean indicating if the LAN faces the public Internet or not. |
Nics | no | object | A collection of NICs associated with the LAN. |
var lan = lanApi.Create(DatacenterId, new Lan
{
Properties = new LanProperties
{
Public = true,
Name = ".Net V2 - Test " + DateTime.Now.ToShortTimeString()
},
Entities=new LanEntities{
Nics= new LanNics
{
Items= new List<Nic>()
{
new Nic
{
Id=nic.Id
}
}
}
}
});
Retrieves the attributes of a given LAN.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
DatacenterId | yes | string | The ID of the VDC. |
LanId | yes | int | The ID of the LAN. |
depth | no | int | The level of details returned. |
var lan = lanApi.FindById(DatacenterId, LanId);
Perform updates to attributes of a LAN.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
DatacenterId | yes | string | The ID of the VDC. |
LanId | yes | int | The ID of the LAN. |
Name | no | string | A descriptive name for the LAN. |
Public | no | bool | Boolean indicating if the LAN faces the public Internet or not. |
IpFailover | no | object | A collection of IP fail-over instances. |
After retrieving a LAN, either by getting it by id, or as a create response object, you can change its properties and call the PartialUpdate
method:
var ipFailover = new IpFailover
{
Ip = "208.95.36.102",
NicUuid = "75f5027d-6487-4e21-8afc-e03678e764c4"
};
var lanProperties = new LanProperties();
lanProperties.IpFailover = new List<IpFailover>();
lanProperties.IpFailover.Add(ipFailover);
lanProperties.Public = true;
var updated = lanApi.PartialUpdate(DatacenterId, LanId, lanProperties);
NOTE: You can also use Update()
, for that operation you will update all the properties.
Deletes the specified LAN.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
DatacenterId | yes | string | The ID of the VDC. |
LanId | yes | string | The ID of the LAN. |
After retrieving a LAN, either by getting it by id, or as a create response object, you can call the Delete
method directly.
lanApi.Delete(DatacenterId,LanId);
Create an instance of the api class:
NetworkInterfacesApi nicApi = new NetworkInterfacesApi(Configuration);
Retrieve a list of LANs within the virtual data center.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
DatacenterId | yes | string | The ID of the VDC. |
ServerId | yes | string | The ID of the server. |
depth | no | int | The level of details returned. |
var list = nicApi.FindAll(DatacenterId, ServerId);
Retrieves the attributes of a given NIC.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
DatacenterId | yes | string | The ID of the VDC. |
ServerId | yes | string | The ID of the server. |
NicId | yes | string | The ID of the NIC. |
depth | no | int | The level of details returned. |
var nic = nicApi.FindById(DatacenterId, ServerId, NicId);
Adds a NIC to the target server.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
DatacenterId | yes | string | The ID of the VDC. |
ServerId | yes | string | The ID of the server. |
Name | no | string | The name of the NIC. |
Ips | no | string collection | IPs assigned to the NIC. This can be a collection. |
Dhcp | no | bool | Set to FALSE if you wish to disable DHCP on the NIC. Default: TRUE. |
Lan | yes | int | The LAN ID the NIC will sit on. If the LAN ID does not exist it will be created. |
Nat | no | bool | Indicates the private IP address has outbound access to the public internet. |
FirewallActive | no | bool | Once you add a firewall rule this will reflect a true value. |
FirewallRules | no | object | A list of firewall rules associated to the NIC represented as a collection. |
var nic = new Nic { Properties = new NicProperties { Lan = 1, Nat = false } };
nic = nicApi.Create(DatacenterId, ServerId, nic);
You can update -- in full or partially -- various attributes on the NIC; however, some restrictions are in place:
The primary address of a NIC connected to a load balancer can only be changed by changing the IP of the load balancer. You can also add additional reserved, public IPs to the NIC.
The user can specify and assign private IPs manually. Valid IP addresses for private networks are 10.0.0.0/8, 172.16.0.0/12 or 192.168.0.0/16.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
DatacenterId | yes | string | The ID of the VDC. |
ServerId | yes | string | The ID of the server. |
NicId | yes | string | The ID of the NIC. |
Name | no | string | The name of the NIC. |
Ips | no | string collection | IPs assigned to the NIC represented as a collection. |
Dhcp | no | bool | Boolean value that indicates if the NIC is using DHCP or not. |
Lan | no | int | The LAN ID the NIC sits on. |
Nat | no | bool | Indicates the private IP address has outbound access to the public internet. |
After retrieving a NIC, either by getting it by id, or as a create response object, you can call the PartialUpdate
method directly.
var updated = nicApi.PartialUpdate(DatacenterId, ServerId, NicId, new NicProperties { Name ="Update", Ips = new System.Collections.Generic.List<string> { "10.8.52.225", "1.1.1.1" } });
NOTE: You can also use Update()
, for that operation you will update all the properties.
Deletes the specified NIC.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
DatacenterId | yes | string | The ID of the VDC. |
ServerId | yes | string | The ID of the server. |
NicId | yes | string | The ID of the NIC. |
After retrieving a NIC, either by getting it by id, or as a create response object, you can call the Delete
method directly.
var resp = nicApi.Delete(DatacenterId, ServerId, NicId);
Create an instace of the api class:
FirewallRuleApi fwApi = new FirewallRuleApi(Configuration);
Retrieves a list of firewall rules associated with a particular NIC.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
DatacenterId | yes | string | The ID of the VDC. |
ServerId | yes | string | The ID of the server. |
NicId | yes | string | The ID of the NIC. |
depth | no | int | The level of details returned. |
var list = fwApi.FindAll(DatacenterId, ServerId, NicId);
Retrieves the attributes of a given firewall rule.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
DatacenterId | yes | string | The ID of the VDC. |
ServerId | yes | string | The ID of the server. |
NicId | yes | string | The ID of the NIC. |
FirewallRuleId | yes | string | The ID of the firewall rule. |
depth | no | int | The level of details returned. |
var newFw = fwApi.FindById(DatacenterId, ServerId, NicId, FirewallRuleId);
This will add a firewall rule to the NIC.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
DatacenterId | yes | string | The ID of the VDC. |
ServerId | yes | string | The ID of the server. |
NicId | yes | string | The ID of the NIC. |
Name | no | string | The name of the firewall rule. |
Protocol | yes | string | The protocol for the rule: TCP, UDP, ICMP, ANY. |
SourceMac | no | string | Only traffic originating from the respective MAC address is allowed. Valid format: aa:bb:cc:dd:ee:ff. A null value allows all source MAC address. |
SourceIp | no | string | Only traffic originating from the respective IPv4 address is allowed. A null value allows all source IPs. |
TargetIp | no | string | In case the target NIC has multiple IP addresses, only traffic directed to the respective IP address of the NIC is allowed. A null value allows all target IPs. |
PortRangeStart | no | string | Defines the start range of the allowed port (from 1 to 65534) if protocol TCP or UDP is chosen. Leave PortRangeStart and PortRangeEnd value as null to allow all ports. |
PortRangeEnd | no | string | Defines the end range of the allowed port (from 1 to 65534) if the protocol TCP or UDP is chosen. Leave PortRangeStart and PortRangeEnd value as null to allow all ports. |
IcmpType | no | string | Defines the allowed type (from 0 to 254) if the protocol ICMP is chosen. A null value allows all types. |
IcmpCode | no | string | Defines the allowed code (from 0 to 254) if protocol ICMP is chosen. A null value allows all codes. |
var fw = new FirewallRule { Properties = new FirewallruleProperties { Protocol = "TCP", Name = ".Net" } };
fw = fwApi.Create(DatacenterId, ServerId, NicId, fw);
Perform updates to attributes of a firewall rule.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
DatacenterId | yes | string | The ID of the VDC. |
ServerId | yes | string | The ID of the server. |
NicId | yes | string | The ID of the NIC. |
FirewallRuleId | yes | string | The ID of the firewall rule. |
Name | no | string | The name of the firewall rule. |
SourceMac | no | string | Only traffic originating from the respective MAC address is allowed. Valid format: aa:bb:cc:dd:ee:ff. A null value allows all source MAC address. |
SourceIp | no | string | Only traffic originating from the respective IPv4 address is allowed. A null value allows all source IPs. |
TargetIp | no | string | In case the target NIC has multiple IP addresses, only traffic directed to the respective IP address of the NIC is allowed. A null value allows all target IPs. |
PortRangeStart | no | string | Defines the start range of the allowed port (from 1 to 65534) if protocol TCP or UDP is chosen. Leave port_range_start and port_range_end value as null to allow all ports. |
PortRangeEnd | no | string | Defines the end range of the allowed port (from 1 to 65534) if the protocol TCP or UDP is chosen. Leave port_range_start and port_range_end value as null to allow all ports. |
IcmpType | no | string | Defines the allowed type (from 0 to 254) if the protocol ICMP is chosen. A null value allows all types. |
IcmpCode | no | string | Defines the allowed code (from 0 to 254) if protocol ICMP is chosen. A null value allows all codes. |
After retrieving a firewall rule, either by getting it by id, or as a create response object, you can change its properties and call the PartialUpdate
method:
var updated = fwApi.PartialUpdate(DatacenterId, ServerId, NicId, FirewallRuleId, new FirewallruleProperties {Name = "Updated" });
NOTE: You can also use Update()
, for that operation you will update all the properties.
Removes the specific firewall rule.
Name | Required | Type | Description |
---|---|---|---|
DatacenterId | yes | string | The ID of the VDC. |
ServerId | yes | string | The ID of the server. |
NicId | yes | string | The ID of the NIC. |
FirewallRuleId | yes | string | The ID of the firewall rule. |
After retrieving a firewall rule, either by getting it by id, or as a create response object, you can call the Delete
method directly.
var resp = fwApi.Delete(DatacenterId, ServerId, NicId, FirewallRuleId);
Create an instace of the api class:
LoadBalancerApi lbApi = new LoadBalancerApi(Configuration)
Retrieve a list of load balancers within the data center.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
DatacenterId | yes | string | The ID of the VDC. |
depth | no | int | The level of details returned. |
var list = lbApi.FindAll(DatacenterId);
Retrieves the attributes of a given load balancer.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
DatacenterId | yes | string | The ID of the VDC. |
LoadBalancerId | yes | string | The ID of the load balancer. |
depth | no | int | The level of details returned. |
var lb = lbApi.FindById(DatacenterId, LoadBalancerId);
Creates a load balancer within the virtual data center. Load balancers can be used for public or private IP traffic.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
DatacenterId | yes | string | The ID of the VDC. |
Name | yes | string | The name of the load balancer. |
Ip | no | string | IPv4 address of the load balancer. All attached NICs will inherit this IP. |
Dhcp | no | bool | Indicates if the load balancer will reserve an IP using DHCP. |
BalancedNics | no | string collection | List of NICs taking part in load-balancing. All balanced NICs inherit the IP of the load balancer. |
var lb = new Loadbalancer
{
Properties = new LoadbalancerProperties
{
Name = ".Net V2 - Test " + DateTime.Now.ToShortTimeString()
}
};
lb = lbApi.Create(DatacenterId, lb, depth: 5);
Perform updates to attributes of a load balancer.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
DatacenterId | yes | string | The ID of the VDC. |
LoadBalancerId | yes | string | The ID of the load balancer. |
Name | no | string | The name of the load balancer. |
Ip | no | string | The IP of the load balancer. |
Dhcp | no | bool | Indicates if the load balancer will reserve an IP using DHCP. |
After retrieving a load balancer, either by getting it by id, or as a create response object, you can change it's properties and call the PartialUpdate
method:
var newLb = lbApi.PartialUpdate(DatacenterId, LoadBalancerId, new LoadbalancerProperties { Name = "Updated" });
NOTE: You can also use Update()
, for that operation you will update all the properties.
Deletes the specified load balancer.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
DatacenterId | yes | string | The ID of the VDC. |
LoadBalancerId | yes | string | The ID of the load balancer. |
After retrieving a load balancer, either by getting it by id, or as a create response object, you can call the Delete
method directly.
var resp = lbApi.Delete(DatacenterId, LoadBalancerId);
This will retrieve a list of NICs associated with the load balancer.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
DatacenterId | yes | string | The ID of the VDC. |
LoadBalancerId | yes | string | The ID of the load balancer. |
depth | no | int | The level of details returned. |
After retrieving a load balancer, either by getting it by id, or as a create response object, you can call the FindAll
method directly.
var BalancedNics = lbApi.FindAll(DatacenterId, LoadBalancerId, depth);
Retrieves the attributes of a given load balanced NIC.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
DatacenterId | yes | string | The ID of the VDC. |
LoadBalancerId | yes | string | The ID of the load balancer. |
NicId | yes | string | The ID of the NIC. |
depth | no | int | The level of details returned. |
After retrieving a load balancer, either by getting it by id, or as a create response object, you can call the get_loadbalanced_nic
method directly.
var balancedNic = lbApi.FindById(DatacenterId, LoadBalancerId, NicId, depth);
This will associate a NIC to a load balancer, enabling the NIC to participate in load-balancing.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
DatacenterId | yes | string | The ID of the VDC. |
LoadBalancerId | yes | string | The ID of the load balancer. |
NicId | yes | string | The ID of the NIC. |
After retrieving a load balancer, either by getting it by id, or as a create response object, you can call the AttachNic
method directly.
NetworkInterfacesApi nicApi = new NetworkInterfacesApi(Configuration);
var attachedNic = nicApi.AttachNic(DatacenterId, LoadBalancerId, new Nic { Id = NicId });
Removes the association of a NIC with a load balancer.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
DatacenterId | yes | string | The ID of the VDC. |
LoadBalancerId | yes | string | The ID of the load balancer. |
NicId | yes | string | The ID of the NIC. |
After retrieving a load balancer, either by getting it by id, or as a create response object, you can call the DetachNic
method directly.
var resp = nicApi.DetachNic(DatacenterId, LoadBalancerId, NicId);
Create an instace of the api class:
GroupApi groupApi = new GroupApi(Configuration);
Retrieves a list of all groups.
Name | Required | Type | Description |
---|---|---|---|
depth | no | int | The level of details returned. |
var groups = groupApi.FindAll();
Retrieves the attributes of a given group.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
GroupId | yes | string | The ID of the group. |
depth | no | int | The level of details returned. |
var group = groupApi.FindById(GroupId);
Creates a new group and set group privileges.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
Name | yes | string | The ID of the group. |
CreateDatacenter | no | bool | Indicates if the group is allowed to create virtual data centers. |
CreateSnapshot | no | bool | Indicates if the group is allowed to create snapshots. |
ReserveIp | no | bool | Indicates if the group is allowed to reserve IP addresses. |
AccessActivityLog | no | bool | Indicates if the group is allowed to access activity log. |
var groupProps = new Group
{
Properties = new GroupProperties
{
Name = "My Group",
CreateDataCenter = true,
CreateSnapshot = true,
ReserveIp = true,
AccessActivityLog = false
}
};
var group = groupApi.Create(groupProps);
Updates a group's name or privileges.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
GroupId | yes | string | The ID of the group. |
Name | yes | string | The ID of the group. |
CreateDatacenter | no | bool | Indicates if the group is allowed to create virtual data centers. |
CreateSnapshot | no | bool | Indicates if the group is allowed to create snapshots. |
ReserveIp | no | bool | Indicates if the group is allowed to reserve IP addresses. |
AccessActivityLog | no | bool | Indicates if the group is allowed to access activity log. |
var newProps = new Group
{
Properties = new GroupProperties
{
Name = "My Group",
CreateDataCenter = true,
CreateSnapshot = true,
ReserveIp = true,
AccessActivityLog = false
}
};
var group = groupApi.Update(GroupId, newProps);
Deletes the specified group.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
GroupId | yes | string | The ID of the group. |
var response = groupApi.Delete(GroupId);
Retrieves a list of all users that are members of a particular group.
Name | Required | Type | Description |
---|---|---|---|
GroupId | yes | string | The ID of the group. |
depth | no | int | The level of details returned. |
var users = groupApi.FindAllGroupUsers(GroupId);
Adds an existing user to a group.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
GroupId | yes | string | The ID of the group. |
UserId | yes | string | The ID of the user. |
var user = groupApi.AddGroupUser(GroupId, UserId);
Removes a user from a group.
Name | Required | Type | Description |
---|---|---|---|
GroupId | yes | string | The ID of the group. |
UserId | yes | string | The ID of the user. |
var response = groupApi.RemoveGroupUser(GroupId, UserId);
Create an instace of the api class:
ShareApi shareApi = new ShareApi(Configuration);
Retrieves a list of all shares though a group.
Name | Required | Type | Description |
---|---|---|---|
GroupId | yes | string | The ID of the group. |
depth | no | int | The level of details returned. |
var shares = shareApi.FindAll(GroupId);
Retrieves a specific resource share available to a group.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
GroupId | yes | string | The ID of the group. |
ResourceId | yes | string | The ID of the resource. |
depth | no | int | The level of details returned. |
var share = shareApi.FindById(GroupId, ResourceId);
Shares a resource through a group.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
GroupId | yes | string | The ID of the group. |
ResourceId | yes | string | The ID of the resource. |
EditPrivilege | no | bool | Indicates that the group has permission to edit privileges on the resource. |
SharePrivilege | no | bool | Indicates that the group has permission to share the resource. |
var shareReq = new Share
{
Properties = new ShareProperties
{
EditPrivilege = false,
SharePrivilege = false
}
};
var share = shareApi.Add(GroupId, ResourceId, shareReq);
Updates the permissions of a group for a resource share.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
GroupId | yes | string | The ID of the group. |
ResourceId | yes | string | The ID of the resource. |
EditPrivilege | no | bool | Indicates that the group has permission to edit privileges on the resource. |
SharePrivilege | no | bool | Indicates that the group has permission to share the resource. |
var share = shareApi.Update(GroupId, ResourceId, new Share { Properties = new ShareProperties { SharePrivilege = false } });
Removes a resource share from a group.
Name | Required | Type | Description |
---|---|---|---|
GroupId | yes | string | The ID of the group. |
ResourceId | yes | string | The ID of the resource. |
var response = shareApi.Remove(GroupId, ResourceId);
Create an instace of the api class:
UserApi userApi = new UserApi(Configuration);
Retrieves a list of all users.
Name | Required | Type | Description |
---|---|---|---|
depth | no | int | The level of details returned. |
var users = userApi.FindAll();
Retrieves a single user.
Name | Required | Type | Description |
---|---|---|---|
UserId | yes | string | The ID of the user. |
depth | no | int | The level of details returned. |
var user = userApi.FindById(UserId);
Creates a new user.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
FirstName | yes | string | A name for the user. |
LastName | yes | string | A name for the user. |
yes | string | An e-mail address for the user. | |
Password | yes | string | A password for the user. |
Administrator | no | bool | Assigns the user have administrative rights. |
ForceSecAuth | no | bool | Indicates if secure (two-factor) authentication should be forced for the user. |
var userReq = new User
{
Properties = new UserProperties
{
FirstName = "John",
LastName = "Doe",
Email = "user1@example.com",
Password = "abc123-321CBA",
Administrator = true,
ForceSecAuth = false
}
};
var user = userApi.Create(userReq);
Updates an existing user.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
UserId | yes | string | The ID of the user. |
FirstName | yes | string | A name for the user. |
LastName | yes | string | A name for the user. |
yes | string | An e-mail address for the user. | |
Administrator | yes | bool | Assigns the user have administrative rights. |
ForceSecAuth | yes | bool | Indicates if secure (two-factor) authentication should be forced for the user. |
var userReq = new User
{
Properties = new UserProperties
{
FirstName = "John",
LastName = "Doe",
Email = "user1@example.com",
Administrator = true,
ForceSecAuth = false
}
};
var user = userApi.Update(UserId, userReq);
Removes a user.
Name | Required | Type | Description |
---|---|---|---|
UserId | yes | string | The ID of the user. |
var response = userApi.Delete(UserId);
Create an instace of the api class:
ResourceApi resourceApi = new ResourceApi(Configuration);
Retrieves a list of all resources. Alternatively, Retrieves all resources of a particular type.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
depth | no | int | The level of details returned. |
var resources = resourceApi.FindAll();
Retrieves all resources of a particular type.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
Type | yes | ResourceType | The resource type enum with the values: datacenter , image , snapshot or ipblock . |
depth | no | int | The level of details returned. |
var resources = resourceApi.FindAllByType(ResourceType.datacenter);
Retrieves a single resource of a particular type.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
Type | yes | ResourceType | The resource type enum with the values: datacenter , image , snapshot or ipblock . |
ResourceId | yes | string | The ID of the resource. |
depth | no | int | The level of details returned. |
var resources = resourceApi.FindAllByType(ResourceType.ipblock, ResourceId);
Create an instace of the api class:
ContractResourcesApi crApi = new ContractResourcesApi(Configuration);
Retrieves information about the resource limits for a particular contract and the current resource usage.
Name | Required | Type | Description |
---|---|---|---|
depth | no | int | The level of details returned. |
var contracts = crApi.List();
Each call to the ProfitBricks Cloud API is assigned a request ID. These operations can be used to get information about the requests that have been submitted and their current status.
Create an instace of the api class:
RequestApi reqApi = new RequestApi(Configuration);
Retrieve a list of requests.
var requests = reqApi.List();
Retrieves the attributes of a specific request.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
RequestId | yes | string | The ID of the request. |
var req = reqApi.Get(RequestId);
Retrieves the status of a request.
The following table describes the request arguments:
Name | Required | Type | Description |
---|---|---|---|
RequestId | yes | string | The ID of the request. |
RequestStatus req = reqApi.GetStatus(RequestId);
Here are a few examples on how to use the module.
The next few sections describe some commonly used features of this .NET library and provide implementation examples.
ProfitBricks utilizes the concept of virtual data centers. These are logically separated from one and the other and allow you to have a self-contained environment for all servers, volumes, networking, snapshots, and so forth. The goal is to replicate the experience of managing resources in a physical data center.
You are required to have a virtual data center created before you can create any other objects. Think of the virtual data center as a bucket in which all objects, such as servers and volumes, live.
The following code example shows you how to programmatically create a data center:
namespace ProfitbricksSDK.Example
{
class Program
{
static void Main(string[] args)
{
var configuration = new Configuration
{
Username = "username",
Password = "password",
};
var dcApi = new DataCenterApi(configuration);
// CreateDataCenterRequest.
// The only required field is DataCenterName.
// If location parameter is left empty the virtual data center will be created in the user's default region
var datacenter = new Datacenter
{
Properties = new DatacenterProperties
{
Name = "dotNet Test " + DateTime.Now.ToShortTimeString(),
Description = "Test for dotNet SDK",
Location = "us/las"
}
};
datacenter = dcApi.Create(datacenter);
}
}
}
You will want to exercise a bit of caution here. Removing a virtual data center will destroy all objects contained within that virtual data center -- servers, volumes, snapshots, and so on. The objects -- once removed -- will NOT be recoverable.
The following is an example of how to remove the virtual data center created above:
dcApi.Delete(datacenter.Id);
The following example illustrates how you would create a server and assign it a number of processing cores and memory. This example also shows specifying the CpuFamily as "INTEL_XEON" rather than the default of "AMD_OPTERON" You may wish to refer to the Cloud API documentation to see the complete list of attributes available.
var server = new Server
{
Properties = new ServerProperties
{
Name = "dotNet Test " + DateTime.Now.ToShortTimeString(),
Cores = 1,
Ram = 256,
CpuFamily = "INTEL_XEON"
}
};
// response will contain Id of a newly created server.
server = serverApi.Create(datacenter.Id, server);
One of the unique features of the ProfitBricks platform when compared with some other cloud providers is that it enables you to set the values for cores, memory, and volume size independently. You are not required to provision your servers by selecting from a set of pre-sized "instances."
ProfitBricks allows users to dynamically update the values assigned to cores, memory, and disk independently of each other. This removes the restriction of needing to upgrade to the next server or instance size just to get access to more memory. This helps manage costs as provisioned resources can be configured to match your actual resource needs.
The following code illustrates how you can update cores and memory:
server = serverApi.PartialUpdate(datacenter.Id, server.Id, new ServerProperties { Name = server.Properties.Name + " -Updated" });
ProfitBricks allows for the creation of multiple storage volumes. You can detach and reattach these on the fly. This allows for various scenarios such as re-attaching a failed OS disk to another server for possible recovery or moving a volume to another location and re-attaching it to a different server.
The following illustrates how you would create a new 40 GB volume:
//First we need to create a volume.
var volume = new Volume
{
Properties = new VolumeProperties
{
Size = 40,
Image = "fbaae2b2-c899-11e5-aa10-52540005ab80",
Type = "HDD",
Name = "dotNet Test " + DateTime.Now.ToShortTimeString(),
ImagePassword = "r@nd0m_S3cure%str1nG"
SshKeys = new System.Collections.Generic.List<string> { "hQGOEJeFL91EG3+l9TtRbWNjzhDVHeLuL3NWee6bekA=" }
}
};
volume = volumeApi.Create(datacenter.Id, volume);
Please review these notes about the create volume example:
-
The value supplied for Image is an example and is unlikely to be valid. ProfitBricks supplies a number of different images for various operating systems. These images are updated from time to time and these updates often result in a new UUID being issued. The .NET SDK can help you to locate valid image IDs. There are also CLI and PowerShell tools available on DevOps Central that can help you find the currently available UUIDs.
-
The value supplied for Type can be set to "HDD" or "SSD", depending on what storage type you want to use.
-
Volumes need to have either an ImagePassword or SshKeys set. It is possible to set both, however, SshKeys are only applicable to Linux images. Therefore you MUST provide an ImagePassword when creating volumes based on a Microsoft Windows Image.
To attach the volume to a server identified by server.Id:
//Then we are going to attach the newly volume to a server.
attachedVolumesApi.AttachVolume(datacenter.Id, server.Id, new Volume { Id = volume.Id });
To detach the volume from a server identified by server.Id:
//Here we are going to detach it from the server.
attachedVolumesApi.DetachVolume(datacenter.Id, server.Id, volume.Id);
You can pull various resource lists from your virtual data centers using the .NET library. The three most commonly queried resources are virtual data centers, servers, and volumes.
The following code illustrates how to pull these three list types:
var dcs = dcApi.FindAll(depth: 5);
var servers = serverApi.FindAll(datacenter.Id, depth: 5);
var volumes = volumeApi.FindAll(datacenter.Id, depth: 5);
The ProfitBricks cloud platform supports adding multiple NICs to a server. These NICs can be used to create different, segmented networks on the platform.
The sample below shows you how to add a second NIC to an existing server:
var nic = new Nic { Properties = new NicProperties { Lan = 1 , Dhcp = true, Name = "Nic name"} };
nic = nicApi.Create(datacenter.Id, server.Id, nic);
Please Note: Using this function will result in a running server being rebooted.
using Api;
using Client;
using Model;
using System;
namespace ProfitbricksSDK.Example
{
class Program
{
static void Main(string[] args)
{
var configuration = new Configuration
{
Username = "username",
Password = "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 = "dotNet Test " + DateTime.Now.ToShortTimeString(),
Description = "Test for dotNet SDK",
Location = "us/las"
}
};
// Response will contain Id of a newly created virtual data center.
datacenter = dcApi.Create(datacenter);
// CreateServer.
// DatacenterId: Defines the virtual 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: Amount of RAM memory (in MiB) to be assigned to the server.
var server = new Server
{
Properties = new ServerProperties
{
Name = "dotNet Test " + DateTime.Now.ToShortTimeString(),
Cores = 1,
Ram = 256
}
};
// response will contain the 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 virtual data center wherein the storage is to be created. If left empty, the storage will be created in a new virtual data center
// Size: Storage size (in GiB). Required Field.
// Type: SSD or HDD disk type, Required Field
// SshKeys: SSH keys, Optional field
var volume = new Volume
{
Properties = new VolumeProperties
{
Size = 4,
Image = "fbaae2b2-c899-11e5-aa10-52540005ab80",
Type = "HDD",
Name = "dotNet 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);
}
}
}
You can engage with us in the ProfitBricks DevOps Central community and we'll be more than happy to answer any questions you might have about using this .NET library.
Please report any issues or bugs your encounter using the GitHub Issue Tracker.
You can find a full list of tests inside the ProfitbricksSDK.Tests
project.
You can run tests from the Visual Studio Test Explorer or Developer Command Prompt.
MSTest /TestContainer:ProfitBricksAllTests.orderedtest
- Fork it ( https://github.com/profitbricks/profitbricks-sdk-net/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request