Cloud API

This documentation contains information about the usage of the Cloud API methods to manage Virtual Servers and Private Clouds.


Virtual Servers

The Virtual Servers endpoints provide you the ability to retrieve information and interact with the Virtual Servers that you have at LeaseWeb. This resource gives you control over each virtual server. You can power on, power off, reboot, reinstall and retrieve administrative information from all of your virtual servers via this resource.

List your Virtual Servers

curl -X GET -H "X-Lsw-Auth: ****-****-****-****" "https://api.leaseweb.com/cloud/v2/virtualServers"
<?php

$resource = '/virtualServers';
$apiKey   = '****-****-****-****';

$apiUrl   = 'https://api.leaseweb.com/cloud/v2';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiUrl . $resource);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-Lsw-Auth: $apiKey"));
$output = curl_exec($ch);

echo $output;
import requests

apiUrl = 'https://api.leaseweb.com/cloud/v2/virtualServers'
headers = {"X-Lsw-Auth":"****-****-****-****"}

# Send synchronously
try:
  response = requests.get(apiUrl, headers=headers)
  content = response.text
  # Success
  print(content)
except requests.exceptions, e:
  # Exception
  print('Exception during request')

Response Body

{
  "virtualServers": [
    {
      "id": "222903",
      "reference": "Web server",
      "customerId": "1301178860",
      "dataCenter": "AMS-01",
      "cloudServerId": null,
      "state": "STOPPED",
      "firewallState": "DISABLED",
      "template": "Ubuntu 14.04 64 40 20140707T1340",
      "serviceOffering": "S",
      "sla": "Bronze",
      "contract": {
        "id": "30000778",
        "startsAt": "2016-02-01T00:00:00+0200",
        "endsAt": "2017-01-31T00:00:00+0200",
        "billingCycle": 12,
        "billingFrequency": "MONTH",
        "pricePerFrequency": 4.7,
        "currency": "EUR"
      },
      "hardware": {
        "cpu": {
          "cores": 1
        },
        "memory": {
          "unit": "MB",
          "amount": 1024
        },
        "storage": {
          "unit": "GB",
          "amount": 40
        }
      },
      "iso": null,
      "ips": [
        {
          "ip": "10.11.116.130",
          "version": 4,
          "type": "PUBLIC"
        }
      ]
    },
    {
      "id": "301708",
      "reference": null,
      "customerId": "1301178860",
      "dataCenter": "AMS-01",
      "cloudServerId": null,
      "state": "STOPPED",
      "firewallState": "ENABLED",
      "template": "CentOS 7.0 64 60 20140711T1039",
      "serviceOffering": "M",
      "sla": "Bronze",
      "contract": {
        "id": "30000779",
        "startsAt": "2016-02-01T00:00:00+0200",
        "endsAt": "2017-01-31T00:00:00+0200",
        "billingCycle": 12,
        "billingFrequency": "MONTH",
        "pricePerFrequency": 4.7,
        "currency": "EUR"
      },
      "hardware": {
        "cpu": {
          "cores": 2
        },
        "memory": {
          "unit": "MB",
          "amount": 2048
        },
        "storage": {
          "unit": "GB",
          "amount": 60
        }
      },
      "iso": {
        "id": "9eadbe14-69be-4dee-8f56-5ebb23bb3c33",
        "name": "Knoppix",
        "displayName": "Knoppix"
      },
      "ips": [
        {
          "ip": "10.11.116.132",
          "version": 4,
          "type": "PUBLIC"
        }
      ]
    }
  ],
  "_metadata": {
    "totalCount": 2,
    "offset": 0,
    "limit": 10
  }
}

To retrieve a list of all of your virtual servers, send a GET request to /cloud/v2/virtualServers.

The following query parameters are available:

Name Type Required Description Example
limit integer No Maximum amount of virtual servers to be retrieved, for pagination purposes. 10
offset integer No Result offset, for pagination purposes. 0

The response will be a JSON object with following keys:

Name Type Description
virtualServers object Array of your virtual servers.
_metadata object Metadata of the request, containing the total number of virtual servers in the collection, the limit and the offset.

The virtualServers object consists of array of virtualServer having the following attributes:

Name Type Description
id string Identifier of the virtual server resource.
reference string The reference description for the virtual server.
customerId string Your customer identifier.
dataCenter string Data center code where the virtual server is located.
cloudServerId string Cloud Server identifier (in case your virtual server is associated to one).
state string State of your virtual server. Possible values are: RUNNING, STOPPED, STARTING, STOPPING, UNKNOWN.
firewallState string State of the firewall of the virtual server. Possible values are: DISABLED, ENABLED, UNKNOWN.
template string Name of the Operating System template of your virtual server.
serviceOffering string Service Offering of your virtual server. Possible values are: S, M, L, XL.
sla string Service Level Agreement of your virtual server.
contract object Virtual server contract information.
hardware object Virtual server hardware information.
iso object ISO information if there is an ISO image attached to the virtual server, otherwise the value will be null.
ips object Information about the virtual server’s IP address(es).
networkTraffic object Network traffic associated to the virtual server.

The contract object contains the following attributes:

Name Type Description
id string Virtual server contract identifier.
startsAt date Contractual date for the virtual server.
endsAt date Contractual end date for the virtual server.
billingCycle integer Applied billing cycle.
billingFrequency string Applied billing frequency.
currency string Currency of the contract according to ISO-4217.

The hardware object contains the following attributes:

Name Type Description
cpu object CPU information.
memory object Memory information.
storage object Storage information.

The cpu object contains the following attributes:

Name Type Description
cores integer Number of cores that the virtual server has.

The memory object contains the following attributes:

Name Type Description
unit string Unit in which the amount attribute is measured.
amount integer Amount of memory that the virtual server has.

The storage object contains the following attributes:

Name Type Description
unit string Unit in which the amount attribute is measured.
amount integer Amount of storage that the virtual server has.

The iso object contains the following attributes:

Name Type Description
id string ISO identifier.
name string ISO name.
displayName string ISO friendly name.

The ips object consists of array of ip objects having the following attributes:

Name Type Description
ip string IP address
version integer IP address version. Possible values are: 4, 6.
type string IP type. Possible values are: PUBLIC, PRIVATE.

The networkTraffic object contains the following attributes:

Name Type Description
type string Type of network traffic. Possible values are: DATATRAFFIC.
trafficType string Type of traffic. Possible values are: VOLUME, PREMIUM.
datatrafficUnit string Unit in which the data traffic limit is represented.
datatrafficLimit integer Data traffic limit for the virtual server.

