Skip to content
This repository was archived by the owner on Apr 25, 2019. It is now read-only.

Commit 446833b

Browse files
上野晶鋭上野晶鋭
authored andcommitted
Respond to issue 2, and change how to create signature and so on.
1 parent dbf6281 commit 446833b

File tree

18 files changed

+15574
-31
lines changed

18 files changed

+15574
-31
lines changed

.python-version

Lines changed: 0 additions & 1 deletion
This file was deleted.

PKG-INFO

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Metadata-Version: 1.0
22
Name: cloudstack.compute
3-
Version: 0.10.1
3+
Version: 0.10.2
44
Summary: Client for Cloud Stack
55
Home-page: UNKNOWN
66
Author: UNKNOWN

build/lib/cloudstack/__init__.py

Whitespace-only changes.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
from cloudstack.compute.shell import API_REFS
2+
from cloudstack.utils import res, dict2obj
3+
import client
4+
import urllib
5+
import sys
6+
7+
def valid_methods():
8+
return [r['name'] for r in API_REFS]
9+
10+
class Method(object):
11+
def __init__(self, command, method_name):
12+
self.command = command
13+
self.method_name = method_name
14+
15+
def __call__(self, **kwargs):
16+
api = [f for f in API_REFS if f['name'] == self.method_name]
17+
if not api:
18+
print '[%s] method is not suuported.' % self.method_name
19+
return
20+
options = api[0]['options']
21+
required_opt = [opt['option'][2:] for opt in options
22+
if opt['required'] == 'true']
23+
missing = set(required_opt) - set(kwargs.keys())
24+
if missing:
25+
print '[%s] option is required.' % ', '.join(list(missing))
26+
return
27+
28+
params = dict([(k,v) for (k,v) in kwargs.items()
29+
for opt in options
30+
if opt['option'][2:] == k])
31+
32+
json = client.connect(host=self.command.host,api_key=self.command.api_key,
33+
secret_key=self.command.secret_key,debug=self.command.debug
34+
).get(self.method_name,params)
35+
if json:
36+
retval = dict2obj(json[json.keys()[0]])
37+
if retval and hasattr(retval,'list'):
38+
return retval.list
39+
else:
40+
return retval
41+
42+
class Compute(object):
43+
def __init__(self,host=None,api_key=None,secret_key=None,api_refs_json=None,debug=False):
44+
self.host = host
45+
self.api_key = api_key
46+
self.secret_key = secret_key
47+
self.api_refs_json = api_refs_json
48+
self.debug = debug
49+
50+
def __getattr__(self,method_name):
51+
return Method(self,method_name)
52+
53+
def methods(self):
54+
return valid_methods()

0 commit comments

Comments
 (0)