~0x44/nova/bug838466

« back to all changes in this revision

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

  • Committer: Trey Morris
  • Date: 2011-06-30 19:20:59 UTC
  • mfrom: (1236 nova)
  • mto: This revision was merged to the branch mainline in revision 1237.
  • Revision ID: trey.morris@rackspace.com-20110630192059-pi1p516i50t8pc06
trunk merge with migration renumbering

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
import os
26
26
import pickle
27
27
import subprocess
 
28
import time
28
29
import uuid
29
30
 
30
31
from nova import context
44
45
 
45
46
XenAPI = None
46
47
LOG = logging.getLogger("nova.virt.xenapi.vmops")
 
48
 
47
49
FLAGS = flags.FLAGS
 
50
flags.DEFINE_integer('windows_version_timeout', 300,
 
51
                     'number of seconds to wait for windows agent to be '
 
52
                     'fully operational')
48
53
 
49
54
 
50
55
def cmp_version(a, b):
243
248
                        'architecture': instance.architecture})
244
249
 
245
250
        def _check_agent_version():
246
 
            version = self.get_agent_version(instance)
 
251
            if instance.os_type == 'windows':
 
252
                # Windows will generally perform a setup process on first boot
 
253
                # that can take a couple of minutes and then reboot. So we
 
254
                # need to be more patient than normal as well as watch for
 
255
                # domid changes
 
256
                version = self.get_agent_version(instance,
 
257
                                  timeout=FLAGS.windows_version_timeout)
 
258
            else:
 
259
                version = self.get_agent_version(instance)
247
260
            if not version:
248
261
                LOG.info(_('No agent version returned by instance'))
249
262
                return
498
511
        task = self._session.call_xenapi('Async.VM.clean_reboot', vm_ref)
499
512
        self._session.wait_for_task(task, instance.id)
500
513
 
501
 
    def get_agent_version(self, instance):
 
514
    def get_agent_version(self, instance, timeout=None):
502
515
        """Get the version of the agent running on the VM instance."""
503
516
 
504
 
        # Send the encrypted password
505
 
        transaction_id = str(uuid.uuid4())
506
 
        args = {'id': transaction_id}
507
 
        resp = self._make_agent_call('version', instance, '', args)
508
 
        if resp is None:
509
 
            # No response from the agent
510
 
            return
511
 
        resp_dict = json.loads(resp)
512
 
        return resp_dict['message']
 
517
        def _call():
 
518
            # Send the encrypted password
 
519
            transaction_id = str(uuid.uuid4())
 
520
            args = {'id': transaction_id}
 
521
            resp = self._make_agent_call('version', instance, '', args)
 
522
            if resp is None:
 
523
                # No response from the agent
 
524
                return
 
525
            resp_dict = json.loads(resp)
 
526
            return resp_dict['message']
 
527
 
 
528
        if timeout:
 
529
            vm_ref = self._get_vm_opaque_ref(instance)
 
530
            vm_rec = self._session.get_xenapi().VM.get_record(vm_ref)
 
531
 
 
532
            domid = vm_rec['domid']
 
533
 
 
534
            expiration = time.time() + timeout
 
535
            while time.time() < expiration:
 
536
                ret = _call()
 
537
                if ret:
 
538
                    return ret
 
539
 
 
540
                vm_rec = self._session.get_xenapi().VM.get_record(vm_ref)
 
541
                if vm_rec['domid'] != domid:
 
542
                    LOG.info(_('domid changed from %(olddomid)s to '
 
543
                               '%(newdomid)s') % {
 
544
                                   'olddomid': domid,
 
545
                                    'newdomid': vm_rec['domid']})
 
546
                    domid = vm_rec['domid']
 
547
        else:
 
548
            return _call()
513
549
 
514
550
    def agent_update(self, instance, url, md5sum):
515
551
        """Update agent on the VM instance."""