The _metadata object contains the following attributes:

Name Type Description
totalCount integer Total amount of virtual servers that were found.
limit integer Maximum amount of virtual servers that will be included in the virtualServers array.
offset integer Offset of the request.

Retrieve a Virtual Server

curl -X GET -H "X-Lsw-Auth: ****-****-****-****" "https://api.leaseweb.com/cloud/v2/virtualServers/123456"
<?php

$resource = '/virtualServers/123456';
$apiKey   = '****-****-****-****';

$apiUrl   = 'https://api.leaseweb.com/cloud/v2';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiUrl . $resource);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-Lsw-Auth: $apiKey"));
$output = curl_exec($ch);

echo $output;
import requests

apiUrl = 'https://api.leaseweb.com/cloud/v2/virtualServers/123456'
headers = {"X-Lsw-Auth":"****-****-****-****"}

# Send synchronously
try:
  response = requests.get(apiUrl, headers=headers)
  content = response.text
  # Success
  print(content)
except requests.exceptions, e:
  # Exception
  print('Exception during request')

Response Body

{
  "id": "222903",
  "reference": "Web server",
  "customerId": "1301178860",
  "dataCenter": "AMS-01",
  "cloudServerId": null,
  "state": "STOPPED",
  "firewallState": "DISABLED",
  "template": "Ubuntu 14.04 64 40 20140707T1340",
  "serviceOffering": "S",
  "sla": "Bronze",
  "contract": {
    "id": "30000778",
    "startsAt": "2016-02-01T00:00:00+0200",
    "endsAt": "2017-01-31T00:00:00+0200",
    "billingCycle": 12,
    "billingFrequency": "MONTH",
    "pricePerFrequency": 4.7,
    "currency": "EUR"
  },
  "hardware": {
    "cpu": {
      "cores": 1
    },
    "memory": {
      "unit": "MB",
      "amount": 1024
    },
    "storage": {
      "unit": "GB",
      "amount": 40
    }
  },
  "iso": {
    "id": "9eadbe14-69be-4dee-8f56-5ebb23bb3c33",
    "name": "Knoppix",
    "displayName": "Knoppix"
  },
  "ips": [
    {
      "ip": "10.11.116.130",
      "version": 4,
      "type": "PUBLIC"
    }
  ]
}

To get information about a specific virtual server, send a GET request to /cloud/v2/virtualServers/{id}.

Name Type Description
id string Identifier of the virtual server resource.
reference string The reference description for the virtual server.
customerId string Your customer identifier.
dataCenter string Data center code where the virtual server is located.
cloudServerId string Cloud Server identifier (in case your virtual server is associated to one).
state string State of your virtual server. Possible values are: RUNNING, STOPPED, STARTING, STOPPING, UNKNOWN.
firewallState string State of the firewall of the virtual server. Possible values are: DISABLED, ENABLED, UNKNOWN.
template string Name of the Operating System template of your virtual server.
serviceOffering string Service Offering of your virtual server. Possible values are: S, M, L, XL.
sla string Service Level Agreement of your virtual server.
contract object Virtual server contract information.
hardware object Virtual server hardware information.
iso object ISO information if there is an ISO image attached to the virtual server, otherwise the value will be null.
ips object Information about the virtual server’s IP address(es).
networkTraffic object Network traffic associated to the virtual server.

The contract object contains the following attributes:

Name Type Description
id string Virtual server contract identifier.
startsAt date Contractual date for the virtual server.
endsAt date Contractual end date for the virtual server.
billingCycle integer Applied billing cycle.
billingFrequency string Applied billing frequency.
currency string Currency of the contract according to ISO-4217.

The hardware object contains the following attributes:

Name Type Description
cpu object CPU information.
memory object Memory information.
storage object Storage information.

The cpu object contains the following attributes:

Name Type Description
cores integer Number of cores that the virtual server has.

The memory object contains the following attributes:

Name Type Description
unit string Unit in which the amount attribute is measured.
amount integer Amount of memory that the virtual server has.

The storage object contains the following attributes:

Name Type Description
unit string Unit in which the amount attribute is measured.
amount integer Amount of storage that the virtual server has.

The iso object contains the following attributes:

Name Type Description
id string ISO identifier.
name string ISO name.
displayName string ISO friendly name.

The ips object consists of array of ip objects having the following attributes:

Name Type Description
ip string IP address
version integer IP address version. Possible values are: 4, 6.
type string IP type. Possible values are: PUBLIC, PRIVATE.

The networkTraffic object contains the following attributes:

Name Type Description
type string Type of network traffic. Possible values are: DATATRAFFIC.
trafficType string Type of traffic. Possible values are: VOLUME, PREMIUM.
datatrafficUnit string Unit in which the data traffic limit is represented.
datatrafficLimit integer Data traffic limit for the virtual server.

Power on

curl -X POST -H "X-Lsw-Auth: ****-****-****-****" "https://api.leaseweb.com/cloud/v2/virtualServers/123456/powerOn"
<?php

$resource = '/virtualServers/123456/powerOn';
$apiKey   = '****-****-****-****';

$data = array();

$apiUrl   = 'https://api.leaseweb.com/cloud/v2';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiUrl . $resource);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-Lsw-Auth: $apiKey"));
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $data );
$output = curl_exec($ch);

echo $output;
import requests

apiUrl = 'https://api.leaseweb.com/cloud/v2/virtualServers/123456/powerOn'
headers = {"X-Lsw-Auth":"****-****-****-****"}

data = {}

# Send synchronously
try:
  response = requests.post(apiUrl, data=data, headers=headers)
  content = response.text
  # Success
  print(content)
except requests.exceptions, e:
  # Exception
  print('Exception during request')

Response Body

{
  "id": "cs01.237daad0-2aed-4260-b0e4-488d9cd55607",
  "name": "virtualServers.powerOn",
  "status": "PENDING",
  "createdAt": "2016-12-31T01:00:59+00:00"
}

To power on the virtual server, send a POST request request to /cloud/v2/virtualServers/{id}/powerOn. The power on call is an asynchronous call, meaning the power on will be performed as soon as possible.

The response will be a HTTP 202 Accepted with a JSON object containing the following attributes:

Name Type Description
id string Identifier of the job.
name string Friendly name of the job.
status string Status of the job. Possible values are: PENDING, COMPLETED.
createdAt date Date when the job was created.

Power off

curl -X POST -H "X-Lsw-Auth: ****-****-****-****" "https://api.leaseweb.com/cloud/v2/virtualServers/123456/powerOff"
<?php

