Guest User

Openstack: extending an nova api extensions

a guest
Aug 31st, 2012
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.80 KB | None | 0 0
  1. class ExtendedHostController(object):
  2.     """The Hosts API controller for the OpenStack API."""
  3.     def __init__(self):
  4.         self.api = compute.HostAPI()
  5.         super(ExtendedHostController, self).__init__()
  6.  
  7.     @wsgi.extends
  8.     def show(self, req, resp_obj, id):
  9.         """ patch to add all available information of a host. """
  10.         host = id
  11.         context = req.environ['nova.context']
  12.         service_ref = db.service_get_all_compute_by_host(context, host)[0]
  13.         compute_ref = service_ref['compute_node'][0]
  14.         try:
  15.             cpu_info = json.loads(compute_ref['cpu_info'])
  16.         except:
  17.             cpu_info = False
  18.         resp_obj['host'].append({'resource':
  19.                                   {'host': host,
  20.                                    'project': 'status',
  21.                                    'state': compute_ref['state'],
  22.                                    'workload': compute_ref['current_workload'],
  23.                                    'running_vms': compute_ref['running_vms'],
  24.                                    'cpu_info': cpu_info,
  25.                                    'hypervisor_type': compute_ref.hypervisor_type,
  26.                                    'hypervisor_version': compute_ref.hypervisor_version,
  27.                                    'hypervisor_hostname': compute_ref.hypervisor_hostname}})
  28.  
  29.  
  30.  
  31.  
  32. class Hosts_state(extensions.ExtensionDescriptor):
  33.     """Extensions for hosts"""
  34.     name = "Hosts State Extension"
  35.     alias = "EY-HOSTS-STATE"
  36.     namespace = "http://docs.openstack.org/compute/ext/hosts/api/v1.1"
  37.     updated = "2012-08-30T00:00:00+00:00"
  38.  
  39.     def get_controller_extensions(self):
  40.         controller = ExtendedHostController()
  41.         extension = extensions.ControllerExtension(self, 'os-hosts', controller)
  42.         return [extension]
Advertisement
Add Comment
Please, Sign In to add comment