root / image_creator / kamaki_wrapper.py @ 40e7a487
History | View | Annotate | Download (2.8 kB)
1 | 40e7a487 | Nikos Skalkotos | # Copyright 2012 GRNET S.A. All rights reserved.
|
---|---|---|---|
2 | 40e7a487 | Nikos Skalkotos | #
|
3 | 40e7a487 | Nikos Skalkotos | # Redistribution and use in source and binary forms, with or
|
4 | 40e7a487 | Nikos Skalkotos | # without modification, are permitted provided that the following
|
5 | 40e7a487 | Nikos Skalkotos | # conditions are met:
|
6 | 40e7a487 | Nikos Skalkotos | #
|
7 | 40e7a487 | Nikos Skalkotos | # 1. Redistributions of source code must retain the above
|
8 | 40e7a487 | Nikos Skalkotos | # copyright notice, this list of conditions and the following
|
9 | 40e7a487 | Nikos Skalkotos | # disclaimer.
|
10 | 40e7a487 | Nikos Skalkotos | #
|
11 | 40e7a487 | Nikos Skalkotos | # 2. Redistributions in binary form must reproduce the above
|
12 | 40e7a487 | Nikos Skalkotos | # copyright notice, this list of conditions and the following
|
13 | 40e7a487 | Nikos Skalkotos | # disclaimer in the documentation and/or other materials
|
14 | 40e7a487 | Nikos Skalkotos | # provided with the distribution.
|
15 | 40e7a487 | Nikos Skalkotos | #
|
16 | 40e7a487 | Nikos Skalkotos | # THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
17 | 40e7a487 | Nikos Skalkotos | # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
18 | 40e7a487 | Nikos Skalkotos | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
19 | 40e7a487 | Nikos Skalkotos | # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
20 | 40e7a487 | Nikos Skalkotos | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
21 | 40e7a487 | Nikos Skalkotos | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22 | 40e7a487 | Nikos Skalkotos | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
23 | 40e7a487 | Nikos Skalkotos | # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
24 | 40e7a487 | Nikos Skalkotos | # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
25 | 40e7a487 | Nikos Skalkotos | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
26 | 40e7a487 | Nikos Skalkotos | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
27 | 40e7a487 | Nikos Skalkotos | # POSSIBILITY OF SUCH DAMAGE.
|
28 | 40e7a487 | Nikos Skalkotos | #
|
29 | 40e7a487 | Nikos Skalkotos | # The views and conclusions contained in the software and
|
30 | 40e7a487 | Nikos Skalkotos | # documentation are those of the authors and should not be
|
31 | 40e7a487 | Nikos Skalkotos | # interpreted as representing official policies, either expressed
|
32 | 40e7a487 | Nikos Skalkotos | # or implied, of GRNET S.A.
|
33 | 40e7a487 | Nikos Skalkotos | |
34 | 40e7a487 | Nikos Skalkotos | from os.path import basename |
35 | 40e7a487 | Nikos Skalkotos | |
36 | 40e7a487 | Nikos Skalkotos | from kamaki.config import Config |
37 | 40e7a487 | Nikos Skalkotos | from kamaki.clients.image import ImageClient |
38 | 40e7a487 | Nikos Skalkotos | |
39 | 40e7a487 | Nikos Skalkotos | from image_creator.util import FatalError |
40 | 40e7a487 | Nikos Skalkotos | |
41 | 40e7a487 | Nikos Skalkotos | CONTAINER = "images"
|
42 | 40e7a487 | Nikos Skalkotos | |
43 | 40e7a487 | Nikos Skalkotos | |
44 | 40e7a487 | Nikos Skalkotos | class Kamaki: |
45 | 40e7a487 | Nikos Skalkotos | __init__(self, account, token):
|
46 | 40e7a487 | Nikos Skalkotos | self.username = username
|
47 | 40e7a487 | Nikos Skalkotos | self.token = token
|
48 | 40e7a487 | Nikos Skalkotos | |
49 | 40e7a487 | Nikos Skalkotos | config = Config() |
50 | 40e7a487 | Nikos Skalkotos | |
51 | 40e7a487 | Nikos Skalkotos | pithos_url = config.get('storage', 'url') |
52 | 40e7a487 | Nikos Skalkotos | self.account = config.get('storage', 'account') |
53 | 40e7a487 | Nikos Skalkotos | self.container = CONTAINER
|
54 | 40e7a487 | Nikos Skalkotos | self.pithos_client = PithosClient(pithos_url, token, self.account, |
55 | 40e7a487 | Nikos Skalkotos | self.container)
|
56 | 40e7a487 | Nikos Skalkotos | |
57 | 40e7a487 | Nikos Skalkotos | image_url = config.get('image', 'url') |
58 | 40e7a487 | Nikos Skalkotos | self.image_client = ImageClient(image_url, token)
|
59 | 40e7a487 | Nikos Skalkotos | |
60 | 40e7a487 | Nikos Skalkotos | self.uploaded_object = None |
61 | 40e7a487 | Nikos Skalkotos | |
62 | 40e7a487 | Nikos Skalkotos | set_container(self, container):
|
63 | 40e7a487 | Nikos Skalkotos | self.pithos_client.container = container
|
64 | 40e7a487 | Nikos Skalkotos | |
65 | 40e7a487 | Nikos Skalkotos | upload(self, filename, size=None, remote_path=None): |
66 | 40e7a487 | Nikos Skalkotos | |
67 | 40e7a487 | Nikos Skalkotos | if remote_path is None: |
68 | 40e7a487 | Nikos Skalkotos | remote_path = basename(filename) |
69 | 40e7a487 | Nikos Skalkotos | |
70 | 40e7a487 | Nikos Skalkotos | with open(filename) as f: |
71 | 40e7a487 | Nikos Skalkotos | # TODO: create container if necessary
|
72 | 40e7a487 | Nikos Skalkotos | self.pithos_client.create_object(remote_path, f, size)
|
73 | 40e7a487 | Nikos Skalkotos | self.uploaded_object = "pithos://%s/%s/%s" % \ |
74 | 40e7a487 | Nikos Skalkotos | (self.account, self.container, remote_path) |
75 | 40e7a487 | Nikos Skalkotos | |
76 | 40e7a487 | Nikos Skalkotos | register(self, metadata):
|
77 | 40e7a487 | Nikos Skalkotos | pass
|
78 | 40e7a487 | Nikos Skalkotos | |
79 | 40e7a487 | Nikos Skalkotos | # vim: set sta sts=4 shiftwidth=4 sw=4 et ai |