$resource = '/virtualServers/123456/powerOff';
$apiKey   = '****-****-****-****';

$data = array();

$apiUrl   = 'https://api.leaseweb.com/cloud/v2';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiUrl . $resource);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-Lsw-Auth: $apiKey"));
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $data );
$output = curl_exec($ch);

echo $output;
import requests

apiUrl = 'https://api.leaseweb.com/cloud/v2/virtualServers/123456/powerOff'
headers = {"X-Lsw-Auth":"****-****-****-****"}

data = {}

# Send synchronously
try:
  response = requests.post(apiUrl, data=data, headers=headers)
  content = response.text
  # Success
  print(content)
except requests.exceptions, e:
  # Exception
  print('Exception during request')

Response Body

{
  "id": "cs01.237daad0-2aed-4260-b0e4-488d9cd55607",
  "name": "virtualServers.powerOff",
  "status": "PENDING",
  "createdAt": "2016-12-31T01:00:59+00:00"
}

To power off the virtual server, send a POST request request to /cloud/v2/virtualServers/{id}/powerOff. The power off call is an asynchronous call, meaning the power off will be performed as soon as possible.

The response will be a HTTP 202 Accepted with a JSON object containing the following attributes:

Name Type Description
id string Identifier of the job.
name string Friendly name of the job.
status string Status of the job. Possible values are: PENDING, COMPLETED.
createdAt date Date when the job was created.

Reboot

curl -X POST -H "X-Lsw-Auth: ****-****-****-****" "https://api.leaseweb.com/cloud/v2/virtualServers/123456/reboot"
<?php

$resource = '/virtualServers/123456/reboot';
$apiKey   = '****-****-****-****';

$data = array();

$apiUrl   = 'https://api.leaseweb.com/cloud/v2';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiUrl . $resource);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-Lsw-Auth: $apiKey"));
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $data );
$output = curl_exec($ch);

echo $output;
import requests

apiUrl = 'https://api.leaseweb.com/cloud/v2/virtualServers/123456/reboot'
headers = {"X-Lsw-Auth":"****-****-****-****"}

data = {}

# Send synchronously
try:
  response = requests.post(apiUrl, data=data, headers=headers)
  content = response.text
  # Success
  print(content)
except requests.exceptions, e:
  # Exception
  print('Exception during request')

Response Body

{
  "id": "cs01.237daad0-2aed-4260-b0e4-488d9cd55607",
  "name": "virtualServers.reboot",
  "status": "PENDING",
  "createdAt": "2016-12-31T01:00:59+00:00"
}

To reboot the virtual server, send a POST request request to /cloud/v2/virtualServers/{id}/reboot. The reboot call is an asynchronous call, meaning the reboot will be performed as soon as possible.

The response will be a HTTP 202 Accepted with a JSON object containing the following attributes:

Name Type Description
id string Identifier of the job.
name string Friendly name of the job.
status string Status of the job. Possible values are: PENDING, COMPLETED.
createdAt date Date when the job was created.

Reinstall

curl -X POST -H "X-Lsw-Auth: ****-****-****-****" "https://api.leaseweb.com/cloud/v2/virtualServers/123456/reinstall"
<?php

$resource = '/virtualServers/123456/reinstall';
$apiKey   = '****-****-****-****';

$data = array();

$apiUrl   = 'https://api.leaseweb.com/cloud/v2';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiUrl . $resource);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-Lsw-Auth: $apiKey"));
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $data );
$output = curl_exec($ch);

echo $output;
import requests

apiUrl = 'https://api.leaseweb.com/cloud/v2/virtualServers/123456/reinstall'
headers = {"X-Lsw-Auth":"****-****-****-****"}

data = {}

# Send synchronously
try:
  response = requests.post(apiUrl, data=data, headers=headers)
  content = response.text
  # Success
  print(content)
except requests.exceptions, e:
  # Exception
  print('Exception during request')

Response Body

{
  "id": "cs01.237daad0-2aed-4260-b0e4-488d9cd55607",
  "name": "virtualServers.reinstall",
  "status": "PENDING",
  "createdAt": "2016-12-31T01:00:59+00:00"
}

To reinstall the virtual server, send a POST request request to /cloud/v2/virtualServers/{id}/reinstall. The virtual server will be reinstalled with the same operating system that it currently has. The reinstall call is an asynchronous call, meaning the reinstall will be performed as soon as possible.

The response will be a HTTP 202 Accepted with a JSON object containing the following attributes:

Name Type Description
id string Identifier of the job.
name string Friendly name of the job.
status string Status of the job. Possible values are: PENDING, COMPLETED.
createdAt date Date when the job was created.

List the credentials

curl -X GET -H "X-Lsw-Auth: ****-****-****-****" "https://api.leaseweb.com/cloud/v2/virtualServers/123456/credentials/OPERATING_SYSTEM"
<?php

$resource = '/virtualServers/123456/credentials/OPERATING_SYSTEM';
$apiKey   = '****-****-****-****';

$apiUrl   = 'https://api.leaseweb.com/cloud/v2';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiUrl . $resource);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-Lsw-Auth: $apiKey"));
$output = curl_exec($ch);

echo $output;
import requests

apiUrl = 'https://api.leaseweb.com/cloud/v2/virtualServers/123456/credentials/OPERATING_SYSTEM'
headers = {"X-Lsw-Auth":"****-****-****-****"}

# Send synchronously
try:
  response = requests.get(apiUrl, headers=headers)
  content = response.text
  # Success
  print(content)
except requests.exceptions, e:
  # Exception
  print('Exception during request')

Response Body

{
  "credentials": [
    {
      "type": "OPERATING_SYSTEM",
      "username": "root"
    }
  ],
  "_metadata": {
    "totalCount": 1,
    "offset": 0,
    "limit": 10
  }
}

To retrieve a list of all of your credentials, send a GET request to /cloud/v2/virtualServers/{id}/credentials/{credentialType}. Please note that you will only be able to retrieve the last password that we configured in your server or control panel. If you changed it, the information retrieved by this API call will not work.

The following table explains the possible values that must be used in the URL parameters:

Name Type Description
credentialType string Type of credential pair. Possible values are OPERATING_SYSTEM, CONTROL_PANEL.

The following query parameters are available:

Name Type Required Description Example
limit integer No Maximum amount of credentials to be retrieved, for pagination purposes. 10
offset integer No Result offset, for pagination purposes. 0

The response will be a JSON object with following keys:

