~ubuntu-branches/ubuntu/quantal/nova/quantal-proposed

« back to all changes in this revision

Viewing changes to nova/virt/xenapi/host.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-08-16 14:04:11 UTC
  • mto: This revision was merged to the branch mainline in revision 84.
  • Revision ID: package-import@ubuntu.com-20120816140411-0mr4n241wmk30t9l
Tags: upstream-2012.2~f3
ImportĀ upstreamĀ versionĀ 2012.2~f3

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
from nova import exception
29
29
from nova import notifications
30
30
from nova.openstack.common import jsonutils
 
31
from nova.virt.xenapi import pool_states
31
32
from nova.virt.xenapi import vm_utils
32
33
 
33
34
LOG = logging.getLogger(__name__)
38
39
    Implements host related operations.
39
40
    """
40
41
    def __init__(self, session):
41
 
        self.XenAPI = session.get_imported_xenapi()
42
42
        self._session = session
43
43
 
44
44
    def host_power_action(self, _host, action):
79
79
                    dest = _host_find(ctxt, self._session, host, host_ref)
80
80
                    (old_ref, new_ref) = db.instance_update_and_get_original(
81
81
                                    ctxt,
82
 
                                    instance.id,
 
82
                                    instance['uuid'],
83
83
                                    {'host': dest,
84
84
                                     'task_state': task_states.MIGRATING})
85
85
                    notifications.send_update(ctxt, old_ref, new_ref)
90
90
 
91
91
                    (old_ref, new_ref) = db.instance_update_and_get_original(
92
92
                                ctxt,
93
 
                                instance.id,
 
93
                                instance['uuid'],
94
94
                                {'vm_state': vm_states.ACTIVE})
95
95
                    notifications.send_update(ctxt, old_ref, new_ref)
96
96
 
97
97
                    break
98
 
                except self.XenAPI.Failure:
 
98
                except self._session.XenAPI.Failure:
99
99
                    LOG.exception('Unable to migrate VM %(vm_ref)s'
100
100
                                  'from %(host)s' % locals())
101
101
                    (old_ref, new_ref) = db.instance_update_and_get_original(
102
102
                                ctxt,
103
 
                                instance.id,
 
103
                                instance['uuid'],
104
104
                                {'hosts': host,
105
105
                                 'vm_state': vm_states.ACTIVE})
106
106
                    notifications.send_update(ctxt, old_ref, new_ref)
117
117
        response = call_xenhost(self._session, "set_host_enabled", args)
118
118
        return response.get("status", response)
119
119
 
 
120
    def get_host_uptime(self, _host):
 
121
        """Returns the result of calling "uptime" on the target host."""
 
122
        response = call_xenhost(self._session, "host_uptime", {})
 
123
        return response.get("uptime", response)
 
124
 
120
125
 
121
126
class HostState(object):
122
127
    """Manages information about the XenServer host this compute
173
178
    out that behavior.
174
179
    """
175
180
    # Create a task ID as something that won't match any instance ID
176
 
    XenAPI = session.get_imported_xenapi()
177
181
    try:
178
182
        result = session.call_plugin('xenhost', method, args=arg_dict)
179
183
        if not result:
182
186
    except ValueError:
183
187
        LOG.exception(_("Unable to get updated status"))
184
188
        return None
185
 
    except XenAPI.Failure as e:
 
189
    except session.XenAPI.Failure as e:
186
190
        LOG.error(_("The call to %(method)s returned "
187
191
                    "an error: %(e)s.") % locals())
188
192
        return e.details[1]
207
211
    # NOTE: this would be a lot simpler if nova-compute stored
208
212
    # FLAGS.host in the XenServer host's other-config map.
209
213
    # TODO(armando-migliaccio): improve according the note above
210
 
    aggregate = db.aggregate_get_by_host(context, src)
 
214
    aggregate = db.aggregate_get_by_host(context, src,
 
215
            key=pool_states.POOL_FLAG)[0]
 
216
    if not aggregate:
 
217
        raise exception.AggregateHostNotFound(host=src)
211
218
    uuid = session.call_xenapi('host.get_record', dst)['uuid']
212
219
    for compute_host, host_uuid in aggregate.metadetails.iteritems():
213
220
        if host_uuid == uuid: