~ttx/nova/d4-merge

« back to all changes in this revision

Viewing changes to nova/api/openstack/contrib/hosts.py

  • Committer: Thierry Carrez
  • Date: 2011-08-23 12:23:07 UTC
  • mfrom: (1130.75.258 nova)
  • Revision ID: thierry@openstack.org-20110823122307-f0vtuyg1ikc14n87
Merge diablo-4 development from trunk (rev1479)

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
from nova.api.openstack import common
25
25
from nova.api.openstack import extensions
26
26
from nova.api.openstack import faults
 
27
from nova.api.openstack.contrib import admin_only
27
28
from nova.scheduler import api as scheduler_api
28
29
 
29
30
 
70
71
            key = raw_key.lower().strip()
71
72
            val = raw_val.lower().strip()
72
73
            # NOTE: (dabo) Right now only 'status' can be set, but other
73
 
            # actions may follow.
 
74
            # settings may follow.
74
75
            if key == "status":
75
76
                if val[:6] in ("enable", "disabl"):
76
77
                    return self._set_enabled_status(req, id,
89
90
        LOG.audit(_("Setting host %(host)s to %(state)s.") % locals())
90
91
        result = self.compute_api.set_host_enabled(context, host=host,
91
92
                enabled=enabled)
 
93
        if result not in ("enabled", "disabled"):
 
94
            # An error message was returned
 
95
            raise webob.exc.HTTPBadRequest(explanation=result)
92
96
        return {"host": host, "status": result}
93
97
 
 
98
    def _host_power_action(self, req, host, action):
 
99
        """Reboots, shuts down or powers up the host."""
 
100
        context = req.environ['nova.context']
 
101
        try:
 
102
            result = self.compute_api.host_power_action(context, host=host,
 
103
                    action=action)
 
104
        except NotImplementedError as e:
 
105
            raise webob.exc.HTTPBadRequest(explanation=e.msg)
 
106
        return {"host": host, "power_action": result}
 
107
 
 
108
    def startup(self, req, id):
 
109
        return self._host_power_action(req, host=id, action="startup")
 
110
 
 
111
    def shutdown(self, req, id):
 
112
        return self._host_power_action(req, host=id, action="shutdown")
 
113
 
 
114
    def reboot(self, req, id):
 
115
        return self._host_power_action(req, host=id, action="reboot")
 
116
 
94
117
 
95
118
class Hosts(extensions.ExtensionDescriptor):
96
119
    def get_name(self):
108
131
    def get_updated(self):
109
132
        return "2011-06-29T00:00:00+00:00"
110
133
 
 
134
    @admin_only.admin_only
111
135
    def get_resources(self):
112
 
        resources = [extensions.ResourceExtension('os-hosts', HostController(),
113
 
                collection_actions={'update': 'PUT'}, member_actions={})]
 
136
        resources = [extensions.ResourceExtension('os-hosts',
 
137
                HostController(), collection_actions={'update': 'PUT'},
 
138
                member_actions={"startup": "GET", "shutdown": "GET",
 
139
                        "reboot": "GET"})]
114
140
        return resources