Name Type Description
credentials object Array of your credentials.
_metadata object Metadata of the request, containing the total number of credentials in the collection, the limit and the offset.

The credentials object consists of array of credentials having the following attributes:

Name Type Description
type string Type of credential pair. Possible values are OPERATING_SYSTEM, CONTROL_PANEL.
username string Name of the user in your server.

Please note that the password is not returned in this call, you must use the endpoint to get a credential by the username to retrieve it.

The _metadata object contains the following attributes:

Name Type Description
totalCount integer Total amount of credentials that were found.
limit integer Maximum amount of credentials that will be included in the credentials array.
offset integer Offset of the request.

Get the credentials of a user

curl -X GET -H "X-Lsw-Auth: ****-****-****-****" "https://api.leaseweb.com/cloud/v2/virtualServers/123456/credentials/OPERATING_SYSTEM/root"
<?php

$resource = '/virtualServers/123456/credentials/OPERATING_SYSTEM/root';
$apiKey   = '****-****-****-****';

$apiUrl   = 'https://api.leaseweb.com/cloud/v2';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiUrl . $resource);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-Lsw-Auth: $apiKey"));
$output = curl_exec($ch);

echo $output;
import requests

apiUrl = 'https://api.leaseweb.com/cloud/v2/virtualServers/123456/credentials/OPERATING_SYSTEM/root'
headers = {"X-Lsw-Auth":"****-****-****-****"}

# Send synchronously
try:
  response = requests.get(apiUrl, headers=headers)
  content = response.text
  # Success
  print(content)
except requests.exceptions, e:
  # Exception
  print('Exception during request')

Response Body

{
  "type": "OPERATING_SYSTEM",
  "username": "root",
  "password": "password123"
}

To get information about a specific credentials, send a GET request to /cloud/v2/virtualServers/{id}/credentials/{credentialType}/{username}. Please note that you will only be able to retrieve the last password that we configured in your server or control panel. If you changed it, the information retrieved by this API call will not work.

Name Type Description
type string Type of credential pair. Possible values are OPERATING_SYSTEM, CONTROL_PANEL.
username string Name of the user in your server.
password string Password associated to the username.

Get the datatraffic metrics

curl -X GET -H "X-Lsw-Auth: ****-****-****-****" "https://api.leaseweb.com/cloud/v2/virtualServers/123456/metrics/datatraffic?from=2017-07-01T00:00:00+00:00&to=2017-07-02T00:00:00+00:00&aggregation=SUM"
<?php

$resource = '/virtualServers/123456/metrics/datatraffic?from=2017-07-01T00:00:00+00:00&to=2017-07-02T00:00:00+00:00&aggregation=SUM';
$apiKey   = '****-****-****-****';

$apiUrl   = 'https://api.leaseweb.com/cloud/v2';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiUrl . $resource);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-Lsw-Auth: $apiKey"));
$output = curl_exec($ch);

echo $output;
import requests

apiUrl = 'https://api.leaseweb.com/cloud/v2/virtualServers/123456/metrics/datatraffic?from=2017-07-01T00:00:00+00:00&to=2017-07-02T00:00:00+00:00&aggregation=SUM'
headers = {"X-Lsw-Auth":"****-****-****-****"}

# Send synchronously
try:
  response = requests.get(apiUrl, headers=headers)
  content = response.text
  # Success
  print(content)
except requests.exceptions, e:
  # Exception
  print('Exception during request')

Response Body

{
  "_metadata": {
    "from": "2016-01-01T00:00:00+00:00",
    "to": "2016-01-31T23:59:59+00:00",
    "granularity": "DAY",
    "aggregation": "SUM"
  },
  "metrics": {
    "DATATRAFFIC_UP": {
      "unit": "B",
      "values": [
        {
          "timestamp": "2016-01-01T23:59:59+00:00",
          "value": 900
        },
        {
          "timestamp": "2016-01-31T23:59:59+00:00",
          "value": 2500
        }
      ]
    },
    "DATATRAFFIC_DOWN": {
      "unit": "B",
      "values": [
        {
          "timestamp": "2016-01-01T23:59:59+00:00",
          "value": 90
        },
        {
          "timestamp": "2016-01-31T23:59:59+00:00",
          "value": 250
        }
      ]
    }
  }
}

To retrieve a list of all of your datatraffic metrics, send a GET request to /cloud/v2/virtualServers/{id}/metrics/datatraffic.

The following query parameters are available:

Name Type Required Description
granularity string No Granularity of the request. Possible values are: NONE, 5MIN, HOUR, DAY, MONTH, YEAR.
aggregation string Yes Aggregation method of the returned values. Possible values are: SUM.
from date Yes Start of date interval in RFC3339 format.
to date Yes End of date interval in RFC3339 format.

The response will be a JSON object with following keys:

Name Type Description
metrics object Array of your datatraffic metrics.
_metadata object Metadata of the request.

The metrics object consists of array of metric having the following attributes:

Name Type Description
DATATRAFFIC_UP object Outgoing datatraffic metrics.
DATATRAFFIC_DOWN object Incoming datatraffic metrics.

The DATATRAFFIC_UP object contains the following attributes:

Name Type Description
unit string Unit in which the metric is measured.
values object Array of value objects that contains the metric measurements.

The DATATRAFFIC_DOWN object contains the following attributes:

Name Type Description
unit string Unit in which the metric is measured.
values object Array of value objects that contains the metric measurements.

The value object contains the following attributes:

Name Type Description
timestamp date Date where the metric was measured.
value object Metric value.

The _metadata object contains the following attributes:

Name Type Description
from date Start date (inclusive) in format RFC3339.
to date End timestamp (exclusive) in format RFC3339.
granularity string Granularity of the request. Possible values are: NONE, 5MIN, HOUR, DAY, MONTH, YEAR.
aggregation string Aggregation method of the returned values. Possible values are: SUM.

Private Clouds

The Private Clouds endpoints provide you the ability to retrieve information about the Private Clouds that you have at LeaseWeb. This resource gives you control over each private cloud.

List your Private Clouds

curl -X GET -H "X-Lsw-Auth: ****-****-****-****" "https://api.leaseweb.com/cloud/v2/privateClouds"
<?php

$resource = '/privateClouds';
$apiKey   = '****-****-****-****';

$apiUrl   = 'https://api.leaseweb.com/cloud/v2';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiUrl . $resource);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-Lsw-Auth: $apiKey"));
$output = curl_exec($ch);

echo $output;
import requests

apiUrl = 'https://api.leaseweb.com/cloud/v2/privateClouds'
headers = {"X-Lsw-Auth":"****-****-****-****"}

