~mirantis/nova/non-shared-migrate

« back to all changes in this revision

Viewing changes to nova/compute/api.py

  • Committer: Tarmac
  • Author(s): Josh Kearney
  • Date: 2011-05-13 16:05:30 UTC
  • mfrom: (1066.3.4 lp781435)
  • Revision ID: tarmac-20110513160530-h6y8tjhzjcyn08g0
Make set_admin_password non-blocking to API.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
"""Handles all requests relating to instances (guest vms)."""
20
20
 
21
21
import datetime
 
22
import eventlet
22
23
import re
23
24
import time
24
25
 
42
43
 
43
44
FLAGS = flags.FLAGS
44
45
flags.DECLARE('vncproxy_topic', 'nova.vnc')
 
46
flags.DEFINE_integer('find_host_timeout', 30,
 
47
                     'Timeout after NN seconds when looking for a host.')
45
48
 
46
49
 
47
50
def generate_default_hostname(instance_id):
484
487
 
485
488
    def _find_host(self, context, instance_id):
486
489
        """Find the host associated with an instance."""
487
 
        for attempts in xrange(10):
 
490
        for attempts in xrange(FLAGS.find_host_timeout):
488
491
            instance = self.get(context, instance_id)
489
492
            host = instance["host"]
490
493
            if host:
493
496
        raise exception.Error(_("Unable to find host for Instance %s")
494
497
                                % instance_id)
495
498
 
 
499
    def _set_admin_password(self, context, instance_id, password):
 
500
        """Set the root/admin password for the given instance."""
 
501
        host = self._find_host(context, instance_id)
 
502
 
 
503
        rpc.cast(context,
 
504
                 self.db.queue_get_for(context, FLAGS.compute_topic, host),
 
505
                 {"method": "set_admin_password",
 
506
                  "args": {"instance_id": instance_id, "new_pass": password}})
 
507
 
496
508
    def snapshot(self, context, instance_id, name):
497
509
        """Snapshot the given instance.
498
510
 
646
658
 
647
659
    def set_admin_password(self, context, instance_id, password=None):
648
660
        """Set the root/admin password for the given instance."""
649
 
        host = self._find_host(context, instance_id)
650
 
 
651
 
        rpc.cast(context,
652
 
                 self.db.queue_get_for(context, FLAGS.compute_topic, host),
653
 
                 {"method": "set_admin_password",
654
 
                  "args": {"instance_id": instance_id, "new_pass": password}})
 
661
        eventlet.spawn_n(self._set_admin_password(context, instance_id,
 
662
                                                  password))
655
663
 
656
664
    def inject_file(self, context, instance_id):
657
665
        """Write a file to the given instance."""