Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ExtendedHostController(object):
- """The Hosts API controller for the OpenStack API."""
- def __init__(self):
- self.api = compute.HostAPI()
- super(ExtendedHostController, self).__init__()
- @wsgi.extends
- def show(self, req, resp_obj, id):
- """ patch to add all available information of a host. """
- host = id
- context = req.environ['nova.context']
- service_ref = db.service_get_all_compute_by_host(context, host)[0]
- compute_ref = service_ref['compute_node'][0]
- try:
- cpu_info = json.loads(compute_ref['cpu_info'])
- except:
- cpu_info = False
- resp_obj['host'].append({'resource':
- {'host': host,
- 'project': 'status',
- 'state': compute_ref['state'],
- 'workload': compute_ref['current_workload'],
- 'running_vms': compute_ref['running_vms'],
- 'cpu_info': cpu_info,
- 'hypervisor_type': compute_ref.hypervisor_type,
- 'hypervisor_version': compute_ref.hypervisor_version,
- 'hypervisor_hostname': compute_ref.hypervisor_hostname}})
- class Hosts_state(extensions.ExtensionDescriptor):
- """Extensions for hosts"""
- name = "Hosts State Extension"
- alias = "EY-HOSTS-STATE"
- namespace = "http://docs.openstack.org/compute/ext/hosts/api/v1.1"
- updated = "2012-08-30T00:00:00+00:00"
- def get_controller_extensions(self):
- controller = ExtendedHostController()
- extension = extensions.ControllerExtension(self, 'os-hosts', controller)
- return [extension]
Advertisement
Add Comment
Please, Sign In to add comment