# Send synchronously
try:
  response = requests.get(apiUrl, headers=headers)
  content = response.text
  # Success
  print(content)
except requests.exceptions, e:
  # Exception
  print('Exception during request')

Response Body

{
  "privateClouds": [
    {
      "id": "218030",
      "customerId": "1301178860",
      "dataCenter": "AMS-01",
      "sla": "Bronze",
      "contract": {
        "id": "30000775",
        "startsAt": "2015-11-01T00:00:00+02:00",
        "endsAt": "2016-12-30T10:39:27+01:00",
        "billingCycle": 12,
        "billingFrequency": "MONTH",
        "pricePerFrequency": 0,
        "currency": "EUR"
      },
      "hardware": {
        "cpu": {
          "cores": 25
        },
        "memory": {
          "unit": "GB",
          "amount": 50
        },
        "storage": {
          "unit": "GB",
          "amount": 1
        }
      },
      "ips": [
        {
          "ip": "10.12.144.32",
          "version": 4,
          "type": "PUBLIC"
        },
        {
          "ip": "10.12.144.33",
          "version": 4,
          "type": "PUBLIC"
        }
      ],
      "networkTraffic": {
        "type": "DATATRAFFIC",
        "trafficType": "PREMIUM|VOLUME",
        "datatrafficUnit": "TB",
        "datatrafficLimit": 6
      }
    },
    {
      "id": "218031",
      "customerId": "1301178860",
      "dataCenter": "AMS-01",
      "sla": "Bronze",
      "contract": {
        "id": "30000775",
        "startsAt": "2015-11-01T00:00:00+02:00",
        "endsAt": "2016-12-30T10:39:27+01:00",
        "billingCycle": 12,
        "billingFrequency": "MONTH",
        "pricePerFrequency": 0,
        "currency": "EUR"
      },
      "hardware": {
        "cpu": {
          "cores": 10
        },
        "memory": {
          "unit": "GB",
          "amount": 30
        },
        "storage": {
          "unit": "TB",
          "amount": 1
        }
      },
      "ips": [
        {
          "ip": "10.12.144.63",
          "version": 4,
          "type": "PUBLIC"
        },
        {
          "ip": "10.12.144.64",
          "version": 4,
          "type": "PUBLIC"
        }
      ],
      "networkTraffic": {
        "type": "DATATRAFFIC",
        "trafficType": "PREMIUM|VOLUME",
        "datatrafficUnit": "TB",
        "datatrafficLimit": 6
      }
    }
  ],
  "_metadata": {
    "totalCount": 2,
    "offset": 0,
    "limit": 10
  }
}

To retrieve a list of all of your private clouds, send a GET request to /cloud/v2/privateClouds.

The following query parameters are available:

Name Type Required Description Example
limit integer No Maximum amount of private clouds to be retrieved, for pagination purposes. 10
offset integer No Result offset, for pagination purposes. 0

The response will be a JSON object with following keys:

Name Type Description
privateClouds object Array of your private clouds.
_metadata object Metadata of the request, containing the total number of private clouds in the collection, the limit and the offset.

The privateClouds object consists of array of privateCloud having the following attributes:

Name Type Description
id string Identifier of the private cloud resource.
customerId string Your customer identifier.
dataCenter string Data center code where the Private cloud is located.
sla string Service Level Agreement of your Private cloud.
contract object Private cloud contract information.
hardware object Private cloud hardware information.
ips object Information about the private cloud’s IP address(es).
networkTraffic object Network traffic associated to the Private cloud.

The contract object contains the following attributes:

Name Type Description
id string Private cloud contract identifier.
startsAt date Contractual date for the private cloud.
endsAt date Contractual end date for the private cloud.
billingCycle integer Applied billing cycle.
billingFrequency string Applied billing frequency.
currency string Currency of the contract according to ISO-4217.

The hardware object contains the following attributes:

Name Type Description
cpu object CPU information.
memory object Memory information.
storage object Storage information.

The cpu object contains the following attributes:

Name Type Description
cores integer Number of cores that the virtual server has.

The memory object contains the following attributes:

Name Type Description
unit string Unit in which the amount attribute is measured.
amount integer Amount of memory that the virtual server has.

The storage object contains the following attributes:

Name Type Description
unit string Unit in which the amount attribute is measured.
amount integer Amount of storage that the virtual server has.

The ips object consists of array of ip objects having the following attributes:

Name Type Description
ip string IP address
version integer IP address version. Possible values are: 4, 6.
type string IP type. Possible values are: PUBLIC, PRIVATE.

The networkTraffic object contains the following attributes:

Name Type Description
type string Type of network traffic. Possible values are: DATATRAFFIC.
trafficType string Type of traffic. Possible values are: VOLUME, PREMIUM.
datatrafficUnit string Unit in which the data traffic limit is represented.
datatrafficLimit integer Data traffic limit for the private cloud.

The _metadata object contains the following attributes:

Name Type Description
totalCount integer Total amount of private clouds that were found.
limit integer Maximum amount of private clouds that will be included in the privateClouds array.
offset integer Offset of the request.

Retrieve a Private Cloud

curl -X GET -H "X-Lsw-Auth: ****-****-****-****" "https://api.leaseweb.com/cloud/v2/privateClouds"
<?php

$resource = '/privateClouds';
$apiKey   = '****-****-****-****';

$apiUrl   = 'https://api.leaseweb.com/cloud/v2';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiUrl . $resource);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-Lsw-Auth: $apiKey"));
$output = curl_exec($ch);

echo $output;
import requests

apiUrl = 'https://api.leaseweb.com/cloud/v2/privateClouds'
headers = {"X-Lsw-Auth":"****-****-****-****"}

# Send synchronously
try:
  response = requests.get(apiUrl, headers=headers)
  content = response.text
  # Success
  print(content)
except requests.exceptions, e:
  # Exception
  print('Exception during request')

Response Body

{
  "id": "218030",
  "customerId": "1301178860",
  "dataCenter": "AMS-01",
  "sla": "Bronze",
  "contract": {
    "id": "30000775",
    "startsAt": "2015-11-01T00:00:00+02:00",
    "endsAt": "2016-12-30T10:39:27+01:00",
    "billingCycle": 12,
    "billingFrequency": "MONTH",
    "pricePerFrequency": 0,
    "currency": "EUR"
  },
  "hardware": {
    "cpu": {
      "cores": 25
    },
    "memory": {
      "unit": "GB",
      "amount": 50
    },
    "storage": {
      "unit": "GB",
      "amount": 1
    }
  },
  "ips": [
    {
      "ip": "10.12.144.32",
      "version": 4,
      "type": "PUBLIC"
    },
    {
      "ip": "10.12.144.33",
      "version": 4,
      "type": "PUBLIC"
    }
  ],
  "networkTraffic": {
    "type": "DATATRAFFIC",
    "trafficType": "PREMIUM|VOLUME",
    "datatrafficUnit": "TB",
    "datatrafficLimit": 6
  }
}

