diff --git a/Changelog b/Changelog index 6732b3db6e6d70bece9666ff5e114be11415a258..c380c4dbe80ad750a24423f44e2500c17dfa59aa 100644 --- a/Changelog +++ b/Changelog @@ -18,6 +18,11 @@ Bug fixes * Handle SSL unicode bug with grace [grnet/kamaki#67] * Check server status before changing it [grnet/kamaki#57] +Support +------- + +* Update library documentation with examples [grnet/kamaki#49] + v0.13rc5 ======== diff --git a/docs/developers/examples.rst b/docs/developers/examples.rst new file mode 100644 index 0000000000000000000000000000000000000000..4b534bca998ffb492a5410ca2137557334a6008c --- /dev/null +++ b/docs/developers/examples.rst @@ -0,0 +1,493 @@ +Examples +======== +This is a collection of python scripts that demonstrate the usage of the kamaki +clients API library + +Initial steps +------------- + +Initialize clients +"""""""""""""""""" +Initialize the identity (`auth`), storage (`store`), `compute`, +`network`, block storage (`volume`) and `image` clients, given an +authentication URL and TOKEN. + +.. literalinclude:: scripts/000_init.py + :language: python + :linenos: + :lines: 48- + +.. warning:: Line 4 sets the CA certificates bundle to support secure + connections. Secure connections are enabled by default and must be managed + before setting any clients. See :ref:`clients-ssl` for more details. + +Authentication URL and TOKEN from config file +""""""""""""""""""""""""""""""""""""""""""""" +Drag the URL and TOKEN information from the kamaki configuration file, using +the "Config" class from kamaki CLI. + +.. literalinclude:: scripts/000_init.py + :language: python + :linenos: + :lines: 34-39 + +.. note:: The cloud URL and TOKEN are stored under a cloud name. Kamaki can be + configured to `use multiple clouds <../setup.html#multiple-clouds>`_. It is + common practice to + `set the value of the default cloud <../setup.html#quick-setup>`_ using the + **global.default_cloud** configuration option. Here it was assumed that the + value **global.default_cloud** is the name of the preferred cloud + +Log HTTP +"""""""" +Instruct kamaki to output the HTTP logs on the console. + +.. literalinclude:: scripts/000_init.py + :language: python + :linenos: + :lines: 42-45 + +Containers and files +-------------------- + +Information on object +""""""""""""""""""""" +List all objects in the storage_client's default container and ask user to pick +one of them for more information. + +.. literalinclude:: scripts/001_file_info.py + :language: python + :linenos: + :lines: 48- + +Backup container +"""""""""""""""" +Back up the contents of the default container to a new container. + +.. literalinclude:: scripts/002_container_backup.py + :language: python + :linenos: + :lines: 48- + +Empty and delete containers +""""""""""""""""""""""""""" +Delete all containers if their names start with "backup". + +.. literalinclude:: scripts/003_container_cleanup.py + :language: python + :linenos: + :lines: 48- + +.. note:: The "del_container" method will empty the container. The + "purge_container" method will destroy an empty container. If the container + is not empty, it cannot be destroyed. + +.. note:: The "try-finally" clause is used to preserve the original container + settings of the client (usually "pithos") + +Upload and Download +""""""""""""""""""" +Upload a local file + +.. literalinclude:: scripts/004_upload_files.py + :language: python + :linenos: + :lines: 56- + +Download a remote object as local file + +.. literalinclude:: scripts/005_download_files.py + :language: python + :linenos: + :lines: 56- + +.. note:: The _gen callback function is used to show upload/download progress. + It is optional. It must be a python generator, for example: + + .. literalinclude:: scripts/004_upload_files.py + :language: python + :linenos: + :lines: 48-54 + +Asynchronous batch upload +""""""""""""""""""""""""" +Upload all files in a directory asynchronously + +.. literalinclude:: scripts/006_async_upload.py + :language: python + :linenos: + :lines: 48- + +Reassign container +"""""""""""""""""" +Each resource is assigned to a project, where the resource quotas are defined. +With this script, users are prompted to choose a project to assign the default +container. + +.. literalinclude:: scripts/007_container_reassign.py + :language: python + :linenos: + :lines: 48- + +Download and stream in parallel +""""""""""""""""""""""""""""""" +Download an object in chunks. Stream them as they are being downloaded. + +.. literalinclude:: scripts/008_stream.py + :language: python + :linenos: + :lines: 48- + +.. note:: The ``kamaki.clients.SilentEvent`` class extends ``threading.Thread`` + in order to simplify thread handling. + +Images +------ + +Register image +"""""""""""""" +Upload an image to container "images" and register it to Plankton. + +.. literalinclude:: scripts/009_register_image.py + :language: python + :linenos: + :lines: 53- + +.. note:: Properties are mandatory in order to create a working image. In this + example it is assumed a Debian Linux image. The suggested method for + creating, uploading and registering custom images is by using the + `snf-image-creator tool `_. + +Find image +"""""""""" +Find images belonging to current user, by its name. + +.. literalinclude:: scripts/010_find_image.py + :language: python + :linenos: + :lines: 48- + +Modify image +"""""""""""" +Change the name and add a properties to an image. Use the image created +`above <#register-image>`_. One of the properties (description) is new, the +other (users) exists and will be updated with a new value. + +.. literalinclude:: scripts/011_modify_image.py + :language: python + :linenos: + :lines: 52- + +Unregister image +"""""""""""""""" +Unregister the image created `above <#register-image>`_. + +.. literalinclude:: scripts/012_unregister_image.py + :language: python + :linenos: + :lines: 52- + +Virtual Machines (Servers) +-------------------------- + +Find flavors +"""""""""""" +Find all flavors with 2048 MB of RAM, 2 CPU cores and disk space between 20 GB +and 40 GB. + +.. literalinclude:: scripts/013_find_flavors.py + :language: python + :linenos: + :lines: 49- + +Create server +""""""""""""" +To create a server, pick a name, a flavor id and an image id. In this example, +assume the image from `a previous step <#register-image>`_. + +.. literalinclude:: scripts/014_create_server.py + :language: python + :linenos: + :lines: 50-54 + +.. note:: To access the virtual server, a password is returned by the creation + method. This password is revealed only once, when the server is created and + it's not stored anywhere on the service side. + +A popular access method is to inject the user ssh keys, as shown bellow. + +.. literalinclude:: scripts/014_create_server.py + :language: python + :linenos: + :lines: 56- + +Connection information +"""""""""""""""""""""" +There are many ways to connect to a server: using a password or ssh keys, +through a VNC console, the IP address or the qualified domain name. + +Credentials for connection through a VNC console: + +.. literalinclude:: scripts/015_connect_server.py + :language: python + :linenos: + :lines: 52-56 + +The following script collects all network information available: the F.Q.D.N. +(fully qualified domain name) and the IP addresses (v4 as well as v6). + +.. literalinclude:: scripts/015_connect_server.py + :language: python + :linenos: + :lines: 59- + +Update server +""""""""""""" +Rename the server and then add/change some metadata. + +.. literalinclude:: scripts/016_update_server.py + :language: python + :linenos: + :lines: 51- + +Start, Shutdown, Reboot or Delete server +"""""""""""""""""""""""""""""""""""""""" +First, get the current status of the server, and write a method for handling +the wait results. + +.. literalinclude:: scripts/017_server_actions.py + :language: python + :linenos: + :lines: 52-56 + +Shutdown a server, assuming it is currently active. + +.. literalinclude:: scripts/017_server_actions.py + :language: python + :linenos: + :lines: 58-62 + +Start the stopped server. + +.. literalinclude:: scripts/017_server_actions.py + :language: python + :linenos: + :lines: 64-68 + +Reboot the active server. + +.. literalinclude:: scripts/017_server_actions.py + :language: python + :linenos: + :lines: 70-74 + +Destroy the server. + +.. literalinclude:: scripts/017_server_actions.py + :language: python + :linenos: + :lines: 76- + +Server snapshots +---------------- + +Lookup volume +""""""""""""" +Each virtual server has at least one volume. This information is already stored +in the "srv" object retrieved in `a previous step <#create-server>`_. + +.. literalinclude:: scripts/023_lookup_volume.py + :language: python + :linenos: + :lines: 55 + +Retrieve this information using the Block Storage client and check if it +matches. + +.. literalinclude:: scripts/023_lookup_volume.py + :language: python + :linenos: + :lines: 57- + +Create and delete volume +"""""""""""""""""""""""" +Create an extra volume. A server can have multiple volumes attached. + +.. note:: In this example, the size of the volume is retrieved from the size of + the server flavor. This is the safest method to set a fitting size. + +.. literalinclude:: scripts/024_volume.py + :language: python + :linenos: + :lines: 55-57 + +Destroy the volume. + +.. literalinclude:: scripts/024_volume.py + :language: python + :linenos: + :lines: 65 + +.. warning:: volume creation and deletion may take some time to complete. + +Lookup snapshot +""""""""""""""" +Find the snapshots of the server's first volume. + +.. literalinclude:: scripts/025_lookup_snapshot.py + :language: python + :linenos: + :lines: 55- + +Create and delete snapshot +"""""""""""""""""""""""""" +Create a snapshot of the first server volume. + +.. literalinclude:: scripts/026_snapshot.py + :language: python + :linenos: + :lines: 55 + +Delete the snapshot. + +.. literalinclude:: scripts/026_snapshot.py + :language: python + :linenos: + :lines: 57 + +Backup and restore snapshot +""""""""""""""""""""""""""" +A snapshot can be thought as a backup, stored at users "snapshots" container. + +Restore server from snapshot (assume the one created in the +`previous step <#create-and-delete-snapshot>`_). + +.. literalinclude:: scripts/027_backup_snapshot.py + :language: python + :linenos: + :lines: 69-70 + +To be safer, download the snapshot to local disk. + +.. literalinclude:: scripts/027_backup_snapshot.py + :language: python + :linenos: + :lines: 72-75 + +If the snapshot has been removed from the system, the server can be restored by +uploading it from the local copy. + +.. literalinclude:: scripts/027_backup_snapshot.py + :language: python + :linenos: + :lines: 77- + +.. note:: By uploading from a local copy, we must register the snapshot as an + image. Use the "exclude_all_taks" to register such images. + +Networks +-------- + +=========== =========== +Term Description +=========== =========== +network A public or private network +sunet A subnet of a network +port A connection between a device (e.g., vm) and a network +floating_ip An external IP v4, reserved by the current user for a network +=========== =========== + +Public and private networks +""""""""""""""""""""""""""" +Public networks are created by the system. Private networks are created and +managed by users. + +Separate public from private networks. + +.. literalinclude:: scripts/018_separate_networks.py + :language: python + :linenos: + :lines: 49-54 + +Create and destroy virtual private network +"""""""""""""""""""""""""""""""""""""""""" +Create a VPN. + +.. literalinclude:: scripts/019_vpn.py + :language: python + :linenos: + :lines: 49-51 + +.. note:: The "type" of the network is a Cyclades-specific parameter. To see + all network types: + + .. literalinclude:: scripts/019_vpn.py + :language: python + :linenos: + :lines: 56 + +Delete the VPN. + +.. literalinclude:: scripts/019_vpn.py + :language: python + :linenos: + :lines: 53 + +Lookup IP +""""""""" +Find the ID of an IP. + +.. literalinclude:: scripts/020_lookup_from_ip.py + :language: python + :linenos: + :lines: 49-54 + +Lookup server from IP +""""""""""""""""""""" +Find the server ID from an IP ID. + +.. literalinclude:: scripts/020_lookup_from_ip.py + :language: python + :linenos: + :lines: 56-58 + +Reserve and release IP +"""""""""""""""""""""" +Reserve an IP. + +.. literalinclude:: scripts/021_ip_pool.py + :language: python + :linenos: + :lines: 49-50 + +.. note:: Reserving an IP means "make it available for use". A freshly reserved + IP is not used by any servers. + +Release an IP. + +.. literalinclude:: scripts/021_ip_pool.py + :language: python + :linenos: + :lines: 52- + +Attach and dettach IP +""""""""""""""""""""" +Attach IP to server, by creating a connection (port) between the server and +the network related to the IP. + +.. note:: The "srv" object and the "assert_status" method from + `an earlier script <#start-shutdown-reboot-or-delete-server>`_ are used + here too. + +.. literalinclude:: scripts/022_handle_ip.py + :language: python + :linenos: + :lines: 56-64 + +Detach IP from server. + +.. literalinclude:: scripts/022_handle_ip.py + :language: python + :linenos: + :lines: 66- + diff --git a/docs/developers/scripts/000_init.py b/docs/developers/scripts/000_init.py new file mode 100644 index 0000000000000000000000000000000000000000..94d5380d042717e93ee3c10ee4481f0abe4b780f --- /dev/null +++ b/docs/developers/scripts/000_init.py @@ -0,0 +1,73 @@ +# Copyright 2014 GRNET S.A. All rights reserved. +# +# Redistribution and use in source and binary forms, with or +# without modification, are permitted provided that the following +# conditions are met: +# +# 1. Redistributions of source code must retain the above +# copyright notice, this list of conditions and the following +# disclaimer. +# +# 2. Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS +# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# The views and conclusions contained in the software and +# documentation are those of the authors and should not be +# interpreted as representing official policies, either expressed +# or implied, of GRNET S.A. + +from kamaki.cli.config import Config + +cnf = Config() +CLOUD = cnf.get('global', 'default_cloud') +URL = cnf.get_cloud(CLOUD, 'url') +TOKEN = cnf.get_cloud(CLOUD, 'token') + + +from kamaki.cli import logger + +logger.add_stream_logger('kamaki.clients.recv', fmt='< %(message)s') +logger.add_stream_logger('kamaki.clients.send', fmt='> %(message)s') + + +from kamaki.clients import astakos, pithos, cyclades, image +from kamaki.clients.utils import https + +https.patch_with_certs('/etc/ssl/certs/ca-certificates.crt') + +identity_client = astakos.AstakosClient(URL, TOKEN) + +pithosURL = identity_client.get_endpoint_url(pithos.PithosClient.service_type) +storage_client = pithos.PithosClient(pithosURL, TOKEN) +storage_client.account = identity_client.user_info['id'] +storage_client.container = 'pithos' + +imageURL = identity_client.get_endpoint_url(image.ImageClient.service_type) +image_client = image.ImageClient(imageURL, TOKEN) + +computeURL = identity_client.get_endpoint_url( + cyclades.CycladesComputeClient.service_type) +compute_client = cyclades.CycladesComputeClient(computeURL, TOKEN) + +networkURL = identity_client.get_endpoint_url( + cyclades.CycladesNetworkClient.service_type) +network_client = cyclades.CycladesNetworkClient(networkURL, TOKEN) + +volumeURL = identity_client.get_endpoint_url( + cyclades.CycladesBlockStorageClient.service_type) +volume_client = cyclades.CycladesBlockStorageClient(volumeURL, TOKEN) diff --git a/docs/developers/scripts/001_file_info.py b/docs/developers/scripts/001_file_info.py new file mode 100644 index 0000000000000000000000000000000000000000..7cea2e2d3387f8464f0293c180dfd1b967cb4367 --- /dev/null +++ b/docs/developers/scripts/001_file_info.py @@ -0,0 +1,55 @@ +# Copyright 2014 GRNET S.A. All rights reserved. +# +# Redistribution and use in source and binary forms, with or +# without modification, are permitted provided that the following +# conditions are met: +# +# 1. Redistributions of source code must retain the above +# copyright notice, this list of conditions and the following +# disclaimer. +# +# 2. Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS +# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# The views and conclusions contained in the software and +# documentation are those of the authors and should not be +# interpreted as representing official policies, either expressed +# or implied, of GRNET S.A. + +from kamaki.cli.config import Config +from kamaki.clients import astakos, pithos, ClientError + +cnf = Config() +CLOUD = cnf.get('global', 'default_cloud') +URL = cnf.get_cloud(CLOUD, 'url') +TOKEN = cnf.get_cloud(CLOUD, 'token') +identity_client = astakos.AstakosClient(URL, TOKEN) + +pithosURL = identity_client.get_endpoint_url(pithos.PithosClient.service_type) +storage_client = pithos.PithosClient(pithosURL, TOKEN) +storage_client.account = identity_client.user_info['id'] +storage_client.container = 'pithos' + +import json + +names = [o['name'] for o in storage_client.list_objects()] +print 'Remote objects:\n\t', '\n\t'.join(names) + +pick = raw_input('Pick one: ') +remote_object = storage_client.get_object_info(pick) +print json.dumps(remote_object, indent=2) diff --git a/docs/developers/scripts/002_container_backup.py b/docs/developers/scripts/002_container_backup.py new file mode 100644 index 0000000000000000000000000000000000000000..e2f7b413ae110364de982b4d7079dc390c79ca72 --- /dev/null +++ b/docs/developers/scripts/002_container_backup.py @@ -0,0 +1,59 @@ +# Copyright 2014 GRNET S.A. All rights reserved. +# +# Redistribution and use in source and binary forms, with or +# without modification, are permitted provided that the following +# conditions are met: +# +# 1. Redistributions of source code must retain the above +# copyright notice, this list of conditions and the following +# disclaimer. +# +# 2. Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS +# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# The views and conclusions contained in the software and +# documentation are those of the authors and should not be +# interpreted as representing official policies, either expressed +# or implied, of GRNET S.A. + +from kamaki.cli.config import Config +from kamaki.clients import astakos, pithos, ClientError + +cnf = Config() +CLOUD = cnf.get('global', 'default_cloud') +URL = cnf.get_cloud(CLOUD, 'url') +TOKEN = cnf.get_cloud(CLOUD, 'token') +identity_client = astakos.AstakosClient(URL, TOKEN) + +pithosURL = identity_client.get_endpoint_url(pithos.PithosClient.service_type) +storage_client = pithos.PithosClient(pithosURL, TOKEN) +storage_client.account = identity_client.user_info['id'] +storage_client.container = 'pithos' + +import time + +backup_container = 'backup_%s' % time.time() +storage_client.create_container(backup_container) + +for o in storage_client.list_objects(): + try: + storage_client.copy_object( + storage_client.container, o['name'], backup_container) + except ClientError as ce: + print "Failed to backup object %s" % o['name'] + print ce diff --git a/docs/developers/scripts/003_container_cleanup.py b/docs/developers/scripts/003_container_cleanup.py new file mode 100644 index 0000000000000000000000000000000000000000..07d2be5b2f7f01d6f33790ee499cc6437d1646f5 --- /dev/null +++ b/docs/developers/scripts/003_container_cleanup.py @@ -0,0 +1,56 @@ +# Copyright 2014 GRNET S.A. All rights reserved. +# +# Redistribution and use in source and binary forms, with or +# without modification, are permitted provided that the following +# conditions are met: +# +# 1. Redistributions of source code must retain the above +# copyright notice, this list of conditions and the following +# disclaimer. +# +# 2. Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS +# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# The views and conclusions contained in the software and +# documentation are those of the authors and should not be +# interpreted as representing official policies, either expressed +# or implied, of GRNET S.A. + +from kamaki.cli.config import Config +from kamaki.clients import astakos, pithos, ClientError + +cnf = Config() +CLOUD = cnf.get('global', 'default_cloud') +URL = cnf.get_cloud(CLOUD, 'url') +TOKEN = cnf.get_cloud(CLOUD, 'token') +identity_client = astakos.AstakosClient(URL, TOKEN) + +pithosURL = identity_client.get_endpoint_url(pithos.PithosClient.service_type) +storage_client = pithos.PithosClient(pithosURL, TOKEN) +storage_client.account = identity_client.user_info['id'] +storage_client.container = 'pithos' + +current_container = storage_client.container +try: + for c in storage_client.list_containers(): + if c['name'].startswith('backup_'): + storage_client.container = c['name'] + storage_client.del_container(delimiter='/') + storage_client.purge_container() +finally: + storage_client.container = current_container diff --git a/docs/developers/scripts/004_upload_files.py b/docs/developers/scripts/004_upload_files.py new file mode 100644 index 0000000000000000000000000000000000000000..54b8c32176761033e27e9353933494b46314f778 --- /dev/null +++ b/docs/developers/scripts/004_upload_files.py @@ -0,0 +1,61 @@ +# Copyright 2014 GRNET S.A. All rights reserved. +# +# Redistribution and use in source and binary forms, with or +# without modification, are permitted provided that the following +# conditions are met: +# +# 1. Redistributions of source code must retain the above +# copyright notice, this list of conditions and the following +# disclaimer. +# +# 2. Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS +# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# The views and conclusions contained in the software and +# documentation are those of the authors and should not be +# interpreted as representing official policies, either expressed +# or implied, of GRNET S.A. + +from kamaki.cli.config import Config +from kamaki.clients import astakos, pithos, ClientError + +cnf = Config() +CLOUD = cnf.get('global', 'default_cloud') +URL = cnf.get_cloud(CLOUD, 'url') +TOKEN = cnf.get_cloud(CLOUD, 'token') +identity_client = astakos.AstakosClient(URL, TOKEN) + +pithosURL = identity_client.get_endpoint_url(pithos.PithosClient.service_type) +storage_client = pithos.PithosClient(pithosURL, TOKEN) +storage_client.account = identity_client.user_info['id'] +storage_client.container = 'pithos' + +import sys + +def _gen(length): + for i in range(length): + sys.stderr.write('*') + yield + yield + +import os.path + +local_file_name = raw_input('File to upload: ') +with open(local_file_name) as f: + remote_object = os.path.basename(f.name) + storage_client.upload_object(remote_object, f, upload_cb=_gen) diff --git a/docs/developers/scripts/005_download_files.py b/docs/developers/scripts/005_download_files.py new file mode 100644 index 0000000000000000000000000000000000000000..93952a1f83b15f95a3d13bbd02b82a9260e837ba --- /dev/null +++ b/docs/developers/scripts/005_download_files.py @@ -0,0 +1,62 @@ +# Copyright 2014 GRNET S.A. All rights reserved. +# +# Redistribution and use in source and binary forms, with or +# without modification, are permitted provided that the following +# conditions are met: +# +# 1. Redistributions of source code must retain the above +# copyright notice, this list of conditions and the following +# disclaimer. +# +# 2. Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS +# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# The views and conclusions contained in the software and +# documentation are those of the authors and should not be +# interpreted as representing official policies, either expressed +# or implied, of GRNET S.A. + +from kamaki.cli.config import Config +from kamaki.clients import astakos, pithos, ClientError + +cnf = Config() +CLOUD = cnf.get('global', 'default_cloud') +URL = cnf.get_cloud(CLOUD, 'url') +TOKEN = cnf.get_cloud(CLOUD, 'token') +identity_client = astakos.AstakosClient(URL, TOKEN) + +pithosURL = identity_client.get_endpoint_url(pithos.PithosClient.service_type) +storage_client = pithos.PithosClient(pithosURL, TOKEN) +storage_client.account = identity_client.user_info['id'] +storage_client.container = 'pithos' + + +import sys + +def _gen(l): + for i in range(l): + sys.stderr.write('*') + yield + yield + +import os.path + +obj = raw_input('Pick remote object to download:') +target = raw_input('Local file name: ') +with open(target, 'w+') as f: + storage_client.download_object(obj, f, download_cb=_gen) diff --git a/docs/developers/scripts/006_async_upload.py b/docs/developers/scripts/006_async_upload.py new file mode 100644 index 0000000000000000000000000000000000000000..5fad729c2468b4fa4b9b697f5f2e38cbf670081d --- /dev/null +++ b/docs/developers/scripts/006_async_upload.py @@ -0,0 +1,56 @@ +# Copyright 2014 GRNET S.A. All rights reserved. +# +# Redistribution and use in source and binary forms, with or +# without modification, are permitted provided that the following +# conditions are met: +# +# 1. Redistributions of source code must retain the above +# copyright notice, this list of conditions and the following +# disclaimer. +# +# 2. Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS +# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# The views and conclusions contained in the software and +# documentation are those of the authors and should not be +# interpreted as representing official policies, either expressed +# or implied, of GRNET S.A. + +from kamaki.cli.config import Config +from kamaki.clients import astakos, pithos, ClientError + +cnf = Config() +CLOUD = cnf.get('global', 'default_cloud') +URL = cnf.get_cloud(CLOUD, 'url') +TOKEN = cnf.get_cloud(CLOUD, 'token') +identity_client = astakos.AstakosClient(URL, TOKEN) + +pithosURL = identity_client.get_endpoint_url(pithos.PithosClient.service_type) +storage_client = pithos.PithosClient(pithosURL, TOKEN) +storage_client.account = identity_client.user_info['id'] +storage_client.container = 'pithos' + +from os import walk + +def upload_one_file(fname): + with open(fname) as f: + storage_client.upload_object(fname, f) + +local_path = raw_input('Dir to upload: ') +for top, subdirs, files in walk(local_path): + storage_client.async_run(upload_one_file, [dict(fname=fn) for fn in files]) diff --git a/docs/developers/scripts/007_container_reassign.py b/docs/developers/scripts/007_container_reassign.py new file mode 100644 index 0000000000000000000000000000000000000000..b043c25ec00d3ffb249c7bad14cdc06f194ec59d --- /dev/null +++ b/docs/developers/scripts/007_container_reassign.py @@ -0,0 +1,52 @@ +# Copyright 2014 GRNET S.A. All rights reserved. +# +# Redistribution and use in source and binary forms, with or +# without modification, are permitted provided that the following +# conditions are met: +# +# 1. Redistributions of source code must retain the above +# copyright notice, this list of conditions and the following +# disclaimer. +# +# 2. Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS +# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# The views and conclusions contained in the software and +# documentation are those of the authors and should not be +# interpreted as representing official policies, either expressed +# or implied, of GRNET S.A. + +from kamaki.cli.config import Config +from kamaki.clients import astakos, pithos, ClientError + +cnf = Config() +CLOUD = cnf.get('global', 'default_cloud') +URL = cnf.get_cloud(CLOUD, 'url') +TOKEN = cnf.get_cloud(CLOUD, 'token') +identity_client = astakos.AstakosClient(URL, TOKEN) + +pithosURL = identity_client.get_endpoint_url(pithos.PithosClient.service_type) +storage_client = pithos.PithosClient(pithosURL, TOKEN) +storage_client.account = identity_client.user_info['id'] +storage_client.container = raw_input('Container to reassign: ') + +import json + +projects = [{p['id']: p['name']} for p in identity_client.get_projects()] +print 'These are your projects:', json.dumps(projects, indent=2) +storage_client.reassign_container(raw_input('Assign container to project id: ')) diff --git a/docs/developers/scripts/008_stream.py b/docs/developers/scripts/008_stream.py new file mode 100644 index 0000000000000000000000000000000000000000..7feec1da653b7fbb06097352e642e08ffef04ad5 --- /dev/null +++ b/docs/developers/scripts/008_stream.py @@ -0,0 +1,72 @@ +# Copyright 2014 GRNET S.A. All rights reserved. +# +# Redistribution and use in source and binary forms, with or +# without modification, are permitted provided that the following +# conditions are met: +# +# 1. Redistributions of source code must retain the above +# copyright notice, this list of conditions and the following +# disclaimer. +# +# 2. Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS +# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# The views and conclusions contained in the software and +# documentation are those of the authors and should not be +# interpreted as representing official policies, either expressed +# or implied, of GRNET S.A. + +from kamaki.cli.config import Config +from kamaki.clients import astakos, pithos, ClientError + +cnf = Config() +CLOUD = cnf.get('global', 'default_cloud') +URL = cnf.get_cloud(CLOUD, 'url') +TOKEN = cnf.get_cloud(CLOUD, 'token') +identity_client = astakos.AstakosClient(URL, TOKEN) + +pithosURL = identity_client.get_endpoint_url(pithos.PithosClient.service_type) +storage_client = pithos.PithosClient(pithosURL, TOKEN) +storage_client.account = identity_client.user_info['id'] +storage_client.container = 'pithos' + +obj = raw_input('Pick object to stream: ') +destination = raw_input('Stream it where? ') + +obj_size = int(storage_client.get_object_info(obj)['content-length']) +BLOCK_SIZE = int(storage_client.get_container_info()['x-container-block-size']) +CHUNK_SIZE = 4 * BLOCK_SIZE + +def stream(i, output): + """Stream the contents of buf[i] to output""" + output.write(bufs[i]) + +from kamaki.clients import SilentEvent + +with open(destination, 'w+') as output: + event = None + bufs = ['', ''] + for i in range(1 + (obj_size / CHUNK_SIZE)): + buf_index = i % 2 + start, end = CHUNK_SIZE * i, min(CHUNK_SIZE * (i + 1), obj_size) + bufs[buf_index] = storage_client.download_to_string( + obj, range_str='%s-%s' % (start, end)) + if event and not event.is_alive(): + event.join() + event = SilentEvent(stream, buf_index, output) + event.start() diff --git a/docs/developers/scripts/009_register_image.py b/docs/developers/scripts/009_register_image.py new file mode 100644 index 0000000000000000000000000000000000000000..9b0e2139cc334a585390b73d9bd07967471d45c4 --- /dev/null +++ b/docs/developers/scripts/009_register_image.py @@ -0,0 +1,62 @@ +# Copyright 2014 GRNET S.A. All rights reserved. +# +# Redistribution and use in source and binary forms, with or +# without modification, are permitted provided that the following +# conditions are met: +# +# 1. Redistributions of source code must retain the above +# copyright notice, this list of conditions and the following +# disclaimer. +# +# 2. Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS +# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# The views and conclusions contained in the software and +# documentation are those of the authors and should not be +# interpreted as representing official policies, either expressed +# or implied, of GRNET S.A. + +from kamaki.cli.config import Config +from kamaki.clients import astakos, pithos, image, ClientError +from kamaki.clients.utils import https + +https.patch_with_certs('/etc/ssl/certs/ca-certificates.crt') +cnf = Config() +CLOUD = cnf.get('global', 'default_cloud') +URL = cnf.get_cloud(CLOUD, 'url') +TOKEN = cnf.get_cloud(CLOUD, 'token') +identity_client = astakos.CachedAstakosClient(URL, TOKEN) + +imageURL = identity_client.get_endpoint_url(image.ImageClient.service_type) +image_client = image.ImageClient(imageURL, TOKEN) + +pithosURL = identity_client.get_endpoint_url(pithos.PithosClient.service_type) +storage_client = pithos.PithosClient(pithosURL, TOKEN) +storage_client.account = identity_client.user_info()['id'] +storage_client.container = 'pithos' + +storage_client.container, path = 'images', 'my_image.diskdump' +with open(path) as f: + storage_client.upload_object(path, f) + +location = (identity_client.user_info()['id'], storage_client.container, path) +properties = dict(osfamily='linux', users='root', os='debian') +img = image_client.register('My New Image', location, properties=properties) + +import json +print 'Image created sucesfully', json.dumps(img, indent=2) diff --git a/docs/developers/scripts/010_find_image.py b/docs/developers/scripts/010_find_image.py new file mode 100644 index 0000000000000000000000000000000000000000..5cd0d7cc00579914dc0a8e3b346e67a851e03714 --- /dev/null +++ b/docs/developers/scripts/010_find_image.py @@ -0,0 +1,51 @@ +# Copyright 2014 GRNET S.A. All rights reserved. +# +# Redistribution and use in source and binary forms, with or +# without modification, are permitted provided that the following +# conditions are met: +# +# 1. Redistributions of source code must retain the above +# copyright notice, this list of conditions and the following +# disclaimer. +# +# 2. Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS +# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# The views and conclusions contained in the software and +# documentation are those of the authors and should not be +# interpreted as representing official policies, either expressed +# or implied, of GRNET S.A. + +from kamaki.cli.config import Config +from kamaki.clients import astakos, image, ClientError +from kamaki.clients.utils import https + +https.patch_with_certs('/etc/ssl/certs/ca-certificates.crt') +cnf = Config() +CLOUD = cnf.get('global', 'default_cloud') +URL = cnf.get_cloud(CLOUD, 'url') +TOKEN = cnf.get_cloud(CLOUD, 'token') +identity_client = astakos.CachedAstakosClient(URL, TOKEN) + +imageURL = identity_client.get_endpoint_url(image.ImageClient.service_type) +image_client = image.ImageClient(imageURL, TOKEN) + +image_name = raw_input('Image name to look for:') +my_images = [img for img in image_client.list_public() if ( + img.get('owner') == identity_client.user_info()['id']) and ( + img.get('name') == image_name)] diff --git a/docs/developers/scripts/011_modify_image.py b/docs/developers/scripts/011_modify_image.py new file mode 100644 index 0000000000000000000000000000000000000000..51cdbdfe3f547a2559fb26d067a23c60b7168b52 --- /dev/null +++ b/docs/developers/scripts/011_modify_image.py @@ -0,0 +1,54 @@ +# Copyright 2014 GRNET S.A. All rights reserved. +# +# Redistribution and use in source and binary forms, with or +# without modification, are permitted provided that the following +# conditions are met: +# +# 1. Redistributions of source code must retain the above +# copyright notice, this list of conditions and the following +# disclaimer. +# +# 2. Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS +# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# The views and conclusions contained in the software and +# documentation are those of the authors and should not be +# interpreted as representing official policies, either expressed +# or implied, of GRNET S.A. + +from kamaki.cli.config import Config +from kamaki.clients import astakos, image, ClientError +from kamaki.clients.utils import https + +https.patch_with_certs('/etc/ssl/certs/ca-certificates.crt') +cnf = Config() +CLOUD = cnf.get('global', 'default_cloud') +URL = cnf.get_cloud(CLOUD, 'url') +TOKEN = cnf.get_cloud(CLOUD, 'token') +identity_client = astakos.CachedAstakosClient(URL, TOKEN) + +imageURL = identity_client.get_endpoint_url(image.ImageClient.service_type) +image_client = image.ImageClient(imageURL, TOKEN) + +location = (identity_client.user_info()['id'], 'images', 'my_image.diskdump') +properties = dict(osfamily='linux', users='root', os='debian') +img = image_client.register('My New Image', location, properties=properties) + +new_props = img.get('properties', dict()).update( + dict(description='Debian Wheezy', users='root user')) +image_client.update_image(img['id'], name='New Name', properties=new_props) diff --git a/docs/developers/scripts/012_unregister_image.py b/docs/developers/scripts/012_unregister_image.py new file mode 100644 index 0000000000000000000000000000000000000000..bbfbf74a5ea192a6cde868343f3d5c3a8a017df2 --- /dev/null +++ b/docs/developers/scripts/012_unregister_image.py @@ -0,0 +1,52 @@ +# Copyright 2014 GRNET S.A. All rights reserved. +# +# Redistribution and use in source and binary forms, with or +# without modification, are permitted provided that the following +# conditions are met: +# +# 1. Redistributions of source code must retain the above +# copyright notice, this list of conditions and the following +# disclaimer. +# +# 2. Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS +# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# The views and conclusions contained in the software and +# documentation are those of the authors and should not be +# interpreted as representing official policies, either expressed +# or implied, of GRNET S.A. + +from kamaki.cli.config import Config +from kamaki.clients import astakos, image, ClientError +from kamaki.clients.utils import https + +https.patch_with_certs('/etc/ssl/certs/ca-certificates.crt') +cnf = Config() +CLOUD = cnf.get('global', 'default_cloud') +URL = cnf.get_cloud(CLOUD, 'url') +TOKEN = cnf.get_cloud(CLOUD, 'token') +identity_client = astakos.CachedAstakosClient(URL, TOKEN) + +imageURL = identity_client.get_endpoint_url(image.ImageClient.service_type) +image_client = image.ImageClient(imageURL, TOKEN) + +location = (identity_client.user_info()['id'], 'images', 'my_image.diskdump') +properties = dict(osfamily='linux', users='root', os='debian') +img = image_client.register('My New Image', location, properties=properties) + +image_client.unregister(img['id']) diff --git a/docs/developers/scripts/013_find_flavors.py b/docs/developers/scripts/013_find_flavors.py new file mode 100644 index 0000000000000000000000000000000000000000..4fd5a894ec53179d0712396913bbb90e7b1b6ac5 --- /dev/null +++ b/docs/developers/scripts/013_find_flavors.py @@ -0,0 +1,51 @@ +# Copyright 2014 GRNET S.A. All rights reserved. +# +# Redistribution and use in source and binary forms, with or +# without modification, are permitted provided that the following +# conditions are met: +# +# 1. Redistributions of source code must retain the above +# copyright notice, this list of conditions and the following +# disclaimer. +# +# 2. Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS +# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# The views and conclusions contained in the software and +# documentation are those of the authors and should not be +# interpreted as representing official policies, either expressed +# or implied, of GRNET S.A. + +from kamaki.cli.config import Config +from kamaki.clients import astakos, cyclades, ClientError +from kamaki.clients.utils import https + +https.patch_with_certs('/etc/ssl/certs/ca-certificates.crt') +cnf = Config() +CLOUD = cnf.get('global', 'default_cloud') +URL = cnf.get_cloud(CLOUD, 'url') +TOKEN = cnf.get_cloud(CLOUD, 'token') +identity_client = astakos.CachedAstakosClient(URL, TOKEN) + +computeURL = identity_client.get_endpoint_url( + cyclades.CycladesComputeClient.service_type) +compute_client = cyclades.CycladesComputeClient(computeURL, TOKEN) + +for flv in compute_client.list_flavors(detail=True): + if flv['ram'] == 2048 and flv['vcpus'] == 2 and 20 <= flv['disk'] <= 40: + print 'Flavor', flv['id'], 'matches' diff --git a/docs/developers/scripts/014_create_server.py b/docs/developers/scripts/014_create_server.py new file mode 100644 index 0000000000000000000000000000000000000000..d336cad1042a13785e5946cda546dd314fe9b73d --- /dev/null +++ b/docs/developers/scripts/014_create_server.py @@ -0,0 +1,63 @@ +# Copyright 2014 GRNET S.A. All rights reserved. +# +# Redistribution and use in source and binary forms, with or +# without modification, are permitted provided that the following +# conditions are met: +# +# 1. Redistributions of source code must retain the above +# copyright notice, this list of conditions and the following +# disclaimer. +# +# 2. Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS +# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# The views and conclusions contained in the software and +# documentation are those of the authors and should not be +# interpreted as representing official policies, either expressed +# or implied, of GRNET S.A. + +from kamaki.cli.config import Config +from kamaki.clients import astakos, cyclades, ClientError +from kamaki.clients.utils import https + +https.patch_with_certs('/etc/ssl/certs/ca-certificates.crt') +cnf = Config() +CLOUD = cnf.get('global', 'default_cloud') +URL = cnf.get_cloud(CLOUD, 'url') +TOKEN = cnf.get_cloud(CLOUD, 'token') +identity_client = astakos.CachedAstakosClient(URL, TOKEN) + +computeURL = identity_client.get_endpoint_url( + cyclades.CycladesComputeClient.service_type) +compute_client = cyclades.CycladesComputeClient(computeURL, TOKEN) + +img = dict(id='10b79e4d-9362-4f30-9223-3105c9a84bce') +srv_name = raw_input('Server name: ') +flv = compute_client.get_flavor_details(raw_input('Flavor id: ')) + +srv = compute_client.create_server( + srv_name, flavor_id=flv['id'], image_id=img['id']) + +from base64 import b64encode +ssh_keys = dict( + contents=b64encode(open('~/.ssh/id_rsa.pub').read()), + path='/root/.ssh/authorized_keys', + owner='root', group='root', mode=0600) +ssh_srv = compute_client.create_server( + srv_name, + flavor_id=flv['id'], image_id=img['id'], personality=[ssh_keys, ]) diff --git a/docs/developers/scripts/015_connect_server.py b/docs/developers/scripts/015_connect_server.py new file mode 100644 index 0000000000000000000000000000000000000000..8367fd94353660a41c902a9d0846921591ed8fc4 --- /dev/null +++ b/docs/developers/scripts/015_connect_server.py @@ -0,0 +1,68 @@ +# Copyright 2014 GRNET S.A. All rights reserved. +# +# Redistribution and use in source and binary forms, with or +# without modification, are permitted provided that the following +# conditions are met: +# +# 1. Redistributions of source code must retain the above +# copyright notice, this list of conditions and the following +# disclaimer. +# +# 2. Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS +# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# The views and conclusions contained in the software and +# documentation are those of the authors and should not be +# interpreted as representing official policies, either expressed +# or implied, of GRNET S.A. + +from kamaki.cli.config import Config +from kamaki.clients import astakos, cyclades, ClientError +from kamaki.clients.utils import https + +https.patch_with_certs('/etc/ssl/certs/ca-certificates.crt') +cnf = Config() +CLOUD = cnf.get('global', 'default_cloud') +URL = cnf.get_cloud(CLOUD, 'url') +TOKEN = cnf.get_cloud(CLOUD, 'token') +identity_client = astakos.CachedAstakosClient(URL, TOKEN) + +computeURL = identity_client.get_endpoint_url( + cyclades.CycladesComputeClient.service_type) +compute_client = cyclades.CycladesComputeClient(computeURL, TOKEN) + +srv = dict(id=613275, metadata=dict(USERS='root'), adminPass='some password') +srv['SNF:fqdn'] = 'snf-613275.example.com' + +import json + +vnc_console = compute_client.get_server_console(srv['id']) +print 'The following VNC credentials will be invalidated shortly' +print json.dumps(vnc_console, indent=2) +print 'VM credentials:\n\t', srv['metadata']['USERS'], '\n\t', srv['adminPass'] + +conn_info = dict(fqdn=srv['SNF:fqdn'], ipv4=[], ipv6=[]) + +nics = compute_client.get_server_nics(srv['id']) +for port in nics['attachments']: + if port['ipv4']: + conn_info['ipv4'].append(port['ipv4']) + if port['ipv6']: + conn_info['ipv6'].append(port['ipv6']) + +print json.dumps(conn_info, indent=2) diff --git a/docs/developers/scripts/016_update_server.py b/docs/developers/scripts/016_update_server.py new file mode 100644 index 0000000000000000000000000000000000000000..2bad939bcd2660f07a60c2601267bd351acead41 --- /dev/null +++ b/docs/developers/scripts/016_update_server.py @@ -0,0 +1,53 @@ +# Copyright 2014 GRNET S.A. All rights reserved. +# +# Redistribution and use in source and binary forms, with or +# without modification, are permitted provided that the following +# conditions are met: +# +# 1. Redistributions of source code must retain the above +# copyright notice, this list of conditions and the following +# disclaimer. +# +# 2. Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS +# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# The views and conclusions contained in the software and +# documentation are those of the authors and should not be +# interpreted as representing official policies, either expressed +# or implied, of GRNET S.A. + +from kamaki.cli.config import Config +from kamaki.clients import astakos, cyclades, ClientError +from kamaki.clients.utils import https + +https.patch_with_certs('/etc/ssl/certs/ca-certificates.crt') +cnf = Config() +CLOUD = cnf.get('global', 'default_cloud') +URL = cnf.get_cloud(CLOUD, 'url') +TOKEN = cnf.get_cloud(CLOUD, 'token') +identity_client = astakos.CachedAstakosClient(URL, TOKEN) + +computeURL = identity_client.get_endpoint_url( + cyclades.CycladesComputeClient.service_type) +compute_client = cyclades.CycladesComputeClient(computeURL, TOKEN) + +srv = dict(id=613275) + +compute_client.update_server_name(srv['id'], 'New Server Name') +compute_client.update_server_metadata( + srv['id'], modified=True, description='No description') diff --git a/docs/developers/scripts/017_server_actions.py b/docs/developers/scripts/017_server_actions.py new file mode 100644 index 0000000000000000000000000000000000000000..bdeb53780e29bd4425789ac1a127da8e9d7e0428 --- /dev/null +++ b/docs/developers/scripts/017_server_actions.py @@ -0,0 +1,80 @@ +# Copyright 2014 GRNET S.A. All rights reserved. +# +# Redistribution and use in source and binary forms, with or +# without modification, are permitted provided that the following +# conditions are met: +# +# 1. Redistributions of source code must retain the above +# copyright notice, this list of conditions and the following +# disclaimer. +# +# 2. Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS +# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# The views and conclusions contained in the software and +# documentation are those of the authors and should not be +# interpreted as representing official policies, either expressed +# or implied, of GRNET S.A. + +from kamaki.cli.config import Config +from kamaki.clients import astakos, cyclades, ClientError +from kamaki.clients.utils import https + +https.patch_with_certs('/etc/ssl/certs/ca-certificates.crt') +cnf = Config() +CLOUD = cnf.get('global', 'default_cloud') +URL = cnf.get_cloud(CLOUD, 'url') +TOKEN = cnf.get_cloud(CLOUD, 'token') +identity_client = astakos.CachedAstakosClient(URL, TOKEN) + +computeURL = identity_client.get_endpoint_url( + cyclades.CycladesComputeClient.service_type) +compute_client = cyclades.CycladesComputeClient(computeURL, TOKEN) + +srv = dict(id=613275) + + +def assert_status(new, expected): + assert new is not None, 'Timeout while waiting for status %s' % expected + assert new == expected, 'Server did not reach status %s' % expected + +srv['status'] = compute_client.get_server_details(srv['id'])['status'] + +compute_client.shutdown_server(srv['id']) +print 'Wait for server to shutdown' +srv['status'] = compute_client.wait_server(srv['id'], srv['status']) +assert_status(srv['status'], 'STOPPED') +print '... OK' + +compute_client.start_server(srv['id']) +print 'Wait for server to start' +srv['status'] = compute_client.wait_server(srv['id'], srv['status']) +assert_status(srv['status'], 'ACTIVE') +print '... OK' + +compute_client.reboot_server(srv['id']) +print 'Wait for server to reboot' +srv['status'] = compute_client.wait_server(srv['id'], 'REBOOT') +assert_status(srv['status'], 'ACTIVE') +print '... OK' + +compute_client.delete_server(srv['id']) +print 'Wait for server to be deleted' +srv['status'] = compute_client.wait_server(srv['id'], srv['status']) +assert_status(srv['status'], 'DELETED') +print '... OK' diff --git a/docs/developers/scripts/018_separate_networks.py b/docs/developers/scripts/018_separate_networks.py new file mode 100644 index 0000000000000000000000000000000000000000..b310615b74b843cfa5a5ba895dead390347c70a3 --- /dev/null +++ b/docs/developers/scripts/018_separate_networks.py @@ -0,0 +1,57 @@ +# Copyright 2014 GRNET S.A. All rights reserved. +# +# Redistribution and use in source and binary forms, with or +# without modification, are permitted provided that the following +# conditions are met: +# +# 1. Redistributions of source code must retain the above +# copyright notice, this list of conditions and the following +# disclaimer. +# +# 2. Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS +# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# The views and conclusions contained in the software and +# documentation are those of the authors and should not be +# interpreted as representing official policies, either expressed +# or implied, of GRNET S.A. + +from kamaki.cli.config import Config +from kamaki.clients import astakos, cyclades, ClientError +from kamaki.clients.utils import https + +https.patch_with_certs('/etc/ssl/certs/ca-certificates.crt') +cnf = Config() +CLOUD = cnf.get('global', 'default_cloud') +URL = cnf.get_cloud(CLOUD, 'url') +TOKEN = cnf.get_cloud(CLOUD, 'token') +identity_client = astakos.CachedAstakosClient(URL, TOKEN) + +networkURL = identity_client.get_endpoint_url( + cyclades.CycladesNetworkClient.service_type) +network_client = cyclades.CycladesNetworkClient(networkURL, TOKEN) + +public_nets, vpns = [], [] +for net in network_client.list_networks(detail=True): + if net['public']: + public_nets.append(net) + else: + vpns.append(net) + +print 'Public networks:\n\t', '\n\t'.join(public_nets) +print 'Private networks:\n\t', '\n\t'.join(vpns) diff --git a/docs/developers/scripts/019_vpn.py b/docs/developers/scripts/019_vpn.py new file mode 100644 index 0000000000000000000000000000000000000000..55858b5b6bc8f1024ccbb4278ff99fb1554507fc --- /dev/null +++ b/docs/developers/scripts/019_vpn.py @@ -0,0 +1,56 @@ +# Copyright 2014 GRNET S.A. All rights reserved. +# +# Redistribution and use in source and binary forms, with or +# without modification, are permitted provided that the following +# conditions are met: +# +# 1. Redistributions of source code must retain the above +# copyright notice, this list of conditions and the following +# disclaimer. +# +# 2. Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS +# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# The views and conclusions contained in the software and +# documentation are those of the authors and should not be +# interpreted as representing official policies, either expressed +# or implied, of GRNET S.A. + +from kamaki.cli.config import Config +from kamaki.clients import astakos, cyclades, ClientError +from kamaki.clients.utils import https + +https.patch_with_certs('/etc/ssl/certs/ca-certificates.crt') +cnf = Config() +CLOUD = cnf.get('global', 'default_cloud') +URL = cnf.get_cloud(CLOUD, 'url') +TOKEN = cnf.get_cloud(CLOUD, 'token') +identity_client = astakos.CachedAstakosClient(URL, TOKEN) + +networkURL = identity_client.get_endpoint_url( + cyclades.CycladesNetworkClient.service_type) +network_client = cyclades.CycladesNetworkClient(networkURL, TOKEN) + +vpn = network_client.create_network( + type=cyclades.CycladesNetworkClient.network_types[1], name='New Net') +print 'Created VPN with id', vpn['id'], 'with name', vpn['name'] + +network_client.delete_network(vpn['id']) +print 'Deleted VPN', vpn['id'] + +print 'Network types:', cyclades.CycladesNetworkClient.network_types diff --git a/docs/developers/scripts/020_lookup_from_ip.py b/docs/developers/scripts/020_lookup_from_ip.py new file mode 100644 index 0000000000000000000000000000000000000000..4827eb41097d92d1b2a9e234705ebca02e647566 --- /dev/null +++ b/docs/developers/scripts/020_lookup_from_ip.py @@ -0,0 +1,60 @@ +# Copyright 2014 GRNET S.A. All rights reserved. +# +# Redistribution and use in source and binary forms, with or +# without modification, are permitted provided that the following +# conditions are met: +# +# 1. Redistributions of source code must retain the above +# copyright notice, this list of conditions and the following +# disclaimer. +# +# 2. Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS +# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# The views and conclusions contained in the software and +# documentation are those of the authors and should not be +# interpreted as representing official policies, either expressed +# or implied, of GRNET S.A. + +from kamaki.cli.config import Config +from kamaki.clients import astakos, cyclades, ClientError +from kamaki.clients.utils import https + +https.patch_with_certs('/etc/ssl/certs/ca-certificates.crt') +cnf = Config() +CLOUD = cnf.get('global', 'default_cloud') +URL = cnf.get_cloud(CLOUD, 'url') +TOKEN = cnf.get_cloud(CLOUD, 'token') +identity_client = astakos.CachedAstakosClient(URL, TOKEN) + +networkURL = identity_client.get_endpoint_url( + cyclades.CycladesNetworkClient.service_type) +network_client = cyclades.CycladesNetworkClient(networkURL, TOKEN) + +ip_addr, ip_id = '123.45.67.89', None + +for ip in network_client.list_floatingips(): + if ip_addr == ip['floating_ip_address']: + ip_id = ip['id'] + break + +ip = network_client.get_floatingip_details(ip_id) +if ip['instance_id']: + print 'IP', ip['floating_ip_address'], 'is used by', ip['instance_id'] +else: + print 'No servers are using IP', ip['floating_ip_address'] diff --git a/docs/developers/scripts/021_ip_pool.py b/docs/developers/scripts/021_ip_pool.py new file mode 100644 index 0000000000000000000000000000000000000000..77d770a933c17f2ea5b40fb873dce888eaaa897d --- /dev/null +++ b/docs/developers/scripts/021_ip_pool.py @@ -0,0 +1,53 @@ +# Copyright 2014 GRNET S.A. All rights reserved. +# +# Redistribution and use in source and binary forms, with or +# without modification, are permitted provided that the following +# conditions are met: +# +# 1. Redistributions of source code must retain the above +# copyright notice, this list of conditions and the following +# disclaimer. +# +# 2. Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS +# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# The views and conclusions contained in the software and +# documentation are those of the authors and should not be +# interpreted as representing official policies, either expressed +# or implied, of GRNET S.A. + +from kamaki.cli.config import Config +from kamaki.clients import astakos, cyclades, ClientError +from kamaki.clients.utils import https + +https.patch_with_certs('/etc/ssl/certs/ca-certificates.crt') +cnf = Config() +CLOUD = cnf.get('global', 'default_cloud') +URL = cnf.get_cloud(CLOUD, 'url') +TOKEN = cnf.get_cloud(CLOUD, 'token') +identity_client = astakos.CachedAstakosClient(URL, TOKEN) + +networkURL = identity_client.get_endpoint_url( + cyclades.CycladesNetworkClient.service_type) +network_client = cyclades.CycladesNetworkClient(networkURL, TOKEN) + +ip = network_client.create_floatingip() +print 'Reserved new IP', ip['floating_ip_address'] + +network_client.delete_floatingip(ip['id']) +print 'Released IP', ip['floating_ip_address'] diff --git a/docs/developers/scripts/022_handle_ip.py b/docs/developers/scripts/022_handle_ip.py new file mode 100644 index 0000000000000000000000000000000000000000..67b04b500a468db3227028297af04570b425adf1 --- /dev/null +++ b/docs/developers/scripts/022_handle_ip.py @@ -0,0 +1,71 @@ +# Copyright 2014 GRNET S.A. All rights reserved. +# +# Redistribution and use in source and binary forms, with or +# without modification, are permitted provided that the following +# conditions are met: +# +# 1. Redistributions of source code must retain the above +# copyright notice, this list of conditions and the following +# disclaimer. +# +# 2. Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS +# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# The views and conclusions contained in the software and +# documentation are those of the authors and should not be +# interpreted as representing official policies, either expressed +# or implied, of GRNET S.A. + +from kamaki.cli.config import Config +from kamaki.clients import astakos, cyclades, ClientError +from kamaki.clients.utils import https + +https.patch_with_certs('/etc/ssl/certs/ca-certificates.crt') +cnf = Config() +CLOUD = cnf.get('global', 'default_cloud') +URL = cnf.get_cloud(CLOUD, 'url') +TOKEN = cnf.get_cloud(CLOUD, 'token') +identity_client = astakos.CachedAstakosClient(URL, TOKEN) + +networkURL = identity_client.get_endpoint_url( + cyclades.CycladesNetworkClient.service_type) +network_client = cyclades.CycladesNetworkClient(networkURL, TOKEN) + +ip, srv = dict(id=567262, floating_ip_address='123.45.67.89'), dict(id=123456) + + +def assert_status(new, expected): + assert new is not None, 'Timeout while waiting for status %s' % expected + assert new == expected, 'Server did not reach status %s' % expected + +port = network_client.create_port( + network_id=ip['floating_network_id'], + device_id=srv['id'], + fixed_ips=[dict(ip_address=ip['floating_ip_address']), ]) + +print 'Attaching IP', ip['floating_ip_address'], 'to server', port['device_id'] +port['status'] = network_client.wait_port(port['id'], port['status']) +assert_status(port['status'], 'ACTIVE') +print '... OK' + +network_client.delete_port(port['id']) + +print 'Detaching IP', ip['floating_ip_address'], 'from', port['device_id'] +port['status'] = network_client.wait_port(port['id'], port['status']) +assert_status(port['status'], 'DELETED') +print '... OK' diff --git a/docs/developers/scripts/023_lookup_volume.py b/docs/developers/scripts/023_lookup_volume.py new file mode 100644 index 0000000000000000000000000000000000000000..a12d8de031cc8ae67cfae37925fc4234b85a8415 --- /dev/null +++ b/docs/developers/scripts/023_lookup_volume.py @@ -0,0 +1,64 @@ +# Copyright 2014 GRNET S.A. All rights reserved. +# +# Redistribution and use in source and binary forms, with or +# without modification, are permitted provided that the following +# conditions are met: +# +# 1. Redistributions of source code must retain the above +# copyright notice, this list of conditions and the following +# disclaimer. +# +# 2. Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS +# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# The views and conclusions contained in the software and +# documentation are those of the authors and should not be +# interpreted as representing official policies, either expressed +# or implied, of GRNET S.A. + +from kamaki.cli.config import Config +from kamaki.clients import astakos, cyclades, ClientError +from kamaki.clients.utils import https + +https.patch_with_certs('/etc/ssl/certs/ca-certificates.crt') +cnf = Config() +CLOUD = cnf.get('global', 'default_cloud') +URL = cnf.get_cloud(CLOUD, 'url') +TOKEN = cnf.get_cloud(CLOUD, 'token') +identity_client = astakos.CachedAstakosClient(URL, TOKEN) + +computeURL = identity_client.get_endpoint_url( + cyclades.CycladesComputeClient.service_type) +compute_client = cyclades.CycladesComputeClient(computeURL, TOKEN) + +volumeURL = identity_client.get_endpoint_url( + cyclades.CycladesBlockStorageClient.service_type) +volume_client = cyclades.CycladesBlockStorageClient(volumeURL, TOKEN) + +srv = compute_client.get_server_details(454001) + +print 'Volumes of server', srv['id'], ':', srv['volumes'] + +volumes = [] +for vol in volume_client.list_volumes(detail=True): + for att in vol['attachments']: + if att['server_id'] == srv['id']: + volumes.append(int(vol['id'])) + continue + +assert sorted(srv['volumes']) == sorted(volumes), 'Volumes do not match!' diff --git a/docs/developers/scripts/024_volume.py b/docs/developers/scripts/024_volume.py new file mode 100644 index 0000000000000000000000000000000000000000..e8c18870f58d28db4b85d6abba22cb77e80f0e9b --- /dev/null +++ b/docs/developers/scripts/024_volume.py @@ -0,0 +1,67 @@ +# Copyright 2014 GRNET S.A. All rights reserved. +# +# Redistribution and use in source and binary forms, with or +# without modification, are permitted provided that the following +# conditions are met: +# +# 1. Redistributions of source code must retain the above +# copyright notice, this list of conditions and the following +# disclaimer. +# +# 2. Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS +# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# The views and conclusions contained in the software and +# documentation are those of the authors and should not be +# interpreted as representing official policies, either expressed +# or implied, of GRNET S.A. + +from kamaki.cli.config import Config +from kamaki.clients import astakos, cyclades, ClientError +from kamaki.clients.utils import https + +https.patch_with_certs('/etc/ssl/certs/ca-certificates.crt') +cnf = Config() +CLOUD = cnf.get('global', 'default_cloud') +URL = cnf.get_cloud(CLOUD, 'url') +TOKEN = cnf.get_cloud(CLOUD, 'token') +identity_client = astakos.CachedAstakosClient(URL, TOKEN) + +computeURL = identity_client.get_endpoint_url( + cyclades.CycladesComputeClient.service_type) +compute_client = cyclades.CycladesComputeClient(computeURL, TOKEN) + +volumeURL = identity_client.get_endpoint_url( + cyclades.CycladesBlockStorageClient.service_type) +volume_client = cyclades.CycladesBlockStorageClient(volumeURL, TOKEN) + +srv = compute_client.get_server_details(454001) + +flv = compute_client.get_flavor_details(srv['flavor']['id']) +new_volume = volume_client.create_volume( + size=flv['disk'], server_id=srv['id'], display_name='New Volume') + +print 'status:', volume_client.get_volume_details(new_volume['id'])['status'] +import time +print 'wait 10 secs...' +time.sleep(10) +print 'status:', volume_client.get_volume_details(new_volume['id'])['status'] + +volume_client.delete_volume(new_volume['id']) + +print 'status:', volume_client.get_volume_details(new_volume['id'])['status'] diff --git a/docs/developers/scripts/025_lookup_snapshot.py b/docs/developers/scripts/025_lookup_snapshot.py new file mode 100644 index 0000000000000000000000000000000000000000..3314effa021b05d112afbddd1725180b00161062 --- /dev/null +++ b/docs/developers/scripts/025_lookup_snapshot.py @@ -0,0 +1,56 @@ +# Copyright 2014 GRNET S.A. All rights reserved. +# +# Redistribution and use in source and binary forms, with or +# without modification, are permitted provided that the following +# conditions are met: +# +# 1. Redistributions of source code must retain the above +# copyright notice, this list of conditions and the following +# disclaimer. +# +# 2. Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS +# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# The views and conclusions contained in the software and +# documentation are those of the authors and should not be +# interpreted as representing official policies, either expressed +# or implied, of GRNET S.A. + +from kamaki.cli.config import Config +from kamaki.clients import astakos, cyclades, ClientError +from kamaki.clients.utils import https + +https.patch_with_certs('/etc/ssl/certs/ca-certificates.crt') +cnf = Config() +CLOUD = cnf.get('global', 'default_cloud') +URL = cnf.get_cloud(CLOUD, 'url') +TOKEN = cnf.get_cloud(CLOUD, 'token') +identity_client = astakos.CachedAstakosClient(URL, TOKEN) + +computeURL = identity_client.get_endpoint_url( + cyclades.CycladesComputeClient.service_type) +compute_client = cyclades.CycladesComputeClient(computeURL, TOKEN) + +volumeURL = identity_client.get_endpoint_url( + cyclades.CycladesBlockStorageClient.service_type) +volume_client = cyclades.CycladesBlockStorageClient(volumeURL, TOKEN) + +srv = compute_client.get_server_details(454001) + +snapshots = [snp for snp in volume_client.list_snapshots(detail=True) if ( + snp['volume_id'] == srv['volumes'][0])] diff --git a/docs/developers/scripts/026_snapshot.py b/docs/developers/scripts/026_snapshot.py new file mode 100644 index 0000000000000000000000000000000000000000..d6cd4b54b6e743f3974a4fc3da9791bdb0518685 --- /dev/null +++ b/docs/developers/scripts/026_snapshot.py @@ -0,0 +1,57 @@ +# Copyright 2014 GRNET S.A. All rights reserved. +# +# Redistribution and use in source and binary forms, with or +# without modification, are permitted provided that the following +# conditions are met: +# +# 1. Redistributions of source code must retain the above +# copyright notice, this list of conditions and the following +# disclaimer. +# +# 2. Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS +# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# The views and conclusions contained in the software and +# documentation are those of the authors and should not be +# interpreted as representing official policies, either expressed +# or implied, of GRNET S.A. + +from kamaki.cli.config import Config +from kamaki.clients import astakos, cyclades, ClientError +from kamaki.clients.utils import https + +https.patch_with_certs('/etc/ssl/certs/ca-certificates.crt') +cnf = Config() +CLOUD = cnf.get('global', 'default_cloud') +URL = cnf.get_cloud(CLOUD, 'url') +TOKEN = cnf.get_cloud(CLOUD, 'token') +identity_client = astakos.CachedAstakosClient(URL, TOKEN) + +computeURL = identity_client.get_endpoint_url( + cyclades.CycladesComputeClient.service_type) +compute_client = cyclades.CycladesComputeClient(computeURL, TOKEN) + +volumeURL = identity_client.get_endpoint_url( + cyclades.CycladesBlockStorageClient.service_type) +volume_client = cyclades.CycladesBlockStorageClient(volumeURL, TOKEN) + +srv = compute_client.get_server_details(478999) + +new_snapshot = volume_client.create_snapshot(srv['volumes'][0], 'New Snapshot') + +volume_client.delete_snapshot(new_snapshot['id']) diff --git a/docs/developers/scripts/027_backup_snapshot.py b/docs/developers/scripts/027_backup_snapshot.py new file mode 100644 index 0000000000000000000000000000000000000000..9032eb1bc9a7a665d83d2869475389b8ec1c4e9d --- /dev/null +++ b/docs/developers/scripts/027_backup_snapshot.py @@ -0,0 +1,85 @@ +# Copyright 2014 GRNET S.A. All rights reserved. +# +# Redistribution and use in source and binary forms, with or +# without modification, are permitted provided that the following +# conditions are met: +# +# 1. Redistributions of source code must retain the above +# copyright notice, this list of conditions and the following +# disclaimer. +# +# 2. Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS +# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# The views and conclusions contained in the software and +# documentation are those of the authors and should not be +# interpreted as representing official policies, either expressed +# or implied, of GRNET S.A. + +from kamaki.cli.config import Config +from kamaki.clients import astakos, cyclades, ClientError, pithos, image +from kamaki.clients.utils import https + +https.patch_with_certs('/etc/ssl/certs/ca-certificates.crt') +cnf = Config() +CLOUD = cnf.get('global', 'default_cloud') +URL = cnf.get_cloud(CLOUD, 'url') +TOKEN = cnf.get_cloud(CLOUD, 'token') +identity_client = astakos.CachedAstakosClient(URL, TOKEN) + +pithosURL = identity_client.get_endpoint_url(pithos.PithosClient.service_type) +storage_client = pithos.PithosClient(pithosURL, TOKEN) +storage_client.account = identity_client.user_info()['id'] +storage_client.container = 'pithos' + +imageURL = identity_client.get_endpoint_url(image.ImageClient.service_type) +image_client = image.ImageClient(imageURL, TOKEN) + +computeURL = identity_client.get_endpoint_url( + cyclades.CycladesComputeClient.service_type) +compute_client = cyclades.CycladesComputeClient(computeURL, TOKEN) + +volumeURL = identity_client.get_endpoint_url( + cyclades.CycladesBlockStorageClient.service_type) +volume_client = cyclades.CycladesBlockStorageClient(volumeURL, TOKEN) + +srv = compute_client.get_server_details(478999) + +new_snapshot = volume_client.create_snapshot(srv['volumes'][0], 'new.snapshot') + +from time import sleep +print 'wait 10...' +sleep(10) + +compute_client.create_server( + name='Reserve', image_id=new_snapshot['id'], flavor_id=srv['flavor']['id']) + +obj = new_snapshot['display_name'] +storage_client.container = 'snapshots' +with open(obj, 'w+') as f: + storage_client.download_object(obj, f) + +with open(obj, 'r') as f: + storage_client.upload_object(obj, f) + +location = (storage_client.account, storage_client.container, obj) +props = dict(exclude_all_taks=True) +snp = image_client.register('Restored snapshot', location, properties=props) + +compute_client.create_server( + name='Reserve', image_id=snp['id'], flavor_id=srv['flavor']['id']) diff --git a/docs/devguide.rst b/docs/devguide.rst index f85643571450614ed8193ccb2d06dd2de57401b4..376f33c4e8f4f11b836b53bf4bc1879de009e701 100644 --- a/docs/devguide.rst +++ b/docs/devguide.rst @@ -9,7 +9,8 @@ Developers Guide developers/config developers/ssl developers/logging + developers/examples + developers/showcase developers/adding-commands developers/extending-clients-api - developers/showcase developers/code