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

« back to all changes in this revision

Viewing changes to nova/virt/powervm/driver.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-08-16 14:04:11 UTC
  • mto: This revision was merged to the branch mainline in revision 84.
  • Revision ID: package-import@ubuntu.com-20120816140411-0mr4n241wmk30t9l
Tags: upstream-2012.2~f3
ImportĀ upstreamĀ versionĀ 2012.2~f3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 
2
 
 
3
# Copyright 2012 IBM
 
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
 
8
#
 
9
#         http://www.apache.org/licenses/LICENSE-2.0
 
10
#
 
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
 
15
#    under the License.
 
16
 
 
17
from nova.compute import task_states
 
18
from nova.compute import vm_states
 
19
 
 
20
from nova import context as nova_context
 
21
from nova import db
 
22
from nova import flags
 
23
 
 
24
from nova.openstack.common import cfg
 
25
from nova.openstack.common import log as logging
 
26
 
 
27
from nova.virt import driver
 
28
from nova.virt.powervm import operator
 
29
 
 
30
 
 
31
LOG = logging.getLogger(__name__)
 
32
 
 
33
powervm_opts = [
 
34
    cfg.StrOpt('powervm_mgr_type',
 
35
               default='ivm',
 
36
               help='PowerVM manager type (ivm, hmc)'),
 
37
    cfg.StrOpt('powervm_mgr',
 
38
               default=None,
 
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',
 
44
               default=None,
 
45
               help='PowerVM manager user name'),
 
46
    cfg.StrOpt('powervm_mgr_passwd',
 
47
               default=None,
 
48
               help='PowerVM manager user password'),
 
49
    cfg.StrOpt('powervm_img_remote_path',
 
50
               default=None,
 
51
               help='PowerVM image remote path'),
 
52
    cfg.StrOpt('powervm_img_local_path',
 
53
               default=None,
 
54
               help='Local directory to download glance images to'),
 
55
    ]
 
56
 
 
57
FLAGS = flags.FLAGS
 
58
FLAGS.register_opts(powervm_opts)
 
59
 
 
60
 
 
61
class PowerVMDriver(driver.ComputeDriver):
 
62
 
 
63
    """PowerVM Implementation of Compute Driver."""
 
64
 
 
65
    def __init__(self):
 
66
        super(PowerVMDriver, self).__init__()
 
67
        self._powervm = operator.PowerVMOperator()
 
68
 
 
69
    @property
 
70
    def host_state(self):
 
71
        pass
 
72
 
 
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:
 
84
                continue
 
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,
 
88
                                    'task_state': None})
 
89
                db.instance_destroy(context, db_instance['uuid'])
 
90
 
 
91
    def get_info(self, instance):
 
92
        """Get the current status of an instance."""
 
93
        return self._powervm.get_info(instance['name'])
 
94
 
 
95
    def get_num_instances(self):
 
96
        return len(self.list_instances())
 
97
 
 
98
    def instance_exists(self, instance_name):
 
99
        return self._powervm.instance_exists(instance_name)
 
100
 
 
101
    def list_instances(self):
 
102
        return self._powervm.list_instances()
 
103
 
 
104
    def list_instances_detail(self):
 
105
        """Return a list of InstanceInfo for all registered VMs"""
 
106
        infos = []
 
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))
 
110
        return infos
 
111
 
 
112
    def get_host_stats(self, refresh=False):
 
113
        """Return currently known host stats"""
 
114
        return self._powervm.get_host_stats(refresh=refresh)
 
115
 
 
116
    def plug_vifs(self, instance, network_info):
 
117
        pass
 
118
 
 
119
    def spawn(self, context, instance, image_meta,
 
120
              network_info=None, block_device_info=None):
 
121
        """
 
122
        Create a new instance/VM/domain on powerVM.
 
123
 
 
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
 
130
        :param network_info:
 
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.
 
134
        """
 
135
        self._powervm.spawn(context, instance, image_meta['id'])
 
136
 
 
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'])
 
140
 
 
141
    def reboot(self, instance, network_info, reboot_type):
 
142
        """Reboot the specified instance.
 
143
 
 
144
        :param instance: Instance object as returned by DB layer.
 
145
        :param network_info:
 
146
           :py:meth:`~nova.network.manager.NetworkManager.get_instance_nw_info`
 
147
        :param reboot_type: Either a HARD or SOFT reboot
 
148
        """
 
149
        # TODO(Vek): Need to pass context in for access to auth_token
 
150
        pass
 
151
 
 
152
    def get_host_ip_addr(self):
 
153
        """
 
154
        Retrieves the IP address of the dom0
 
155
        """
 
156
        pass
 
157
 
 
158
    def pause(self, instance):
 
159
        """Pause the specified instance."""
 
160
        pass
 
161
 
 
162
    def unpause(self, instance):
 
163
        """Unpause paused VM instance"""
 
164
        pass
 
165
 
 
166
    def suspend(self, instance):
 
167
        """suspend the specified instance"""
 
168
        pass
 
169
 
 
170
    def resume(self, instance):
 
171
        """resume the specified instance"""
 
172
        pass
 
173
 
 
174
    def power_off(self, instance):
 
175
        """Power off the specified instance."""
 
176
        self._powervm.power_off(instance['name'])
 
177
 
 
178
    def power_on(self, instance):
 
179
        """Power on the specified instance"""
 
180
        self._powervm.power_on(instance['name'])
 
181
 
 
182
    def update_available_resource(self, ctxt, host):
 
183
        """Updates compute manager resource info on ComputeNode table.
 
184
 
 
185
        This method is called when nova-compute launches, and
 
186
        whenever admin executes "nova-manage service update_resource".
 
187
 
 
188
        :param ctxt: security context
 
189
        :param host: hostname that compute manager is currently running
 
190
 
 
191
        """
 
192
        pass
 
193
 
 
194
    def host_power_action(self, host, action):
 
195
        """Reboots, shuts down or powers up the host."""
 
196
        pass
 
197
 
 
198
    def legacy_nwinfo(self):
 
199
        """
 
200
        Indicate if the driver requires the legacy network_info format.
 
201
        """
 
202
        # TODO(tr3buchet): update all subclasses and remove this
 
203
        return False
 
204
 
 
205
    def manage_image_cache(self, context):
 
206
        """
 
207
        Manage the driver's local image cache.
 
208
 
 
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.
 
213
        """
 
214
        pass