To get information about a specific private cloud, send a GET request to /cloud/v2/privateClouds.

Name Type Description
id string Identifier of the private cloud resource.
customerId string Your customer identifier.
dataCenter string Data center code where the Private cloud is located.
sla string Service Level Agreement of your Private cloud.
contract object Private cloud contract information.
hardware object Private cloud hardware information.
ips object Information about the private cloud’s IP address(es).
networkTraffic object Network traffic associated to the Private cloud.

The contract object contains the following attributes:

Name Type Description
id string Private cloud contract identifier.
startsAt date Contractual date for the private cloud.
endsAt date Contractual end date for the private cloud.
billingCycle integer Applied billing cycle.
billingFrequency string Applied billing frequency.
currency string Currency of the contract according to ISO-4217.

The hardware object contains the following attributes:

Name Type Description
cpu object CPU information.
memory object Memory information.
storage object Storage information.

The cpu object contains the following attributes:

Name Type Description
cores integer Number of cores that the virtual server has.

The memory object contains the following attributes:

Name Type Description
unit string Unit in which the amount attribute is measured.
amount integer Amount of memory that the virtual server has.

The storage object contains the following attributes:

Name Type Description
unit string Unit in which the amount attribute is measured.
amount integer Amount of storage that the virtual server has.

The ips object consists of array of ip objects having the following attributes:

Name Type Description
ip string IP address
version integer IP address version. Possible values are: 4, 6.
type string IP type. Possible values are: PUBLIC, PRIVATE.

The networkTraffic object contains the following attributes:

Name Type Description
type string Type of network traffic. Possible values are: DATATRAFFIC.
trafficType string Type of traffic. Possible values are: VOLUME, PREMIUM.
datatrafficUnit string Unit in which the data traffic limit is represented.
datatrafficLimit integer Data traffic limit for the private cloud.

List the credentials

curl -X GET -H "X-Lsw-Auth: ****-****-****-****" "https://api.leaseweb.com/cloud/v2/privateClouds/123456/credentials/REMOTE_MANAGEMENT"
<?php

$resource = '/privateClouds/123456/credentials/REMOTE_MANAGEMENT';
$apiKey   = '****-****-****-****';

$apiUrl   = 'https://api.leaseweb.com/cloud/v2';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiUrl . $resource);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-Lsw-Auth: $apiKey"));
$output = curl_exec($ch);

echo $output;
import requests

apiUrl = 'https://api.leaseweb.com/cloud/v2/privateClouds/123456/credentials/REMOTE_MANAGEMENT'
headers = {"X-Lsw-Auth":"****-****-****-****"}

# Send synchronously
try:
  response = requests.get(apiUrl, headers=headers)
  content = response.text
  # Success
  print(content)
except requests.exceptions, e:
  # Exception
  print('Exception during request')

Response Body

{
  "credentials": [
    {
      "type": "REMOTE_MANAGEMENT",
      "username": "root",
      "domain": "123456"
    }
  ],
  "_metadata": {
    "totalCount": 1,
    "offset": 0,
    "limit": 10
  }
}

To retrieve a list of all of your credentials, send a GET request to /cloud/v2/privateClouds/{id}/credentials/{credentialType}. Please note that you will only be able to retrieve the last password that we configured in your remote management tool. If you changed it, the information retrieved by this API call will not work.

The following table explains the possible values that must be used in the URL parameters:

Name Type Description
credentialType string Type of credential pair. Possible values are REMOTE_MANAGEMENT.

The following query parameters are available:

Name Type Required Description Example
limit integer No Maximum amount of credentials to be retrieved, for pagination purposes. 10
offset integer No Result offset, for pagination purposes. 0

The response will be a JSON object with following keys:

Name Type Description
credentials object Array of your credentials.
_metadata object Metadata of the request, containing the total number of credentials in the collection, the limit and the offset.

The credentials object consists of array of credentials having the following attributes:

Name Type Description
type string Type of credential pair. Possible values are REMOTE_MANAGEMENT.
username string Name of the user in the remote management tool.
domain string Domain name to log in to the remote management tool.

Please note that the password is not returned in this call, you must use the endpoint to get a credential by the username to retrieve it.

The _metadata object contains the following attributes:

Name Type Description
totalCount integer Total amount of credentials that were found.
limit integer Maximum amount of credentials that will be included in the credentials array.
offset integer Offset of the request.

Get the credentials of a user

curl -X GET -H "X-Lsw-Auth: ****-****-****-****" "https://api.leaseweb.com/cloud/v2/privateClouds/123456/credentials/OPERATING_SYSTEM/root"
<?php

$resource = '/privateClouds/123456/credentials/OPERATING_SYSTEM/root';
$apiKey   = '****-****-****-****';

$apiUrl   = 'https://api.leaseweb.com/cloud/v2';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiUrl . $resource);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-Lsw-Auth: $apiKey"));
$output = curl_exec($ch);

echo $output;
import requests

apiUrl = 'https://api.leaseweb.com/cloud/v2/privateClouds/123456/credentials/OPERATING_SYSTEM/root'
headers = {"X-Lsw-Auth":"****-****-****-****"}

# Send synchronously
try:
  response = requests.get(apiUrl, headers=headers)
  content = response.text
  # Success
  print(content)
except requests.exceptions, e:
  # Exception
  print('Exception during request')

Response Body

{
  "type": "REMOTE_MANAGEMENT",
  "username": "root",
  "password": "password123",
  "domain": "123456"
}

To get information about a specific credentials, send a GET request to /cloud/v2/privateClouds/{id}/credentials/{credentialType}/{username}. Please note that you will only be able to retrieve the last password that we configured in your server or control panel. If you changed it, the information retrieved by this API call will not work.

Name Type Description
type string Type of credential pair. Possible values are REMOTE_MANAGEMENT.
username string Name of the user in the remote management tool.
domain string Domain name to log in to the remote management tool.
password string Password associated to the username.

Get the datatraffic metrics

