Merge lp:~xtoddx/nova/lp70769 into lp:~hudson-openstack/nova/trunk

Proposed by Todd Willey
Status: Merged
Approved by: Vish Ishaya
Approved revision: 620
Merged at revision: 621
Proposed branch: lp:~xtoddx/nova/lp70769
Merge into: lp:~hudson-openstack/nova/trunk
Diff against target: 96 lines (+57/-0)
2 files modified
nova/adminclient.py (+44/-0)
nova/api/ec2/admin.py (+13/-0)
To merge this branch: bzr merge lp:~xtoddx/nova/lp70769
Reviewer Review Type Date Requested Status
Thierry Carrez (community) ffe Approve
Vish Ishaya (community) Approve
Devin Carlen (community) Approve
Review via email: mp+47488@code.launchpad.net

Description of the change

Add DescribeInstanceTypes to admin api. This lets the dashboard know what sizes can be launched (using the -t flag in euca-run-instances, for example) and what resources they provide.

To post a comment you must log in.
Revision history for this message
Devin Carlen (devcamcar) wrote :

lgtm, this fixes openstack-dashboard, yay!

review: Approve
Revision history for this message
Vish Ishaya (vishvananda) wrote :

lgtm

review: Approve
Revision history for this message
Thierry Carrez (ttx) wrote :

Note that this is an additional "feature" that should have been covered by a formal exception. That said, it is very self-contained and very needed, so consider it retrospectively granted :)

review: Approve (ffe)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'nova/adminclient.py'
2--- nova/adminclient.py 2011-01-10 21:06:36 +0000
3+++ nova/adminclient.py 2011-01-26 00:45:19 +0000
4@@ -190,6 +190,45 @@
5 setattr(self, name, value)
6
7
8+class InstanceType(object):
9+ """
10+ Information about a Nova instance type, as parsed through SAX.
11+
12+ **Fields include**
13+
14+ * name
15+ * vcpus
16+ * disk_gb
17+ * memory_mb
18+ * flavor_id
19+
20+ """
21+
22+ def __init__(self, connection=None):
23+ self.connection = connection
24+ self.name = None
25+ self.vcpus = None
26+ self.disk_gb = None
27+ self.memory_mb = None
28+ self.flavor_id = None
29+
30+ def __repr__(self):
31+ return 'InstanceType:%s' % self.name
32+
33+ def startElement(self, name, attrs, connection):
34+ return None
35+
36+ def endElement(self, name, value, connection):
37+ if name == "memoryMb":
38+ self.memory_mb = str(value)
39+ elif name == "flavorId":
40+ self.flavor_id = str(value)
41+ elif name == "diskGb":
42+ self.disk_gb = str(value)
43+ else:
44+ setattr(self, name, str(value))
45+
46+
47 class NovaAdminClient(object):
48
49 def __init__(
50@@ -373,3 +412,8 @@
51
52 def get_hosts(self):
53 return self.apiconn.get_list('DescribeHosts', {}, [('item', HostInfo)])
54+
55+ def get_instance_types(self):
56+ """Grabs the list of all users."""
57+ return self.apiconn.get_list('DescribeInstanceTypes', {},
58+ [('item', InstanceType)])
59
60=== modified file 'nova/api/ec2/admin.py'
61--- nova/api/ec2/admin.py 2011-01-19 20:26:09 +0000
62+++ nova/api/ec2/admin.py 2011-01-26 00:45:19 +0000
63@@ -26,6 +26,7 @@
64 from nova import exception
65 from nova import log as logging
66 from nova.auth import manager
67+from nova.compute import instance_types
68
69
70 LOG = logging.getLogger('nova.api.ec2.admin')
71@@ -62,6 +63,14 @@
72 return {}
73
74
75+def instance_dict(name, inst):
76+ return {'name': name,
77+ 'memory_mb': inst['memory_mb'],
78+ 'vcpus': inst['vcpus'],
79+ 'disk_gb': inst['local_gb'],
80+ 'flavor_id': inst['flavorid']}
81+
82+
83 class AdminController(object):
84 """
85 API Controller for users, hosts, nodes, and workers.
86@@ -70,6 +79,10 @@
87 def __str__(self):
88 return 'AdminController'
89
90+ def describe_instance_types(self, _context, **_kwargs):
91+ return {'instanceTypeSet': [instance_dict(n, v) for n, v in
92+ instance_types.INSTANCE_TYPES.iteritems()]}
93+
94 def describe_user(self, _context, name, **_kwargs):
95 """Returns user data, including access and secret keys."""
96 return user_dict(manager.AuthManager().get_user(name))