1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
5
# Licensed under the Apache License, Version 2.0 (the "License"); you may
6
# not use this file except in compliance with the License. You may obtain
7
# a copy of the License at
9
# http://www.apache.org/licenses/LICENSE-2.0
11
# Unless required by applicable law or agreed to in writing, software
12
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
# License for the specific language governing permissions and limitations
17
from nova.compute import task_states
18
from nova.compute import vm_states
20
from nova import context as nova_context
22
from nova import flags
24
from nova.openstack.common import cfg
25
from nova.openstack.common import log as logging
27
from nova.virt import driver
28
from nova.virt.powervm import operator
31
LOG = logging.getLogger(__name__)
34
cfg.StrOpt('powervm_mgr_type',
36
help='PowerVM manager type (ivm, hmc)'),
37
cfg.StrOpt('powervm_mgr',
39
help='PowerVM manager host or ip'),
40
cfg.StrOpt('powervm_vios',
41
default='powervm_mgr',
42
help='PowerVM vios host or ip if different from manager'),
43
cfg.StrOpt('powervm_mgr_user',
45
help='PowerVM manager user name'),
46
cfg.StrOpt('powervm_mgr_passwd',
48
help='PowerVM manager user password'),
49
cfg.StrOpt('powervm_img_remote_path',
51
help='PowerVM image remote path'),
52
cfg.StrOpt('powervm_img_local_path',
54
help='Local directory to download glance images to'),
58
FLAGS.register_opts(powervm_opts)
61
class PowerVMDriver(driver.ComputeDriver):
63
"""PowerVM Implementation of Compute Driver."""
66
super(PowerVMDriver, self).__init__()
67
self._powervm = operator.PowerVMOperator()
73
def init_host(self, host):
74
"""Initialize anything that is necessary for the driver to function,
75
including catching up with currently running VM's on the given host."""
76
context = nova_context.get_admin_context()
77
instances = db.instance_get_all_by_host(context, host)
78
powervm_instances = self.list_instances()
79
# Looks for db instances that don't exist on the host side
80
# and cleanup the inconsistencies.
81
for db_instance in instances:
82
task_state = db_instance['task_state']
83
if db_instance['name'] in powervm_instances:
85
if task_state in [task_states.DELETING, task_states.SPAWNING]:
86
db.instance_update(context, db_instance['uuid'],
87
{'vm_state': vm_states.DELETED,
89
db.instance_destroy(context, db_instance['uuid'])
91
def get_info(self, instance):
92
"""Get the current status of an instance."""
93
return self._powervm.get_info(instance['name'])
95
def get_num_instances(self):
96
return len(self.list_instances())
98
def instance_exists(self, instance_name):
99
return self._powervm.instance_exists(instance_name)
101
def list_instances(self):
102
return self._powervm.list_instances()
104
def list_instances_detail(self):
105
"""Return a list of InstanceInfo for all registered VMs"""
107
for instance_name in self.list_instances():
108
state = self._powervm.get_info(instance_name)['state']
109
infos.append(driver.InstanceInfo(instance_name, state))
112
def get_host_stats(self, refresh=False):
113
"""Return currently known host stats"""
114
return self._powervm.get_host_stats(refresh=refresh)
116
def plug_vifs(self, instance, network_info):
119
def spawn(self, context, instance, image_meta,
120
network_info=None, block_device_info=None):
122
Create a new instance/VM/domain on powerVM.
124
:param context: security context
125
:param instance: Instance object as returned by DB layer.
126
This function should use the data there to guide
127
the creation of the new instance.
128
:param image_meta: image object returned by nova.image.glance that
129
defines the image from which to boot this instance
131
:py:meth:`~nova.network.manager.NetworkManager.get_instance_nw_info`
132
:param block_device_info: Information about block devices to be
133
attached to the instance.
135
self._powervm.spawn(context, instance, image_meta['id'])
137
def destroy(self, instance, network_info, block_device_info=None):
138
"""Destroy (shutdown and delete) the specified instance."""
139
self._powervm.destroy(instance['name'])
141
def reboot(self, instance, network_info, reboot_type):
142
"""Reboot the specified instance.
144
:param instance: Instance object as returned by DB layer.
146
:py:meth:`~nova.network.manager.NetworkManager.get_instance_nw_info`
147
:param reboot_type: Either a HARD or SOFT reboot
149
# TODO(Vek): Need to pass context in for access to auth_token
152
def get_host_ip_addr(self):
154
Retrieves the IP address of the dom0
158
def pause(self, instance):
159
"""Pause the specified instance."""
162
def unpause(self, instance):
163
"""Unpause paused VM instance"""
166
def suspend(self, instance):
167
"""suspend the specified instance"""
170
def resume(self, instance):
171
"""resume the specified instance"""
174
def power_off(self, instance):
175
"""Power off the specified instance."""
176
self._powervm.power_off(instance['name'])
178
def power_on(self, instance):
179
"""Power on the specified instance"""
180
self._powervm.power_on(instance['name'])
182
def update_available_resource(self, ctxt, host):
183
"""Updates compute manager resource info on ComputeNode table.
185
This method is called when nova-compute launches, and
186
whenever admin executes "nova-manage service update_resource".
188
:param ctxt: security context
189
:param host: hostname that compute manager is currently running
194
def host_power_action(self, host, action):
195
"""Reboots, shuts down or powers up the host."""
198
def legacy_nwinfo(self):
200
Indicate if the driver requires the legacy network_info format.
202
# TODO(tr3buchet): update all subclasses and remove this
205
def manage_image_cache(self, context):
207
Manage the driver's local image cache.
209
Some drivers chose to cache images for instances on disk. This method
210
is an opportunity to do management of that cache which isn't directly
211
related to other calls into the driver. The prime example is to clean
212
the cache and remove images which are no longer of interest.