curl -X GET -H "X-Lsw-Auth: ****-****-****-****" "https://api.leaseweb.com/cloud/v2/privateClouds/123456/metrics/datatraffic?from=2017-07-01T00:00:00+00:00&to=2017-07-02T00:00:00+00:00&aggregation=SUM"
<?php

$resource = '/privateClouds/123456/metrics/datatraffic?from=2017-07-01T00:00:00+00:00&to=2017-07-02T00:00:00+00:00&aggregation=SUM';
$apiKey   = '****-****-****-****';

$apiUrl   = 'https://api.leaseweb.com/cloud/v2';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiUrl . $resource);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-Lsw-Auth: $apiKey"));
$output = curl_exec($ch);

echo $output;
import requests

apiUrl = 'https://api.leaseweb.com/cloud/v2/privateClouds/123456/metrics/datatraffic?from=2017-07-01T00:00:00+00:00&to=2017-07-02T00:00:00+00:00&aggregation=SUM'
headers = {"X-Lsw-Auth":"****-****-****-****"}

# Send synchronously
try:
  response = requests.get(apiUrl, headers=headers)
  content = response.text
  # Success
  print(content)
except requests.exceptions, e:
  # Exception
  print('Exception during request')

Response Body

{
  "_metadata": {
    "from": "2017-07-01T00:00:00+00:00",
    "to": "2017-07-01T00:00:00+00:00",
    "granularity": "MONTH",
    "aggregation": "SUM"
  },
  "metrics": {
    "DATATRAFFIC_UP": {
      "unit": "GB",
      "values": [
        {
          "timestamp": "2017-07-01T00:00:00+00:00",
          "value": 900
        },
        {
          "timestamp": "2017-07-02T00:00:00+00:00",
          "value": 2500
        }
      ]
    },
    "DATATRAFFIC_DOWN": {
      "unit": "GB",
      "values": [
        {
          "timestamp": "2017-07-01T00:00:00+00:00",
          "value": 90
        },
        {
          "timestamp": "2017-07-02T00:00:00+00:00",
          "value": 250
        }
      ]
    }
  }
}

To retrieve a list of all of your datatraffic metrics, send a GET request to /cloud/v2/privateClouds/{id}/metrics/datatraffic.

The following query parameters are available:

Name Type Required Description
granularity string No Granularity of the request. Possible values are: NONE, 5MIN, HOUR, DAY, MONTH, YEAR.
aggregation string Yes Aggregation method of the returned values. Possible values are: SUM.
from date Yes Start of date interval in RFC3339 format.
to date Yes End of date interval in RFC3339 format.

The response will be a JSON object with following keys:

Name Type Description
metrics object Array of your datatraffic metrics.
_metadata object Metadata of the request.

The metrics object consists of array of metric having the following attributes:

Name Type Description
DATATRAFFIC_UP object Outgoing datatraffic metrics.
DATATRAFFIC_DOWN object Incoming datatraffic metrics.

The DATATRAFFIC_UP object contains the following attributes:

Name Type Description
unit string Unit in which the metric is measured.
values object Array of value objects that contains the metric measurements.

The DATATRAFFIC_DOWN object contains the following attributes:

Name Type Description
unit string Unit in which the metric is measured.
values object Array of value objects that contains the metric measurements.

The value object contains the following attributes:

Name Type Description
timestamp date Date where the metric was measured.
value object Metric value.

The _metadata object contains the following attributes:

Name Type Description
from date Start date (inclusive) in format RFC3339.
to date End timestamp (exclusive) in format RFC3339.
granularity string Granularity of the request. Possible values are: NONE, 5MIN, HOUR, DAY, MONTH, YEAR.
aggregation string Aggregation method of the returned values. Possible values are: SUM.

Get the CPU metrics

curl -X GET -H "X-Lsw-Auth: ****-****-****-****" "https://api.leaseweb.com/cloud/v2/privateClouds/123456/metrics/cpu?from=2017-07-01T00:00:00+00:00&to=2017-08-01T00:00:00+00:00&aggregation=MAX&granularity=MONTH"
<?php

$resource = '/privateClouds/123456/metrics/cpu?from=2017-07-01T00:00:00+00:00&to=2017-08-01T00:00:00+00:00&aggregation=MAX&granularity=MONTH';
$apiKey   = '****-****-****-****';

$apiUrl   = 'https://api.leaseweb.com/cloud/v2';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiUrl . $resource);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-Lsw-Auth: $apiKey"));
$output = curl_exec($ch);

echo $output;
import requests

apiUrl = 'https://api.leaseweb.com/cloud/v2/privateClouds/123456/metrics/cpu?from=2017-07-01T00:00:00+00:00&to=2017-08-01T00:00:00+00:00&aggregation=MAX&granularity=MONTH'
headers = {"X-Lsw-Auth":"****-****-****-****"}

# Send synchronously
try:
  response = requests.get(apiUrl, headers=headers)
  content = response.text
  # Success
  print(content)
except requests.exceptions, e:
  # Exception
  print('Exception during request')

Response Body

{
  "_metadata": {
    "from": "2017-07-01T00:00:00+00:00",
    "to": "2017-07-02T00:00:00+00:00",
    "granularity": "MONTH",
    "aggregation": "MAX"
  },
  "metrics": {
    "CPU": {
      "unit": "CORES",
      "values": [
        {
          "timestamp": "2017-07-01T00:00:00+00:00",
          "value": 24
        },
        {
          "timestamp": "2017-07-02T00:00:00+00:00",
          "value": 24
        }
      ]
    }
  }
}

To retrieve a list of all of your cpu metrics, send a GET request to /cloud/v2/privateClouds/{id}/metrics/cpu.

The following query parameters are available:

Name Type Required Description
granularity string No Granularity of the request. Possible values are: NONE, 5MIN, HOUR, DAY, MONTH, YEAR.
aggregation string Yes Aggregation method of the returned values. Possible values are: AVG.
from date Yes Start of date interval in RFC3339 format.
to date Yes End of date interval in RFC3339 format.

The response will be a JSON object with following keys:

Name Type Description
metrics object Array of your cpu metrics.
_metadata object Metadata of the request.

The metrics object consists of array of metric having the following attributes:

Name Type Description
CPU object CPU metrics.

The CPU object contains the following attributes:

Name Type Description
unit string Unit in which the metric is measured.
values object Array of value objects that contains the metric measurements.

The value object contains the following attributes:

Name Type Description
timestamp date Date where the metric was measured.
value object Metric value.

The _metadata object contains the following attributes:

