Clouds
Cloud computing has become popular among the general public about a year and a half or two years ago, and
Amazon EC2 has played a huge role in this. Gradually, the active discussion of this technology only increased, there were supporters and opponents who believed that this was just another fashionable trend and nothing more; some began to experiment and use cloud computing to solve their problems.
EC2 had not many alternatives for quite a long time, so few people thought about the problems of migration from one provider to another cloud. However, in the last year, more and more companies began to appear, providing cloud services of adequate quality at an affordable price.
')
At the moment, EC2, perhaps, still remains the leader, but several other major players have appeared - I think names like Rackspace and GoGrid are widely known to anyone who is at least superficially interested in the topic. In addition to them, at least a dozen companies offering similar services are now active in the market.
Such diversity already makes us more attentive to the question of choosing a provider and thinking about a possible migration plan.
Why do you need libcloud?
An integral part of cloud services is the presence of an API, usually RESTful or REST-like, which allows you to fully control cloud infrastructure. Unfortunately, almost every provider creates its own API, which is incompatible with the existing ones, which is very inconvenient if you decide to switch from one service to another, and creates additional difficulties if you have to support several different services at the same time.
When
libcloud was born at
Cloudkick (which, by the way, recently bought Rackspace), the goal was not only to create a tool for working with Python clones, but also to formulate a vision of what a common interface should (may) be to work with. from the service API, as well as from the client side when working with different platforms. For example, in parallel with the Python version, the Java version is developed, the principle of operation and concepts are exactly the same.
However, I will not delve into philosophical aspects, but will demonstrate what libcloud allows you to do.
Getting Started
Installation and Setup
The installation process is unlikely to seem new to anyone:
easy_install apache-libcloud
The second preparatory stage is to activate the API and get the key and password. This procedure is different for different cloud providers and is usually described in their documentation. For example, in the case of actionspace, it looks like this: go to
manage.rackspacecloud.com , then in the menu
Your Account -> API Access .
Terminology and Interface
The following terminology is used in libcloud:
- A node is an instance of a single virtual server. Providers are usually called simply server
- Node size - the physical size of a node. For different providers, the characteristics differ, usually the size of the RAM, the number of processor cores, sometimes the size of the disk space
- Node Image - An operating system image that is used to load a node.
Above all the above objects, the operation
list is possible - get the current list of objects. More operations are supported for nodes: they can be
created (
create ),
deleted (
destroy ), and also
reloaded (
reboot ).
View available node sizes and images
Let's start with a simple example: connect to the service and get a list of all images from CentOS, as well as a list of all possible node sizes:
To start, you will need to create the “secret.py” file and declare there the access_id and secret_key variables with the required user and password to access the API of your provider. Pay attention to the line:
Driver = get_driver(Provider.GOGRID)
Here we say we want to use a driver for the GoGrid. In order to get a list of all supported providers, in the shell you need to run the following command:
pydoc libcloud.types.Provider
Creating and deleting nodes
Let's consider an example of creating and deleting a node. To create, we need to decide on the basic parameters of the node, such as the name, size and image. As the image, again, select the first image that contains the CentOS name, and take the first size that appears.
Conclusion
As you can see, everything is also quite simple and transparent here; and two short scripts managed to cover almost the entire common interface. Of course, libcloud's functionality is not limited to this, and I do not set myself the task of compiling detailed usage guidelines, but only to interest those who are just starting to work with clauses and, in particular, those who use right-specific libraries. .
More experienced cloud users will probably have the feeling that the described functionality is not enough. Yes, in most cases it is really required to use something more, and, it is clear that all provider-specific things cannot be covered with a single interface.
In this case, libcloud supports so-called 'extra' methods in provider drivers that allow, for example, creating ssh key pairs, creating your own node images, etc. According to my observations, drivers of popular providers pretty well cover all the functionality and are updated promptly. Information about what each driver supports is available in the libcloud API
documentation .
I hope, libcloud will simplify the life of those who work with clouds, and my article will help you quickly navigate the project.