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

« back to all changes in this revision

Viewing changes to nova/compute/manager.py

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2010-12-13 10:17:01 UTC
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: james.westby@ubuntu.com-20101213101701-txhhqbzsxw4avnxv
Tags: upstream-2011.1~bzr456
ImportĀ upstreamĀ versionĀ 2011.1~bzr456

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
The :py:class:`ComputeManager` class is a :py:class:`nova.manager.Manager` that
23
23
handles RPC calls relating to creating instances.  It is responsible for
24
24
building a disk image, launching it via the underlying virtualization driver,
25
 
responding to calls to check it state, attaching persistent as well as
26
 
termination.
 
25
responding to calls to check its state, attaching persistent storage, and
 
26
terminating it.
27
27
 
28
28
**Related Flags**
29
29
 
45
45
from nova import utils
46
46
from nova.compute import power_state
47
47
 
48
 
 
49
48
FLAGS = flags.FLAGS
50
 
flags.DEFINE_string('instances_path', utils.abspath('../instances'),
 
49
flags.DEFINE_string('instances_path', '$state_path/instances',
51
50
                    'where instances are stored on disk')
52
51
flags.DEFINE_string('compute_driver', 'nova.virt.connection.get_connection',
53
 
                    'Driver to use for volume creation')
 
52
                    'Driver to use for controlling virtualization')
54
53
 
55
54
 
56
55
class ComputeManager(manager.Manager):
 
56
 
57
57
    """Manages the running instances from creation to destruction."""
58
58
 
59
59
    def __init__(self, compute_driver=None, *args, **kwargs):
84
84
        """This call passes stright through to the virtualization driver."""
85
85
        yield self.driver.refresh_security_group(security_group_id)
86
86
 
87
 
    def create_instance(self, context, security_groups=None, **kwargs):
88
 
        """Creates the instance in the datastore and returns the
89
 
        new instance as a mapping
90
 
 
91
 
        :param context: The security context
92
 
        :param security_groups: list of security group ids to
93
 
                                attach to the instance
94
 
        :param kwargs: All additional keyword args are treated
95
 
                       as data fields of the instance to be
96
 
                       created
97
 
 
98
 
        :retval Returns a mapping of the instance information
99
 
                that has just been created
100
 
 
101
 
        """
102
 
        instance_ref = self.db.instance_create(context, kwargs)
103
 
        inst_id = instance_ref['id']
104
 
 
105
 
        elevated = context.elevated()
106
 
        if not security_groups:
107
 
            security_groups = []
108
 
        for security_group_id in security_groups:
109
 
            self.db.instance_add_security_group(elevated,
110
 
                                                inst_id,
111
 
                                                security_group_id)
112
 
        return instance_ref
113
 
 
114
 
    def update_instance(self, context, instance_id, **kwargs):
115
 
        """Updates the instance in the datastore.
116
 
 
117
 
        :param context: The security context
118
 
        :param instance_id: ID of the instance to update
119
 
        :param kwargs: All additional keyword args are treated
120
 
                       as data fields of the instance to be
121
 
                       updated
122
 
 
123
 
        :retval None
124
 
 
125
 
        """
126
 
        self.db.instance_update(context, instance_id, kwargs)
127
 
 
128
87
    @defer.inlineCallbacks
129
88
    @exception.wrap_exception
130
89
    def run_instance(self, context, instance_id, **_kwargs):
134
93
        if instance_ref['name'] in self.driver.list_instances():
135
94
            raise exception.Error("Instance has already been created")
136
95
        logging.debug("instance %s: starting...", instance_id)
137
 
        project_id = instance_ref['project_id']
138
96
        self.network_manager.setup_compute_network(context, instance_id)
139
97
        self.db.instance_update(context,
140
98
                                instance_id,
176
134
            self.db.instance_destroy(context, instance_id)
177
135
            raise exception.Error('trying to destroy already destroyed'
178
136
                                  ' instance: %s' % instance_id)
179
 
 
180
137
        yield self.driver.destroy(instance_ref)
181
138
 
182
139
        # TODO(ja): should we keep it in a terminated state for a bit?