summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--nova/adminclient.py44
-rw-r--r--nova/api/ec2/admin.py13
2 files changed, 57 insertions, 0 deletions
diff --git a/nova/adminclient.py b/nova/adminclient.py
index b2609c8c4..3cdd8347f 100644
--- a/nova/adminclient.py
+++ b/nova/adminclient.py
@@ -190,6 +190,45 @@ class HostInfo(object):
setattr(self, name, value)
+class InstanceType(object):
+ """
+ Information about a Nova instance type, as parsed through SAX.
+
+ **Fields include**
+
+ * name
+ * vcpus
+ * disk_gb
+ * memory_mb
+ * flavor_id
+
+ """
+
+ def __init__(self, connection=None):
+ self.connection = connection
+ self.name = None
+ self.vcpus = None
+ self.disk_gb = None
+ self.memory_mb = None
+ self.flavor_id = None
+
+ def __repr__(self):
+ return 'InstanceType:%s' % self.name
+
+ def startElement(self, name, attrs, connection):
+ return None
+
+ def endElement(self, name, value, connection):
+ if name == "memoryMb":
+ self.memory_mb = str(value)
+ elif name == "flavorId":
+ self.flavor_id = str(value)
+ elif name == "diskGb":
+ self.disk_gb = str(value)
+ else:
+ setattr(self, name, str(value))
+
+
class NovaAdminClient(object):
def __init__(
@@ -373,3 +412,8 @@ class NovaAdminClient(object):
def get_hosts(self):
return self.apiconn.get_list('DescribeHosts', {}, [('item', HostInfo)])
+
+ def get_instance_types(self):
+ """Grabs the list of all users."""
+ return self.apiconn.get_list('DescribeInstanceTypes', {},
+ [('item', InstanceType)])
diff --git a/nova/api/ec2/admin.py b/nova/api/ec2/admin.py
index 78ff1b3e0..d7e899d12 100644
--- a/nova/api/ec2/admin.py
+++ b/nova/api/ec2/admin.py
@@ -26,6 +26,7 @@ from nova import db
from nova import exception
from nova import log as logging
from nova.auth import manager
+from nova.compute import instance_types
LOG = logging.getLogger('nova.api.ec2.admin')
@@ -62,6 +63,14 @@ def host_dict(host):
return {}
+def instance_dict(name, inst):
+ return {'name': name,
+ 'memory_mb': inst['memory_mb'],
+ 'vcpus': inst['vcpus'],
+ 'disk_gb': inst['local_gb'],
+ 'flavor_id': inst['flavorid']}
+
+
class AdminController(object):
"""
API Controller for users, hosts, nodes, and workers.
@@ -70,6 +79,10 @@ class AdminController(object):
def __str__(self):
return 'AdminController'
+ def describe_instance_types(self, _context, **_kwargs):
+ return {'instanceTypeSet': [instance_dict(n, v) for n, v in
+ instance_types.INSTANCE_TYPES.iteritems()]}
+
def describe_user(self, _context, name, **_kwargs):
"""Returns user data, including access and secret keys."""
return user_dict(manager.AuthManager().get_user(name))