adding nova.get_vm task
Adding nova.get_vm task to retrieve VM information Change-Id: Id6dc05f274438f934a8baeaa2991bd76541bf6d1
This commit is contained in:
parent
4aef254997
commit
089c73d556
|
@ -18,7 +18,6 @@ import taskflow.retry as retry
|
|||
|
||||
import cue.client as client
|
||||
import cue.taskflow.task as cue_task
|
||||
import os_tasklib.cinder as cinder_task
|
||||
import os_tasklib.common as common_task
|
||||
import os_tasklib.neutron as neutron_task
|
||||
import os_tasklib.nova as nova_task
|
||||
|
@ -28,8 +27,6 @@ def create_cluster():
|
|||
flow = linear_flow.Flow('creating vm').add(
|
||||
neutron_task.CreatePort(os_client=client.neutron_client(),
|
||||
provides='neutron_port_id'),
|
||||
cinder_task.CreateVolume(os_client=client.cinder_client(),
|
||||
provides='cinder_volume_id'),
|
||||
nova_task.CreateVm(os_client=client.nova_client(),
|
||||
requires=('name', 'image', 'flavor', 'nics'),
|
||||
provides='nova_vm_id'),
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2015 Hewlett-Packard Development Company, L.P.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import uuid
|
||||
|
||||
from cue import client
|
||||
from cue.tests import base
|
||||
from cue.tests.test_fixtures import nova
|
||||
import os_tasklib.nova.get_vm as get_vm
|
||||
|
||||
import novaclient.exceptions as nova_exc
|
||||
from taskflow import engines
|
||||
from taskflow.patterns import linear_flow
|
||||
|
||||
|
||||
class GetVmTests(base.TestCase):
|
||||
additional_fixtures = [
|
||||
nova.NovaClient,
|
||||
]
|
||||
|
||||
def setUp(self):
|
||||
super(GetVmTests, self).setUp()
|
||||
|
||||
image_name = "cirros-0.3.2-x86_64-uec-kernel"
|
||||
flavor_name = "m1.tiny"
|
||||
|
||||
self.nova_client = client.nova_client()
|
||||
|
||||
self.valid_vm_name = uuid.uuid4().hex
|
||||
valid_image = self.nova_client.images.find(name=image_name)
|
||||
valid_flavor = self.nova_client.flavors.find(name=flavor_name)
|
||||
new_vm = self.nova_client.servers.create(name=self.valid_vm_name,
|
||||
image=valid_image,
|
||||
flavor=valid_flavor)
|
||||
self.valid_vm_id = new_vm.id
|
||||
|
||||
self.flow = linear_flow.Flow("create vm flow")
|
||||
self.flow.add(
|
||||
get_vm.GetVm(
|
||||
os_client=self.nova_client,
|
||||
requires=('server',),
|
||||
provides=('vm_info')
|
||||
)
|
||||
)
|
||||
|
||||
def test_get_valid_vm(self):
|
||||
flow_store = {
|
||||
'server': self.valid_vm_id
|
||||
}
|
||||
|
||||
result = engines.run(self.flow, store=flow_store)
|
||||
new_vm = result['vm_info']
|
||||
self.assertEqual(self.valid_vm_id, new_vm['id'])
|
||||
self.assertEqual(self.valid_vm_name, new_vm['name'])
|
||||
|
||||
def test_get_invalid_vm(self):
|
||||
invalid_vm_id = uuid.uuid4().hex
|
||||
flow_store = {
|
||||
'server': invalid_vm_id
|
||||
}
|
||||
|
||||
self.assertRaises(nova_exc.NotFound, engines.run,
|
||||
self.flow, store=flow_store)
|
||||
|
||||
def tearDown(self):
|
||||
if self.valid_vm_id is not None:
|
||||
self.nova_client.servers.delete(self.valid_vm_id)
|
||||
super(GetVmTests, self).tearDown()
|
|
@ -160,9 +160,14 @@ class NovaClient(base.BaseFixture):
|
|||
|
||||
def get_vm(self, server, **kwargs):
|
||||
try:
|
||||
return self._vm_list[server.id]
|
||||
server_id = server.id
|
||||
except AttributeError:
|
||||
return self._vm_list[server]
|
||||
server_id = server
|
||||
|
||||
try:
|
||||
return self._vm_list[server_id]
|
||||
except KeyError:
|
||||
raise nova_exc.NotFound(404)
|
||||
|
||||
def list_vms(self, retrieve_all=True, **_params):
|
||||
"""Mock'd version of novaclient...list_vms().
|
||||
|
|
|
@ -14,4 +14,6 @@
|
|||
# under the License.
|
||||
|
||||
from create_vm import CreateVm # noqa
|
||||
from delete_vm import DeleteVm # noqa
|
||||
from get_vm import GetVm # noqa
|
||||
from get_vm_status import GetVmStatus # noqa
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2015 Hewlett-Packard Development Company, L.P.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
import os_tasklib
|
||||
|
||||
from cue.common.i18n import _LW # noqa
|
||||
from cue.openstack.common import log as logging
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class GetVm(os_tasklib.BaseTask):
|
||||
"""GetVm Task
|
||||
|
||||
This task interfaces with Nova API and retrieves information about a VM
|
||||
|
||||
"""
|
||||
|
||||
def execute(self, server):
|
||||
"""main execute method
|
||||
|
||||
:param server: UUID of the VM to retrieve
|
||||
:type server: string
|
||||
:return: VM record provided by Nova
|
||||
:rtype: dict
|
||||
"""
|
||||
|
||||
vm_info = self.os_client.servers.get(server=server)
|
||||
return vm_info.to_dict()
|
Loading…
Reference in New Issue