Name Type Description
from date Start date (inclusive) in format RFC3339.
to date End timestamp (exclusive) in format RFC3339.
granularity string Granularity of the request. Possible values are: NONE, 5MIN, HOUR, DAY, MONTH, YEAR.
aggregation string Aggregation method of the returned values. Possible values are: AVG.

Get the memory metrics

curl -X GET -H "X-Lsw-Auth: ****-****-****-****" "https://api.leaseweb.com/cloud/v2/privateClouds/123456/metrics/memory?from=2017-07-01T00:00:00+00:00&to=2017-08-01T00:00:00+00:00&aggregation=MAX&granularity=MONTH"
<?php

$resource = '/privateClouds/123456/metrics/memory?from=2017-07-01T00:00:00+00:00&to=2017-08-01T00:00:00+00:00&aggregation=MAX&granularity=MONTH';
$apiKey   = '****-****-****-****';

$apiUrl   = 'https://api.leaseweb.com/cloud/v2';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiUrl . $resource);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-Lsw-Auth: $apiKey"));
$output = curl_exec($ch);

echo $output;
import requests

apiUrl = 'https://api.leaseweb.com/cloud/v2/privateClouds/123456/metrics/memory?from=2017-07-01T00:00:00+00:00&to=2017-08-01T00:00:00+00:00&aggregation=MAX&granularity=MONTH'
headers = {"X-Lsw-Auth":"****-****-****-****"}

# Send synchronously
try:
  response = requests.get(apiUrl, headers=headers)
  content = response.text
  # Success
  print(content)
except requests.exceptions, e:
  # Exception
  print('Exception during request')

Response Body

{
  "_metadata": {
    "from": "2017-07-01T00:00:00+00:00",
    "to": "2017-07-02T00:00:00+00:00",
    "granularity": "MONTH",
    "aggregation": "MAX"
  },
  "metrics": {
    "MEMORY": {
      "unit": "GB",
      "values": [
        {
          "timestamp": "2017-07-01T00:00:00+00:00",
          "value": 8
        },
        {
          "timestamp": "2017-07-02T00:00:00+00:00",
          "value": 16
        }
      ]
    }
  }
}

To retrieve a list of all of your memory metrics, send a GET request to /cloud/v2/privateClouds/{id}/metrics/memory.

The following query parameters are available:

Name Type Required Description
granularity string No Granularity of the request. Possible values are: NONE, 5MIN, HOUR, DAY, MONTH, YEAR.
aggregation string Yes Aggregation method of the returned values. Possible values are: AVG.
from date Yes Start of date interval in RFC3339 format.
to date Yes End of date interval in RFC3339 format.

The response will be a JSON object with following keys:

Name Type Description
metrics object Array of your memory metrics.
_metadata object Metadata of the request.

The metrics object consists of array of metric having the following attributes:

Name Type Description
MEMORY object Outgoing datatraffic metrics.

The MEMORY object contains the following attributes:

Name Type Description
unit string Unit in which the metric is measured.
values object Array of value objects that contains the metric measurements.

The value object contains the following attributes:

Name Type Description
timestamp date Date where the metric was measured.
value object Metric value.

The _metadata object contains the following attributes:

Name Type Description
from date Start date (inclusive) in format RFC3339.
to date End timestamp (exclusive) in format RFC3339.
granularity string Granularity of the request. Possible values are: NONE, 5MIN, HOUR, DAY, MONTH, YEAR.
aggregation string Aggregation method of the returned values. Possible values are: AVG.

Get the storage metrics

curl -X GET -H "X-Lsw-Auth: ****-****-****-****" "https://api.leaseweb.com/cloud/v2/privateClouds/123456/metrics/storage?from=2017-07-01T00:00:00+00:00&to=2017-08-01T00:00:00+00:00&aggregation=MAX&granularity=MONTH"
<?php

$resource = '/privateClouds/123456/metrics/storage?from=2017-07-01T00:00:00+00:00&to=2017-08-01T00:00:00+00:00&aggregation=MAX&granularity=MONTH';
$apiKey   = '****-****-****-****';

$apiUrl   = 'https://api.leaseweb.com/cloud/v2';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiUrl . $resource);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-Lsw-Auth: $apiKey"));
$output = curl_exec($ch);

echo $output;
import requests

apiUrl = 'https://api.leaseweb.com/cloud/v2/privateClouds/123456/metrics/storage?from=2017-07-01T00:00:00+00:00&to=2017-08-01T00:00:00+00:00&aggregation=MAX&granularity=MONTH'
headers = {"X-Lsw-Auth":"****-****-****-****"}

# Send synchronously
try:
  response = requests.get(apiUrl, headers=headers)
  content = response.text
  # Success
  print(content)
except requests.exceptions, e:
  # Exception
  print('Exception during request')

Response Body

{
  "_metadata": {
    "from": "2017-07-01T00:00:00+00:00",
    "to": "2017-07-02T00:00:00+00:00",
    "granularity": "MONTH",
    "aggregation": "MAX"
  },
  "metrics": {
    "STORAGE": {
      "unit": "GB",
      "values": [
        {
          "timestamp": "2017-07-01T00:00:00+00:00",
          "value": 900
        },
        {
          "timestamp": "2017-07-02T00:00:00+00:00",
          "value": 2500
        }
      ]
    }
  }
}

To retrieve a list of all of your storage metrics, send a GET request to /cloud/v2/privateClouds/{id}/metrics/storage.

The following query parameters are available:

Name Type Required Description
granularity string No Granularity of the request. Possible values are: NONE, 5MIN, HOUR, DAY, MONTH, YEAR.
aggregation string Yes Aggregation method of the returned values. Possible values are: MAX.
from date Yes Start of date interval in RFC3339 format.
to date Yes End of date interval in RFC3339 format.

The response will be a JSON object with following keys:

Name Type Description
metrics object Array of your storage metrics.
_metadata object Metadata of the request.

The metrics object consists of array of metric having the following attributes:

Name Type Description
STORAGE object Storage metrics.

The STORAGE object contains the following attributes:

Name Type Description
unit string Unit in which the metric is measured.
values object Array of value objects that contains the metric measurements.

The value object contains the following attributes:

Name Type Description
timestamp date Date where the metric was measured.
value object Metric value.

The _metadata object contains the following attributes:

Name Type Description
from date Start date (inclusive) in format RFC3339.
to date End timestamp (exclusive) in format RFC3339.
granularity string Granularity of the request. Possible values are: NONE, 5MIN, HOUR, DAY, MONTH, YEAR.
aggregation string Aggregation method of the returned values. Possible values are: MAX.