Images
Here you can find different examples of actions you can do with your images
Create
Creates an Image.
###########################################################################
# CLOUD SERVER API DOCUMENTATION
#
# Name: createImage
# Language: Perl
#
# Description: this function creates a new image
###########################################################################
use strict;
use LWP::UserAgent;
use URI::Escape;
use JSON;
require Http::Request::Common;
#ID access to API
my $TOKEN = "{YOUR_API_TOKEN}"; # e.g.: "f03c3c76cc853ee690b879909c9c6f2a"
my $url = "https://api.cloudbuilder.es/v1";
sub _createImage
{
my ($content) = @_;
my $_command = $url ."/images";
my $_method = 'POST';
#Create the request
my $ua = LWP::UserAgent->new;
my $request = HTTP::Request->new($_method => $_command);
$request->header('X-TOKEN' => $TOKEN);
$request->content_type('application/json');
#Add additional parameters
$request->content($content);
#Get the response
my $response = $ua->request($request);
if($response)
{
#Get the response and close the handlers
print $response->headers()->as_string ."\n";
return $response->content;
$response->close;
$request->close;
}
else
{
#Get the error and close the handlers
return "Http Error Code: ", $response->code, "\n";
$request->close;
}
}
#Parameters
my $server_id = "{YOUR_SERVER_ID}"; # e.g.: "5340033E7FBBC308BC329414A0DF3C20"
my $name = "My image";
my $description = "My image description";
my $frequency = "WEEKLY";
my $num_images = 5;
my %_query = ("server_id" => $server_id, "name" => $name, "description" => $description, "frequency" => $frequency, "num_images" => $num_images);
my $query = encode_json \%_query;
#Create image
print _createImage($query);
<?php
###########################################################################
# CLOUD SERVER API DOCUMENTATION
#
# Name: createImage
# Language: PHP
#
# Description: this function creates a new image
###########################################################################
#ID access to API
$TOKEN = "{YOUR_API_TOKEN}"; # e.g.: "f03c3c76cc853ee690b879909c9c6f2a"
$url = "https://api.cloudbuilder.es/v1";
function createImage($data){
global $url;
global $TOKEN;
$_command = $url . "/images";
$request = curl_init();
//Set options
curl_setopt($request, CURLOPT_URL, $_command);
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
curl_setopt($request, CURLOPT_HTTPHEADER, array("X-TOKEN:$TOKEN", "Content-type:application/json"));
curl_setopt($request, CURLOPT_CUSTOMREQUEST, "POST");
//Add parameters
curl_setopt($request, CURLOPT_POSTFIELDS, $data);
//Try to get the response
$response = curl_exec($request);
if ($response == false){
return( curl_error($request));
}
else{
return( $response);
}
curl_close($request);
}
#PARAMETERS
$server_id = "{YOUR_IMAGE_ID}"; # e.g.: "5340033E7FBBC308BC329414A0DF3C20"
$name = "My image";
$description = "My image description";
$frequency = "WEEKLY";
$num_images = 5;
$data = array('server_id' => $server_id, 'name' => $name, 'description' => $description,
'frequency' => $frequency, 'num_images' => $num_images);
$data = json_encode($data);
echo createImage($data);
?>
###########################################################################
# CLOUD SERVER API DOCUMENTATION
#
# Name: createImage
# Language: Python
#
# Description: this function creates a new image
###########################################################################
from urllib.request import Request, urlopen
import urllib
import json
#ID access to API
TOKEN = "{YOUR_API_TOKEN}" # e.g.: "f03c3c76cc853ee690b879909c9c6f2a"
url = "https://api.cloudbuilder.es/v1"
def _createImage(content):
#Configure the request
_command = url + "/images"
_method = 'POST'
request = Request(_command, data=content.encode(encoding='utf_8'),
headers={'X-TOKEN':TOKEN, 'content-type':'application/json'},
method=_method)
#Try to get the response
try:
response = urlopen(request)
content = response.read()
return (content.decode())
#Fetch error
except urllib.error.URLError as e:
return("Error " + str(e.code) + ":" + e.reason)
#PARAMETERS
name = 'My image'
description = 'My image description'
server_id = "1D9329FB64F6C308C12504DE3298C6FF"
frequency = "WEEKLY"
num_images = 10
data = json.dumps({'name':name, 'description':description, 'server_id':server_id,
'frequency':frequency, 'num_images':num_images})
#Create image
print(_createImage(data))
Delete
Deletes an Image.
###########################################################################
# CLOUD SERVER API DOCUMENTATION
#
# Name: deleteImage
# Language: Perl
#
# Description: this function removes an image
###########################################################################
use strict;
use LWP::UserAgent;
use URI::Escape;
require Http::Request::Common;
#ID access to API
my $TOKEN = "{YOUR_API_TOKEN}"; # e.g.: "f03c3c76cc853ee690b879909c9c6f2a"
my $url = "https://api.cloudbuilder.es/v1";
sub _deleteImage
{
my ($id) = @_;
my $_command = $url ."/images/" .$id;
my $_method = 'DELETE';
#Create the request
my $ua = LWP::UserAgent->new;
my $request = HTTP::Request->new($_method => $_command);
$request->header('X-TOKEN' => $TOKEN);
$request->content_type('application/json');
#Ignore the certificate
$ua->ssl_opts(verify_hostname => 0);
$ua->ssl_opts(SSL_verify_mode => 0x00);
#Get the response
my $response = $ua->request($request);
if($response)
{
#Get the response and close the handlers
print $response->headers()->as_string ."\n";
return $response->content;
$response->close;
$request->close;
}
else
{
#Get the error and close the handlers
return "Http Error Code: ", $response->code, "\n";
$request->close;
}
}
#Parameters
my $id = "{YOUR_IMAGE_ID}"; # e.g.: "5340033E7FBBC308BC329414A0DF3C20"
#Delete image
print _deleteImage($id);
<?php
###########################################################################
# CLOUD SERVER API DOCUMENTATION
#
# Name: deleteImage
# Language: PHP
#
# Description: this function removes an image
###########################################################################
#ID access to API
$TOKEN = "{YOUR_API_TOKEN}"; # e.g.: "f03c3c76cc853ee690b879909c9c6f2a"
$url = "https://api.cloudbuilder.es/v1";
function deleteImages($id){
global $url;
global $TOKEN;
$_command = $url . "/images/$id";
$request = curl_init();
//Set options
curl_setopt($request, CURLOPT_URL, $_command);
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
curl_setopt($request, CURLOPT_HTTPHEADER, array("X-TOKEN:$TOKEN", "Content-type:application/json"));
curl_setopt($request, CURLOPT_CUSTOMREQUEST, "DELETE");
//Try to get the response
$response = curl_exec($request);
if ($response == false){
return( curl_error($request));
}
else{
return( $response);
}
curl_close($request);
}
#PARAMETERS
$id = "{YOUR_IMAGE_ID}"; # e.g.: "5340033E7FBBC308BC329414A0DF3C20"
echo deleteImages($id);
?>
###########################################################################
# CLOUD SERVER API DOCUMENTATION
#
# Name: deleteImage
# Language: Python
#
# Description: this function removes an image
###########################################################################
from urllib.request import Request, urlopen
import urllib
#ID access to API
TOKEN = "{YOUR_API_TOKEN}" # e.g.: "f03c3c76cc853ee690b879909c9c6f2a"
url = "https://api.cloudbuilder.es/v1"
def _deleteImage(id):
#Configure the request
_command = url + "/images/" + id
_method = 'DELETE'
request = Request(_command,
headers={'X-TOKEN':TOKEN, 'content-type':'application/json'},
method=_method)
#Try to get the response
try:
response = urlopen(request)
content = response.read()
return (content.decode())
#Fetch error
except urllib.error.URLError as e:
return("Error " + str(e.code) + ":" + e.reason)
#PARAMETERS
id = "{YOUR_IMAGE_ID}" # e.g.: "5340033E7FBBC308BC329414A0DF3C20"
#Delete image
print(_deleteImage(id))
Info
Returns the information of one Image.
###########################################################################
# CLOUD SERVER API DOCUMENTATION
#
# Name: infoImage
# Language: Perl
#
# Description: this function returns information about your image
###########################################################################
use strict;
use LWP::UserAgent;
use URI::Escape;
require Http::Request::Common;
#ID access to API
my $TOKEN = "{YOUR_API_TOKEN}"; # e.g.: "f03c3c76cc853ee690b879909c9c6f2a"
my $url = "https://api.cloudbuilder.es/v1";
sub _infoImage
{
my ($id) = @_;
my $_command = $url ."/images/" .$id;
my $_method = 'GET';
#Create the request
my $ua = LWP::UserAgent->new;
my $request = HTTP::Request->new($_method => $_command);
$request->header('X-TOKEN' => $TOKEN);
$request->content_type('application/json');
#Get the response
my $response = $ua->request($request);
if($response)
{
#Get the response and close the handlers
print $response->headers()->as_string ."\n";
return $response->content;
$response->close;
$request->close;
}
else
{
#Get the error and close the handlers
return "Http Error Code: ", $response->code, "\n";
$request->close;
}
}
#Parameters
my $id = "{YOUR_IMAGE_ID}"; # e.g.: "5340033E7FBBC308BC329414A0DF3C20"
#Information about an image
print _infoImage($id);
<?php
###########################################################################
# CLOUD SERVER API DOCUMENTATION
#
# Name: infoImage
# Language: PHP
#
# Description: this function returns information about your image
###########################################################################
#ID access to API
$TOKEN = "{YOUR_API_TOKEN}"; # e.g.: "f03c3c76cc853ee690b879909c9c6f2a"
$url = "https://api.cloudbuilder.es/v1";
function infoImages($id){
global $url;
global $TOKEN;
$_command = $url . "/images/$id";
$request = curl_init();
//Set options
curl_setopt($request, CURLOPT_URL, $_command);
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
curl_setopt($request, CURLOPT_HTTPHEADER, array("X-TOKEN:$TOKEN", "Content-type:application/json"));
curl_setopt($request, CURLOPT_CUSTOMREQUEST, "GET");
//Try to get the response
$response = curl_exec($request);
if ($response == false){
return( curl_error($request));
}
else{
return( $response);
}
curl_close($request);
}
#PARAMETERS
$id = "{YOUR_IMAGE_ID}"; # e.g.: "5340033E7FBBC308BC329414A0DF3C20"
echo infoImages($id);
?>
###########################################################################
# CLOUD SERVER API DOCUMENTATION
#
# Name: infoImage
# Language: Python
#
# Description: this function returns information about your image
###########################################################################
from urllib.request import Request, urlopen
import urllib
#ID access to API
TOKEN = "{YOUR_API_TOKEN}" # e.g.: "f03c3c76cc853ee690b879909c9c6f2a"
url = "https://api.cloudbuilder.es/v1"
def _infoImage(id):
#Configure the request
_command = url + "/images/" + id
_method = 'GET'
request = Request(_command,
headers={'X-TOKEN':TOKEN, 'content-type':'application/json'},
method=_method)
#Try to get the response
try:
response = urlopen(request)
content = response.read()
return (content.decode())
#Fetch error
except urllib.error.URLError as e:
return("Error " + str(e.code) + ":" + e.reason)
#PARAMETERS
id = "{YOUR_IMAGE_ID}" # e.g.: "5340033E7FBBC308BC329414A0DF3C20"
#Info image
print(_infoImage(id))
List
Returns a list of all Images.
###########################################################################
# CLOUD SERVER API DOCUMENTATION
#
# Name: listImages
# Language: Perl
#
# Description: this function returns a list with your images
###########################################################################
use strict;
use LWP::UserAgent;
use URI::Escape;
require Http::Request::Common;
#ID access to API
my $TOKEN = "{YOUR_API_TOKEN}"; # e.g.: "f03c3c76cc853ee690b879909c9c6f2a"
my $url = "https://api.cloudbuilder.es/v1";
sub _listImages
{
my $_command = $url ."/images";
my $_method = 'GET';
#Create the request
my $ua = LWP::UserAgent->new;
my $request = HTTP::Request->new($_method => $_command);
$request->header('X-TOKEN' => $TOKEN);
$request->content_type('application/json');
#Get the response
my $response = $ua->request($request);
if($response)
{
#Get the response and close the handlers
print $response->headers()->as_string ."\n";
return $response->content;
$response->close;
$request->close;
}
else
{
#Get the error and close the handlers
return "Http Error Code: ", $response->code, "\n";
$request->close;
}
}
#List images
print _listImages;
<?php
###########################################################################
# CLOUD SERVER API DOCUMENTATION
#
# Name: listImages
# Language: PHP
#
# Description: this function returns a list with your images
###########################################################################
#ID access to API
$TOKEN = "{YOUR_API_TOKEN}"; # e.g.: "f03c3c76cc853ee690b879909c9c6f2a"
$url = "https://api.cloudbuilder.es/v1";
function listImages($data){
global $url;
global $TOKEN;
$_command = $url . "/images";
$request = curl_init();
//Set options
curl_setopt($request, CURLOPT_URL, $_command);
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
curl_setopt($request, CURLOPT_HTTPHEADER, array("X-TOKEN:$TOKEN", "Content-type:application/json"));
curl_setopt($request, CURLOPT_CUSTOMREQUEST, "GET");
//Try to get the response
$response = curl_exec($request);
if ($response == false){
return( curl_error($request));
}
else{
return( $response);
}
curl_close($request);
}
#PARAMETERS
echo listImages();
?>
###########################################################################
# CLOUD SERVER API DOCUMENTATION
#
# Name: listImages
# Language: Python
#
# Description: this function returns a list with your images
###########################################################################
from urllib.request import Request, urlopen
import urllib
#ID access to API
TOKEN = "{YOUR_API_TOKEN}" # e.g.: "f03c3c76cc853ee690b879909c9c6f2a"
url = "https://api.cloudbuilder.es/v1"
def _listImages():
#Configure the request
_command = url + "/images"
_method = 'GET'
request = Request(_command,
headers={'X-TOKEN':TOKEN, 'content-type':'application/json'},
method=_method)
#Try to get the response
try:
response = urlopen(request)
content = response.read()
return (content.decode())
#Fetch error
except urllib.error.URLError as e:
return("Error " + str(e.code) + ":" + e.reason)
#PARAMETERS
#List images
print(_listImages())
Reconfigure
Reconfigures an Image.
###########################################################################
# CLOUD SERVER API DOCUMENTATION
#
# Name: reconfigureImage
# Language: Perl
#
# Description: this function reconfigure an image
###########################################################################
use strict;
use LWP::UserAgent;
use URI::Escape;
use JSON;
require Http::Request::Common;
#ID access to API
my $TOKEN = "{YOUR_API_TOKEN}"; # e.g.: "f03c3c76cc853ee690b879909c9c6f2a"
my $url = "https://api.cloudbuilder.es/v1";
sub _reconfigureImage
{
my ($id, $content) = @_;
my $_command = $url ."/images/" .$id;
my $_method = 'PUT';
#Create the request
my $ua = LWP::UserAgent->new;
my $request = HTTP::Request->new($_method => $_command);
$request->header('X-TOKEN' => $TOKEN);
$request->content_type('application/json');
#Add additional parameters
$request->content($content);
#Get the response
my $response = $ua->request($request);
if($response)
{
#Get the response and close the handlers
print $response->headers()->as_string ."\n";
return $response->content;
$response->close;
$request->close;
}
else
{
#Get the error and close the handlers
return "Http Error Code: ", $response->code, "\n";
$request->close;
}
}
#Parameters
my $id = "{YOUR_IMAGE_ID}"; # e.g.: "5340033E7FBBC308BC329414A0DF3C20"
my $name = "My image";
my $description = "My image description";
my $frequency = "ONCE";
my %_query = ("name" => $name, "description" => $description, "frequency" => $frequency);
my $query = encode_json \%_query;
#Reconfigure image
print _reconfigureImage($id, $query);
<?php
###########################################################################
# CLOUD SERVER API DOCUMENTATION
#
# Name: reconfigureImage
# Language: PHP
#
# Description: this function reconfigure image's features
###########################################################################
#ID access to API
$TOKEN = "{YOUR_API_TOKEN}"; # e.g.: "f03c3c76cc853ee690b879909c9c6f2a"
$url = "https://api.cloudbuilder.es/v1";
function reconfigureImage($id, $data){
global $url;
global $TOKEN;
$_command = $url . "/images/$id";
$request = curl_init();
//Set options
curl_setopt($request, CURLOPT_URL, $_command);
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
curl_setopt($request, CURLOPT_HTTPHEADER, array("X-TOKEN:$TOKEN", "Content-type:application/json"));
curl_setopt($request, CURLOPT_CUSTOMREQUEST, "PUT");
//Add parameters
curl_setopt($request, CURLOPT_POSTFIELDS, $data);
//Try to get the response
$response = curl_exec($request);
if ($response == false){
return( curl_error($request));
}
else{
return( $response);
}
curl_close($request);
}
#PARAMETERS
$id = "{YOUR_IMAGE_ID}"; # e.g.: "5340033E7FBBC308BC329414A0DF3C20"
$name = "My image";
$description = "My image description";
$frequency = "ONCE";
$data = array('name' => $name, 'description' => $description, 'frequency' => $frequency);
$data = json_encode($data);
echo reconfigureImage($id, $data);
?>
###########################################################################
# CLOUD SERVER API DOCUMENTATION
#
# Name: reconfigureImage
# Language: Python
#
# Description: this function reconfigure an image
###########################################################################
from urllib.request import Request, urlopen
import urllib
import json
#ID access to API
TOKEN = "{YOUR_API_TOKEN}" # e.g.: "f03c3c76cc853ee690b879909c9c6f2a"
url = "https://api.cloudbuilder.es/v1"
def _reconfigureImage(id, content):
#Configure the request
_command = url + "/images/" + id
_method = 'PUT'
request = Request(_command, data=content.encode(encoding='utf_8'),
headers={'X-TOKEN':TOKEN, 'content-type':'application/json'},
method=_method)
#Try to get the response
try:
response = urlopen(request)
content = response.read()
return (content.decode())
#Fetch error
except urllib.error.URLError as e:
return("Error " + str(e.code) + ":" + e.reason)
#PARAMETERS
id = "{YOUR_IMAGE_ID}" # e.g.: "5340033E7FBBC308BC329414A0DF3C20"
name = 'My image rename'
description = 'My image rename description'
frequency = "ONCE"
data = json.dumps({'name':name, 'description':description, 'frequency':frequency})
#Reconfigure image
print(_reconfigureImage(id, data))