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
25
responding to calls to check its state, attaching persistent storage, and
45
45
from nova import utils
46
46
from nova.compute import power_state
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')
56
55
class ComputeManager(manager.Manager):
57
57
"""Manages the running instances from creation to destruction."""
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)
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
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
98
:retval Returns a mapping of the instance information
99
that has just been created
102
instance_ref = self.db.instance_create(context, kwargs)
103
inst_id = instance_ref['id']
105
elevated = context.elevated()
106
if not security_groups:
108
for security_group_id in security_groups:
109
self.db.instance_add_security_group(elevated,
114
def update_instance(self, context, instance_id, **kwargs):
115
"""Updates the instance in the datastore.
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
126
self.db.instance_update(context, instance_id, kwargs)
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,
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)
180
137
yield self.driver.destroy(instance_ref)
182
139
# TODO(ja): should we keep it in a terminated state for a bit?