Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
kamaki
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
itminedu
kamaki
Commits
e3132145
Commit
e3132145
authored
Aug 29, 2014
by
Stavros Sachtouris
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Write a set of short scripts using the kamaki lib
Fixes grnet/kamaki#49
parent
28dd8a05
Changes
31
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
31 changed files
with
2206 additions
and
1 deletion
+2206
-1
Changelog
Changelog
+5
-0
docs/developers/examples.rst
docs/developers/examples.rst
+493
-0
docs/developers/scripts/000_init.py
docs/developers/scripts/000_init.py
+73
-0
docs/developers/scripts/001_file_info.py
docs/developers/scripts/001_file_info.py
+55
-0
docs/developers/scripts/002_container_backup.py
docs/developers/scripts/002_container_backup.py
+59
-0
docs/developers/scripts/003_container_cleanup.py
docs/developers/scripts/003_container_cleanup.py
+56
-0
docs/developers/scripts/004_upload_files.py
docs/developers/scripts/004_upload_files.py
+61
-0
docs/developers/scripts/005_download_files.py
docs/developers/scripts/005_download_files.py
+62
-0
docs/developers/scripts/006_async_upload.py
docs/developers/scripts/006_async_upload.py
+56
-0
docs/developers/scripts/007_container_reassign.py
docs/developers/scripts/007_container_reassign.py
+52
-0
docs/developers/scripts/008_stream.py
docs/developers/scripts/008_stream.py
+72
-0
docs/developers/scripts/009_register_image.py
docs/developers/scripts/009_register_image.py
+62
-0
docs/developers/scripts/010_find_image.py
docs/developers/scripts/010_find_image.py
+51
-0
docs/developers/scripts/011_modify_image.py
docs/developers/scripts/011_modify_image.py
+54
-0
docs/developers/scripts/012_unregister_image.py
docs/developers/scripts/012_unregister_image.py
+52
-0
docs/developers/scripts/013_find_flavors.py
docs/developers/scripts/013_find_flavors.py
+51
-0
docs/developers/scripts/014_create_server.py
docs/developers/scripts/014_create_server.py
+63
-0
docs/developers/scripts/015_connect_server.py
docs/developers/scripts/015_connect_server.py
+68
-0
docs/developers/scripts/016_update_server.py
docs/developers/scripts/016_update_server.py
+53
-0
docs/developers/scripts/017_server_actions.py
docs/developers/scripts/017_server_actions.py
+80
-0
docs/developers/scripts/018_separate_networks.py
docs/developers/scripts/018_separate_networks.py
+57
-0
docs/developers/scripts/019_vpn.py
docs/developers/scripts/019_vpn.py
+56
-0
docs/developers/scripts/020_lookup_from_ip.py
docs/developers/scripts/020_lookup_from_ip.py
+60
-0
docs/developers/scripts/021_ip_pool.py
docs/developers/scripts/021_ip_pool.py
+53
-0
docs/developers/scripts/022_handle_ip.py
docs/developers/scripts/022_handle_ip.py
+71
-0
docs/developers/scripts/023_lookup_volume.py
docs/developers/scripts/023_lookup_volume.py
+64
-0
docs/developers/scripts/024_volume.py
docs/developers/scripts/024_volume.py
+67
-0
docs/developers/scripts/025_lookup_snapshot.py
docs/developers/scripts/025_lookup_snapshot.py
+56
-0
docs/developers/scripts/026_snapshot.py
docs/developers/scripts/026_snapshot.py
+57
-0
docs/developers/scripts/027_backup_snapshot.py
docs/developers/scripts/027_backup_snapshot.py
+85
-0
docs/devguide.rst
docs/devguide.rst
+2
-1
No files found.
Changelog
View file @
e3132145
...
...
@@ -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
========
...
...
docs/developers/examples.rst
0 → 100644
View file @
e3132145
This diff is collapsed.
Click to expand it.
docs/developers/scripts/000_init.py
0 → 100644
View file @
e3132145
# 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
)
docs/developers/scripts/001_file_info.py
0 → 100644
View file @
e3132145
# 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
)
docs/developers/scripts/002_container_backup.py
0 → 100644
View file @
e3132145
# 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
docs/developers/scripts/003_container_cleanup.py
0 → 100644
View file @
e3132145
# 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
docs/developers/scripts/004_upload_files.py
0 → 100644
View file @
e3132145
# 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
)
docs/developers/scripts/005_download_files.py
0 → 100644
View file @
e3132145
# 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
)
docs/developers/scripts/006_async_upload.py
0 → 100644
View file @
e3132145
# 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
])
docs/developers/scripts/007_container_reassign.py
0 → 100644
View file @
e3132145
# 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: '
))
docs/developers/scripts/008_stream.py
0 → 100644
View file @
e3132145
# 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
()
docs/developers/scripts/009_register_image.py
0 → 100644
View file @
e3132145
# 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
)
docs/developers/scripts/010_find_image.py
0 → 100644
View file @
e3132145
# 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
)]
docs/developers/scripts/011_modify_image.py
0 → 100644
View file @
e3132145
# 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