Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the acf domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-includes/functions.php on line 6131

Deprecated: Creation of dynamic property ACF::$fields is deprecated in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-content/plugins/advanced-custom-fields-pro/includes/fields.php on line 138

Deprecated: Creation of dynamic property acf_loop::$loops is deprecated in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-content/plugins/advanced-custom-fields-pro/includes/loop.php on line 28

Deprecated: Creation of dynamic property ACF::$loop is deprecated in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-content/plugins/advanced-custom-fields-pro/includes/loop.php on line 269

Deprecated: Creation of dynamic property ACF::$revisions is deprecated in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-content/plugins/advanced-custom-fields-pro/includes/revisions.php on line 397

Deprecated: Creation of dynamic property acf_validation::$errors is deprecated in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-content/plugins/advanced-custom-fields-pro/includes/validation.php on line 28

Deprecated: Creation of dynamic property ACF::$validation is deprecated in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-content/plugins/advanced-custom-fields-pro/includes/validation.php on line 214

Deprecated: Creation of dynamic property acf_form_customizer::$preview_values is deprecated in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-content/plugins/advanced-custom-fields-pro/includes/forms/form-customizer.php on line 28

Deprecated: Creation of dynamic property acf_form_customizer::$preview_fields is deprecated in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-content/plugins/advanced-custom-fields-pro/includes/forms/form-customizer.php on line 29

Deprecated: Creation of dynamic property acf_form_customizer::$preview_errors is deprecated in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-content/plugins/advanced-custom-fields-pro/includes/forms/form-customizer.php on line 30

Deprecated: Creation of dynamic property ACF::$form_front is deprecated in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-content/plugins/advanced-custom-fields-pro/includes/forms/form-front.php on line 598

Deprecated: Creation of dynamic property acf_form_widget::$preview_values is deprecated in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-content/plugins/advanced-custom-fields-pro/includes/forms/form-widget.php on line 34

Deprecated: Creation of dynamic property acf_form_widget::$preview_reference is deprecated in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-content/plugins/advanced-custom-fields-pro/includes/forms/form-widget.php on line 35

Deprecated: Creation of dynamic property acf_form_widget::$preview_errors is deprecated in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-content/plugins/advanced-custom-fields-pro/includes/forms/form-widget.php on line 36

Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the all-in-one-wp-migration domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-includes/functions.php on line 6131

Warning: Cannot modify header information - headers already sent by (output started at /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-includes/functions.php:6131) in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-content/plugins/wp_plugin/wp_plugin.php on line 23

Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-content/plugins/wp-super-cache/wp-cache-phase2.php on line 54

Warning: Cannot modify header information - headers already sent by (output started at /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-includes/functions.php:6131) in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-content/plugins/wp-super-cache/wp-cache-phase2.php on line 1539

Deprecated: strtolower(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-content/plugins/wp-super-cache/wp-cache-phase2.php on line 828

Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the rocket domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-includes/functions.php on line 6131

Deprecated: Creation of dynamic property acf_field_oembed::$width is deprecated in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-content/plugins/advanced-custom-fields-pro/includes/fields/class-acf-field-oembed.php on line 31

Deprecated: Creation of dynamic property acf_field_oembed::$height is deprecated in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-content/plugins/advanced-custom-fields-pro/includes/fields/class-acf-field-oembed.php on line 32

Deprecated: Creation of dynamic property acf_field_google_map::$default_values is deprecated in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-content/plugins/advanced-custom-fields-pro/includes/fields/class-acf-field-google-map.php on line 33

Deprecated: Creation of dynamic property acf_field__group::$have_rows is deprecated in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-content/plugins/advanced-custom-fields-pro/includes/fields/class-acf-field-group.php on line 31

Deprecated: Creation of dynamic property acf_field_clone::$cloning is deprecated in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-content/plugins/advanced-custom-fields-pro/pro/fields/class-acf-field-clone.php on line 34

Deprecated: Creation of dynamic property acf_field_clone::$have_rows is deprecated in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-content/plugins/advanced-custom-fields-pro/pro/fields/class-acf-field-clone.php on line 35

Deprecated: Creation of dynamic property jh_acf_field_table::$settings is deprecated in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-content/plugins/advanced-custom-fields-table-field/class-jh-acf-field-table.php on line 23

Warning: Cannot modify header information - headers already sent by (output started at /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-includes/functions.php:6131) in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-includes/rest-api/class-wp-rest-server.php on line 1902

Warning: Cannot modify header information - headers already sent by (output started at /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-includes/functions.php:6131) in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-includes/rest-api/class-wp-rest-server.php on line 1902

Warning: Cannot modify header information - headers already sent by (output started at /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-includes/functions.php:6131) in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-includes/rest-api/class-wp-rest-server.php on line 1902

Warning: Cannot modify header information - headers already sent by (output started at /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-includes/functions.php:6131) in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-includes/rest-api/class-wp-rest-server.php on line 1902

Warning: Cannot modify header information - headers already sent by (output started at /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-includes/functions.php:6131) in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-includes/rest-api/class-wp-rest-server.php on line 1902

Warning: Cannot modify header information - headers already sent by (output started at /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-includes/functions.php:6131) in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-includes/rest-api/class-wp-rest-server.php on line 1902

Warning: Cannot modify header information - headers already sent by (output started at /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-includes/functions.php:6131) in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-includes/rest-api/class-wp-rest-server.php on line 1902

Warning: Cannot modify header information - headers already sent by (output started at /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-includes/functions.php:6131) in /var/www/vhosts/studiogo.tech/httpdocs/upcloudold/wp-includes/rest-api/class-wp-rest-server.php on line 1902
{"id":24434,"date":"2017-10-17T11:00:03","date_gmt":"2017-10-17T08:00:03","guid":{"rendered":"https:\/\/upcloud.com\/community\/tutorials\/getting-started-libcloud-compute-nodes"},"modified":"2017-10-17T11:00:03","modified_gmt":"2017-10-17T08:00:03","slug":"getting-started-libcloud-compute-nodes","status":"publish","type":"tutorial","link":"https:\/\/studiogo.tech\/upcloudold\/tutorial\/getting-started-libcloud-compute-nodes\/","title":{"rendered":"How to get started with Libcloud compute nodes"},"content":{"rendered":"\n

Apache Libcloud<\/a> is a Python programming language library that unifies supported cloud provider APIs under a single interface. The Libcloud compute driver for UpCloud allows you to deploy and manage cloud servers using simple functions. Follow the instructions below to install the Libcloud library and check the usage examples to get started.<\/p>\n\n\n\n

\n
Test hosting on UpCloud!<\/a><\/div>\n<\/div>\n\n\n\n

Enable API permissions<\/h2>\n\n\n\n

Before you begin, allowing Libcloud to connect to your UpCloud account requires you to enable the API permissions.<\/p>\n\n\n\n

We recommend creating a new workspace member account just for the API communication. Log in to your UpCloud account and go to the\u00a0People<\/em> tab. You can check out the instructions on how to do this in our getting started guide for the API<\/a>.<\/p>\n\n\n\n

Note that you should restrict the API account from your other UpCloud services. <\/tt>Take care handling your credentials when programming automation.<\/p>\n\n\n\n

Installing prerequisites<\/h2>\n\n\n\n

To begin developing with Libcloud, you will need to have a Python programming environment configured on your computer. You can find instructions to install Python for your operating system in their beginner\u2019s guide<\/a>.<\/p>\n\n\n\n

Installing Libcloud<\/h2>\n\n\n\n

Libcloud is available for most Linux distributions with the package managers or directly from the Libcloud downloads page<\/a> on other operating systems as well.<\/p>\n\n\n\n

However, the easiest and most universal way to install Libcloud is using the Python Package Index. It is the official third-party software repository for the Python programming language and contains almost everything you could ever need.<\/p>\n\n\n\n

In most cases, the command line client pip<\/tt> should have been installed together with the Python environment. If it was not, follow the install instructions in their documentation<\/a>.<\/p>\n\n\n\n

With pip<\/tt> installed, getting the Libcloud libraries is a simple task. Use the following command to install the apache-libcloud<\/tt> package.<\/p>\n\n\n\n

pip install apache-libcloud<\/pre>\n\n\n\n

If you already had a version of Libcloud installed, you can upgrade it with the next command.<\/p>\n\n\n\n

pip install --upgrade apache-libcloud<\/pre>\n\n\n\n

To get the most up-to-date packages, you will need to use the development version. The Libcloud driver for UpCloud will initially be only available on the development\u00a0channel until it gets included in the stable release.<\/p>\n\n\n\n

Install the Libcloud development version with the command underneath.<\/p>\n\n\n\n

pip install -e git+https:\/\/git-wip-us.apache.org\/repos\/asf\/libcloud.git@trunk#egg=apache-libcloud<\/pre>\n\n\n\n

With the libraries installed, you are then ready to start programming. Continue below with examples of how to create and manage nodes on UpCloud using the Libcloud API.<\/p>\n\n\n\n

Instantiating a new driver<\/h2>\n\n\n\n

To issue commands to the UpCloud services, you first need to instantiate a driver with your credentials. Begin by creating a file called libctest.py<\/tt> with the following content.<\/p>\n\n\n\n

#!\/usr\/bin\/env python\nimport os\nimport libcloud\nfrom pprint import pprint\n\ncls = libcloud.get_driver(libcloud.DriverType.COMPUTE,libcloud.DriverType.COMPUTE.UPCLOUD)\ndriver = cls(os.environ['UpCloud_API_username'], os.environ['UpCloud_API_password'])\n\npprint(driver.list_locations())<\/pre>\n\n\n\n

Next, assign\u00a0your credentials to environmental variables named\u00a0UpCloud_API_username<\/tt>\u00a0and UpCloud_API_password<\/tt>. For example on Linux use the following commands.<\/p>\n\n\n\n

export UpCloud_API_username='username'\nexport UpCloud_API_password='password'\n<\/tt><\/tt><\/pre>\n\n\n\n

These can also be stored permanently in your .bashrc<\/tt> or .zshrc<\/tt> profiles avoiding having to rerun the export commands manually on every new terminal.<\/p>\n\n\n\n

Set the test program as executable with the next command.<\/p>\n\n\n\n

chmod +x libctest.py<\/pre>\n\n\n\n

Then run the short program on the terminal to test that it connects to the UpCloud API correctly using the command below.<\/p>\n\n\n\n

.\/libctest<\/tt>.py<\/pre>\n\n\n\n
[<NodeLocation: id=de-fra1, name=Frankfurt #1, country=DE, driver=Upcloud>,\n <NodeLocation: id=fi-hel1, name=Helsinki #1, country=FI, driver=Upcloud>,\n <NodeLocation: id=fi-hel2, name=Helsinki #2, country=FI, driver=Upcloud>,\n <NodeLocation: id=nl-ams1, name=Amsterdam #1, country=NL, driver=Upcloud>,\n <NodeLocation: id=sg-sin1, name=Singapore #1, country=SG, driver=Upcloud>,\n <NodeLocation: id=uk-lon1, name=London #1, country=UK, driver=Upcloud>,\n <NodeLocation: id=us-chi1, name=Chicago #1, country=US, driver=Upcloud>]<\/pre>\n\n\n\n

If you see an output like the above, your driver is working!<\/p>\n\n\n\n

Creating a new server<\/h2>\n\n\n\n

The basic process of creating a new server requires the following minimum parameters: system image, configuration size, data centre location, and a name for the server. Below are some examples of how to select the parameters for the deployment call.<\/p>\n\n\n\n

# Get the Ubuntu 16.04 public template\nfor image in driver.list_images():\n    if image.name.startswith('Ubuntu') \n    and image.name.count('16.04') \n    and image.id.endswith('0'):\n        break\n\n# Select the node size from the preconfigured instances\nfor size in driver.list_sizes():\n    if size.name == '1xCPU-1GB':\n        break\n\n# Pick the zone by the city name\nfor location in driver.list_locations():\n    if location.name.startswith('London'):\n        break\n\nnode = driver.create_node(\n    image=image,\n    size=size,\n    location=location,\n    name='Libcloud Example',\n    ex_hostname='libcloud.example.com'\n    )\n\npprint(node.state)<\/pre>\n\n\n\n

Simply add the above code to the end of your libctest.py<\/tt> test file. Then run the program as before to deploy the first server.<\/p>\n\n\n\n

Rebooting a server<\/h2>\n\n\n\n

Issuing a reboot command requires you to first get the right node object. Afterwards, you have the following two options to restart the node.<\/p>\n\n\n\n

Asking the driver to reboot the node.<\/p>\n\n\n\n

node = [node for node in driver.list_nodes() if node.name == 'Libcloud Example'][0]\ndriver.reboot_node(node)<\/pre>\n\n\n\n

Alternatively, you can command the node object directly.<\/p>\n\n\n\n

node = [node for node in driver.list_nodes() if node.name == 'Libcloud Example'][0]\nnode.reboot()<\/pre>\n\n\n\n

The functions will return True<\/tt> once the server has been rebooted successfully. If something went wrong, you will get False<\/tt> instead.<\/p>\n\n\n\n

Destroying a server<\/h2>\n\n\n\n

Similarly to the reboot commands, a node can be destroyed using either of the two methods below. The process will shut down the target node and remove the server without deleting the storage device.<\/p>\n\n\n\n

Select the node you wish to destroy and ask the driver to remove it.<\/p>\n\n\n\n

node = [node for node in driver.list_nodes() if node.name == 'Libcloud Example'][0]\ndriver.destroy_node(node)<\/pre>\n\n\n\n

Or tell the node to destroy itself.<\/p>\n\n\n\n

node = [node for node in driver.list_nodes() if node.name == 'Libcloud Example'][0]\nnode.destroy()<\/pre>\n\n\n\n

The functions will return True<\/tt> once the server has been successfully deleted. In case the server could not be removed, you will get False<\/tt> as a response.<\/p>\n\n\n\n

Note that after destroying a server, the state of the node object will no longer be up to date. You should always refresh the list of nodes after creating or destroying nodes.<\/p>\n\n\n\n

Including SSH keys at deployment<\/h2>\n\n\n\n

SSH keys are a safe and convenient way to authenticate when logging in to your cloud servers. You can include the public half of your SSH key pair when deploying a new node by reading it from the key file into the auth<\/tt> parameter.<\/p>\n\n\n\n

By default, the public key is added to the root<\/tt> user account. If you wish to define a custom username, you can add it to the\u00a0ex_username<\/tt> parameter. The new username is created at deployment and given sudo<\/tt> privileges.<\/p>\n\n\n\n

from libcloud.compute.base import NodeAuthSSHKey\n\nwith open('\/path\/to\/public_ssh_key', 'r') as public:\n    public_ssh_key = public.read().replace('n', '')\n\nnode = driver.create_node(\n    image=image,\n    size=size,\n    location=location,\n    name='Libcloud Example',\n    ex_hostname='libcloud.example.com',\n    auth=NodeAuthSSHKey(public_ssh_key),\n    ex_username='username'\n    )<\/pre>\n\n\n\n

Defining a username already at deployment allows you to skip the hassle of setting up sudo<\/tt> access manually.<\/p>\n\n\n\n

Using init scripts at deployment<\/h2>\n\n\n\n

Libcloud also supports running custom scripts at server deployment. The scripts can contain any normal Linux commands and tasks but will only work with Linux system templates.<\/p>\n\n\n\n

Using an init script will require a private SSH key that corresponds to your public SSH key. The Libcloud driver needs to connect to the new server over SSH to run the script. Include the file path to your private SSH key in the ssh_key<\/tt> parameter as shown in the example below.<\/p>\n\n\n\n

You also have the option to run the init script under a specific user account by defining the ssh_username<\/tt> parameter.<\/p>\n\n\n\n

Note that the init script and deployment time SSH details are only available in the deploy_node()<\/tt> function.<\/p>\n\n\n\n

from libcloud.compute.deployment import ScriptDeployment\nfrom libcloud.compute.base import NodeAuthSSHKey\n\n# Create an init script that is run during deployment\ninitscript = ScriptDeployment('echo \"Deployed with Libcloud\" > ~\/libcloud.out')\n\n# Include SSH keys that are used to authenticate on the server\nprivate_ssh_key_file = '\/path\/to\/private_ssh_key'\nwith open('\/path\/to\/public_ssh_key', 'r') as public:\n    public_ssh_key = public.read().replace('n', '')\n\nnode = driver.deploy_node(\n    ssh_key=private_ssh_key_file,\n    ssh_username='root',\n    deploy=initscript,\n    image=image,\n    size=size,\n    location=location,\n    name='Libcloud Example',\n    ex_hostname='libcloud.example.com',\n    auth=NodeAuthSSHKey(public_ssh_key)\n    )<\/pre>\n\n\n\n

Once deployed, the process will attempt to connect to the server and run the init script.<\/p>\n\n\n\n

In case the SSH connection fails, the function will raise an HTTP exception.<\/p>\n","protected":false},"featured_media":27277,"comment_status":"open","ping_status":"closed","template":"","community-category":[113,117],"class_list":["post-24434","tutorial","type-tutorial","status-publish","has-post-thumbnail","hentry","community-category-integrations","community-category-automation"],"acf":[],"_links":{"self":[{"href":"https:\/\/studiogo.tech\/upcloudold\/wp-json\/wp\/v2\/tutorial\/24434","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/studiogo.tech\/upcloudold\/wp-json\/wp\/v2\/tutorial"}],"about":[{"href":"https:\/\/studiogo.tech\/upcloudold\/wp-json\/wp\/v2\/types\/tutorial"}],"replies":[{"embeddable":true,"href":"https:\/\/studiogo.tech\/upcloudold\/wp-json\/wp\/v2\/comments?post=24434"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/studiogo.tech\/upcloudold\/wp-json\/wp\/v2\/media\/27277"}],"wp:attachment":[{"href":"https:\/\/studiogo.tech\/upcloudold\/wp-json\/wp\/v2\/media?parent=24434"}],"wp:term":[{"taxonomy":"community-category","embeddable":true,"href":"https:\/\/studiogo.tech\/upcloudold\/wp-json\/wp\/v2\/community-category?post=24434"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}