Add volume connector support to Python API
This adds support for volume_connector, which is required to boot instances from volumes. This will expose new Python API to operate volume connectors: - client.volume_connector.create - client.volume_connector.list - client.volume_connector.get - client.volume_connector.update - client.volume_connector.delete - client.node.list_volume_connectors Co-Authored-By: Satoru Moriya <satoru.moriya.br@hitachi.com> Co-Authored-By: Stephane Miller <stephane@alum.mit.edu> Co-Authored-By: Hironori Shiina <shiina.hironori@jp.fujitsu.com> Depends-On: I328a698f2109841e1e122e17fea4b345c4179161 Change-Id: I485595b081b2c1c9f9bdf55382d06dd275784fad Partial-Bug: 1526231
This commit is contained in:
parent
df74135eff
commit
8f0c442c2e
@ -215,7 +215,7 @@ def common_params_for_list(args, fields, field_labels):
|
||||
|
||||
|
||||
def common_filters(marker=None, limit=None, sort_key=None, sort_dir=None,
|
||||
fields=None):
|
||||
fields=None, detail=False):
|
||||
"""Generate common filters for any list request.
|
||||
|
||||
:param marker: entity ID from which to start returning entities.
|
||||
@ -224,6 +224,9 @@ def common_filters(marker=None, limit=None, sort_key=None, sort_dir=None,
|
||||
:param sort_dir: direction of sorting: 'asc' or 'desc'.
|
||||
:param fields: a list with a specified set of fields of the resource
|
||||
to be returned.
|
||||
:param detail: Boolean, True to return detailed information. This parameter
|
||||
can be used for resources which accept 'detail' as a URL
|
||||
parameter.
|
||||
:returns: list of string filters.
|
||||
"""
|
||||
filters = []
|
||||
@ -237,6 +240,8 @@ def common_filters(marker=None, limit=None, sort_key=None, sort_dir=None,
|
||||
filters.append('sort_dir=%s' % sort_dir)
|
||||
if fields is not None:
|
||||
filters.append('fields=%s' % ','.join(fields))
|
||||
if detail:
|
||||
filters.append('detail=True')
|
||||
return filters
|
||||
|
||||
|
||||
|
@ -25,6 +25,7 @@ from ironicclient.common import utils as common_utils
|
||||
from ironicclient import exc
|
||||
from ironicclient.tests.unit import utils
|
||||
from ironicclient.v1 import node
|
||||
from ironicclient.v1 import volume_connector
|
||||
|
||||
if six.PY3:
|
||||
import io
|
||||
@ -58,6 +59,11 @@ PORTGROUP = {'uuid': '11111111-2222-3333-4444-555555555555',
|
||||
'node_uuid': '66666666-7777-8888-9999-000000000000',
|
||||
'address': 'AA:BB:CC:DD:EE:FF',
|
||||
'extra': {}}
|
||||
CONNECTOR = {'uuid': 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee',
|
||||
'node_uuid': 'bbbbbbbb-cccc-dddd-eeee-ffffffffffff',
|
||||
'type': 'iqn',
|
||||
'connector_id': 'iqn.2010-10.org.openstack:test',
|
||||
'extra': {}}
|
||||
|
||||
POWER_STATE = {'power_state': 'power on',
|
||||
'target_power_state': 'power off'}
|
||||
@ -290,6 +296,27 @@ fake_responses = {
|
||||
{"portgroups": [PORTGROUP]},
|
||||
),
|
||||
},
|
||||
'/v1/nodes/%s/volume/connectors' % NODE1['uuid']:
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{"connectors": [CONNECTOR]},
|
||||
),
|
||||
},
|
||||
'/v1/nodes/%s/volume/connectors?detail=True' % NODE1['uuid']:
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{"connectors": [CONNECTOR]},
|
||||
),
|
||||
},
|
||||
'/v1/nodes/%s/volume/connectors?fields=uuid,connector_id' % NODE1['uuid']:
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{"connectors": [CONNECTOR]},
|
||||
),
|
||||
},
|
||||
'/v1/nodes/%s/maintenance' % NODE1['uuid']:
|
||||
{
|
||||
'PUT': (
|
||||
@ -446,6 +473,21 @@ fake_responses_pagination = {
|
||||
{"portgroups": [PORTGROUP]},
|
||||
),
|
||||
},
|
||||
'/v1/nodes/%s/volume/connectors?limit=1' % NODE1['uuid']:
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{"connectors": [CONNECTOR]},
|
||||
),
|
||||
},
|
||||
'/v1/nodes/%s/volume/connectors?marker=%s' % (NODE1['uuid'],
|
||||
CONNECTOR['uuid']):
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{"connectors": [CONNECTOR]},
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
fake_responses_sorting = {
|
||||
@ -491,6 +533,20 @@ fake_responses_sorting = {
|
||||
{"portgroups": [PORTGROUP]},
|
||||
),
|
||||
},
|
||||
'/v1/nodes/%s/volume/connectors?sort_key=updated_at' % NODE1['uuid']:
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{"connectors": [CONNECTOR]},
|
||||
),
|
||||
},
|
||||
'/v1/nodes/%s/volume/connectors?sort_dir=desc' % NODE1['uuid']:
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{"connectors": [CONNECTOR]},
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@ -856,6 +912,92 @@ class NodeManagerTest(testtools.TestCase):
|
||||
self.assertRaises(exc.InvalidAttribute, self.mgr.list_ports,
|
||||
NODE1['uuid'], detail=True, fields=['uuid', 'extra'])
|
||||
|
||||
def _validate_node_volume_connector_list(self, expect, volume_connectors):
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertEqual(1, len(volume_connectors))
|
||||
self.assertIsInstance(volume_connectors[0],
|
||||
volume_connector.VolumeConnector)
|
||||
self.assertEqual(CONNECTOR['uuid'], volume_connectors[0].uuid)
|
||||
self.assertEqual(CONNECTOR['type'], volume_connectors[0].type)
|
||||
self.assertEqual(CONNECTOR['connector_id'],
|
||||
volume_connectors[0].connector_id)
|
||||
|
||||
def test_node_volume_connector_list(self):
|
||||
volume_connectors = self.mgr.list_volume_connectors(NODE1['uuid'])
|
||||
expect = [
|
||||
('GET', '/v1/nodes/%s/volume/connectors' % NODE1['uuid'],
|
||||
{}, None),
|
||||
]
|
||||
self._validate_node_volume_connector_list(expect, volume_connectors)
|
||||
|
||||
def test_node_volume_connector_list_limit(self):
|
||||
self.api = utils.FakeAPI(fake_responses_pagination)
|
||||
self.mgr = node.NodeManager(self.api)
|
||||
volume_connectors = self.mgr.list_volume_connectors(NODE1['uuid'],
|
||||
limit=1)
|
||||
expect = [
|
||||
('GET', '/v1/nodes/%s/volume/connectors?limit=1' % NODE1['uuid'],
|
||||
{}, None),
|
||||
]
|
||||
self._validate_node_volume_connector_list(expect, volume_connectors)
|
||||
|
||||
def test_node_volume_connector_list_marker(self):
|
||||
self.api = utils.FakeAPI(fake_responses_pagination)
|
||||
self.mgr = node.NodeManager(self.api)
|
||||
volume_connectors = self.mgr.list_volume_connectors(
|
||||
NODE1['uuid'], marker=CONNECTOR['uuid'])
|
||||
expect = [
|
||||
('GET', '/v1/nodes/%s/volume/connectors?marker=%s' % (
|
||||
NODE1['uuid'], CONNECTOR['uuid']), {}, None),
|
||||
]
|
||||
self._validate_node_volume_connector_list(expect, volume_connectors)
|
||||
|
||||
def test_node_volume_connector_list_sort_key(self):
|
||||
self.api = utils.FakeAPI(fake_responses_sorting)
|
||||
self.mgr = node.NodeManager(self.api)
|
||||
volume_connectors = self.mgr.list_volume_connectors(
|
||||
NODE1['uuid'], sort_key='updated_at')
|
||||
expect = [
|
||||
('GET', '/v1/nodes/%s/volume/connectors?sort_key=updated_at' %
|
||||
NODE1['uuid'], {}, None),
|
||||
]
|
||||
self._validate_node_volume_connector_list(expect, volume_connectors)
|
||||
|
||||
def test_node_volume_connector_list_sort_dir(self):
|
||||
self.api = utils.FakeAPI(fake_responses_sorting)
|
||||
self.mgr = node.NodeManager(self.api)
|
||||
volume_connectors = self.mgr.list_volume_connectors(NODE1['uuid'],
|
||||
sort_dir='desc')
|
||||
expect = [
|
||||
('GET', '/v1/nodes/%s/volume/connectors?sort_dir=desc' %
|
||||
NODE1['uuid'], {}, None),
|
||||
]
|
||||
self._validate_node_volume_connector_list(expect, volume_connectors)
|
||||
|
||||
def test_node_volume_connector_list_detail(self):
|
||||
volume_connectors = self.mgr.list_volume_connectors(NODE1['uuid'],
|
||||
detail=True)
|
||||
expect = [
|
||||
('GET',
|
||||
'/v1/nodes/%s/volume/connectors?detail=True' % NODE1['uuid'],
|
||||
{}, None),
|
||||
]
|
||||
self._validate_node_volume_connector_list(expect, volume_connectors)
|
||||
|
||||
def test_node_volume_connector_list_fields(self):
|
||||
volume_connectors = self.mgr.list_volume_connectors(
|
||||
NODE1['uuid'], fields=['uuid', 'connector_id'])
|
||||
expect = [
|
||||
('GET', '/v1/nodes/%s/volume/connectors?fields=uuid,connector_id' %
|
||||
NODE1['uuid'], {}, None),
|
||||
]
|
||||
self._validate_node_volume_connector_list(expect, volume_connectors)
|
||||
|
||||
def test_node_volume_connector_list_detail_and_fields_fail(self):
|
||||
self.assertRaises(exc.InvalidAttribute,
|
||||
self.mgr.list_volume_connectors,
|
||||
NODE1['uuid'], detail=True, fields=['uuid', 'extra'])
|
||||
|
||||
def test_node_set_maintenance_true(self):
|
||||
maintenance = self.mgr.set_maintenance(NODE1['uuid'], 'true',
|
||||
maint_reason='reason')
|
||||
|
334
ironicclient/tests/unit/v1/test_volume_connector.py
Normal file
334
ironicclient/tests/unit/v1/test_volume_connector.py
Normal file
@ -0,0 +1,334 @@
|
||||
# Copyright 2015 Hitachi Data Systems
|
||||
#
|
||||
# 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 copy
|
||||
|
||||
import testtools
|
||||
|
||||
from ironicclient import exc
|
||||
from ironicclient.tests.unit import utils
|
||||
import ironicclient.v1.port
|
||||
|
||||
NODE_UUID = '55555555-4444-3333-2222-111111111111'
|
||||
CONNECTOR1 = {'uuid': '11111111-2222-3333-4444-555555555555',
|
||||
'node_uuid': NODE_UUID,
|
||||
'type': 'iqn',
|
||||
'connector_id': 'iqn.2010-10.org.openstack:test',
|
||||
'extra': {}}
|
||||
|
||||
CONNECTOR2 = {'uuid': '66666666-7777-8888-9999-000000000000',
|
||||
'node_uuid': NODE_UUID,
|
||||
'type': 'wwpn',
|
||||
'connector_id': '1234567890543216',
|
||||
'extra': {}}
|
||||
|
||||
CREATE_CONNECTOR = copy.deepcopy(CONNECTOR1)
|
||||
del CREATE_CONNECTOR['uuid']
|
||||
|
||||
CREATE_CONNECTOR_WITH_UUID = copy.deepcopy(CONNECTOR1)
|
||||
|
||||
UPDATED_CONNECTOR = copy.deepcopy(CONNECTOR1)
|
||||
NEW_CONNECTOR_ID = '1234567890123456'
|
||||
UPDATED_CONNECTOR['connector_id'] = NEW_CONNECTOR_ID
|
||||
|
||||
fake_responses = {
|
||||
'/v1/volume/connectors':
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{"connectors": [CONNECTOR1]},
|
||||
),
|
||||
'POST': (
|
||||
{},
|
||||
CONNECTOR1,
|
||||
),
|
||||
},
|
||||
'/v1/volume/connectors/?detail=True':
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{"connectors": [CONNECTOR1]},
|
||||
),
|
||||
},
|
||||
'/v1/volume/connectors/?fields=uuid,connector_id':
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{"connectors": [CONNECTOR1]},
|
||||
),
|
||||
},
|
||||
'/v1/volume/connectors/%s' % CONNECTOR1['uuid']:
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
CONNECTOR1,
|
||||
),
|
||||
'DELETE': (
|
||||
{},
|
||||
None,
|
||||
),
|
||||
'PATCH': (
|
||||
{},
|
||||
UPDATED_CONNECTOR,
|
||||
),
|
||||
},
|
||||
'/v1/volume/connectors/%s?fields=uuid,connector_id' % CONNECTOR1['uuid']:
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
CONNECTOR1,
|
||||
),
|
||||
},
|
||||
'/v1/volume/connectors/?detail=True&node=%s' % NODE_UUID:
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{"connectors": [CONNECTOR1]},
|
||||
),
|
||||
},
|
||||
'/v1/volume/connectors/?node=%s' % NODE_UUID:
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{"connectors": [CONNECTOR1]},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
fake_responses_pagination = {
|
||||
'/v1/volume/connectors':
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{"connectors": [CONNECTOR1],
|
||||
"next": "http://127.0.0.1:6385/v1/volume/connectors/?limit=1"}
|
||||
),
|
||||
},
|
||||
'/v1/volume/connectors/?limit=1':
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{"connectors": [CONNECTOR2]}
|
||||
),
|
||||
},
|
||||
'/v1/volume/connectors/?marker=%s' % CONNECTOR1['uuid']:
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{"connectors": [CONNECTOR2]}
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
fake_responses_sorting = {
|
||||
'/v1/volume/connectors/?sort_key=updated_at':
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{"connectors": [CONNECTOR2, CONNECTOR1]}
|
||||
),
|
||||
},
|
||||
'/v1/volume/connectors/?sort_dir=desc':
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{"connectors": [CONNECTOR2, CONNECTOR1]}
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
class VolumeConnectorManagerTest(testtools.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(VolumeConnectorManagerTest, self).setUp()
|
||||
self.api = utils.FakeAPI(fake_responses)
|
||||
self.mgr = ironicclient.v1.volume_connector.VolumeConnectorManager(
|
||||
self.api)
|
||||
|
||||
def _validate_obj(self, expect, obj):
|
||||
self.assertEqual(expect['uuid'], obj.uuid)
|
||||
self.assertEqual(expect['type'], obj.type)
|
||||
self.assertEqual(expect['connector_id'], obj.connector_id)
|
||||
self.assertEqual(expect['node_uuid'], obj.node_uuid)
|
||||
|
||||
def _validate_list(self, expect_request,
|
||||
expect_connectors, actual_connectors):
|
||||
self.assertEqual(expect_request, self.api.calls)
|
||||
self.assertEqual(len(expect_connectors), len(actual_connectors))
|
||||
for expect, obj in zip(expect_connectors, actual_connectors):
|
||||
self._validate_obj(expect, obj)
|
||||
|
||||
def test_volume_connectors_list(self):
|
||||
volume_connectors = self.mgr.list()
|
||||
expect = [
|
||||
('GET', '/v1/volume/connectors', {}, None),
|
||||
]
|
||||
expect_connectors = [CONNECTOR1]
|
||||
self._validate_list(expect, expect_connectors, volume_connectors)
|
||||
|
||||
def test_volume_connectors_list_by_node(self):
|
||||
volume_connectors = self.mgr.list(node=NODE_UUID)
|
||||
expect = [
|
||||
('GET', '/v1/volume/connectors/?node=%s' % NODE_UUID, {}, None),
|
||||
]
|
||||
expect_connectors = [CONNECTOR1]
|
||||
self._validate_list(expect, expect_connectors, volume_connectors)
|
||||
|
||||
def test_volume_connectors_list_by_node_detail(self):
|
||||
volume_connectors = self.mgr.list(node=NODE_UUID, detail=True)
|
||||
expect = [
|
||||
('GET', '/v1/volume/connectors/?detail=True&node=%s' % NODE_UUID,
|
||||
{}, None),
|
||||
]
|
||||
expect_connectors = [CONNECTOR1]
|
||||
self._validate_list(expect, expect_connectors, volume_connectors)
|
||||
|
||||
def test_volume_connectors_list_detail(self):
|
||||
volume_connectors = self.mgr.list(detail=True)
|
||||
expect = [
|
||||
('GET', '/v1/volume/connectors/?detail=True', {}, None),
|
||||
]
|
||||
expect_connectors = [CONNECTOR1]
|
||||
self._validate_list(expect, expect_connectors, volume_connectors)
|
||||
|
||||
def test_volume_connector_list_fields(self):
|
||||
volume_connectors = self.mgr.list(fields=['uuid', 'connector_id'])
|
||||
expect = [
|
||||
('GET',
|
||||
'/v1/volume/connectors/?fields=uuid,connector_id',
|
||||
{},
|
||||
None),
|
||||
]
|
||||
expect_connectors = [CONNECTOR1]
|
||||
self._validate_list(expect, expect_connectors, volume_connectors)
|
||||
|
||||
def test_volume_connector_list_detail_and_fields_fail(self):
|
||||
self.assertRaises(exc.InvalidAttribute, self.mgr.list,
|
||||
detail=True, fields=['uuid', 'connector_id'])
|
||||
|
||||
def test_volume_connectors_list_limit(self):
|
||||
self.api = utils.FakeAPI(fake_responses_pagination)
|
||||
self.mgr = ironicclient.v1.volume_connector.VolumeConnectorManager(
|
||||
self.api)
|
||||
volume_connectors = self.mgr.list(limit=1)
|
||||
expect = [
|
||||
('GET', '/v1/volume/connectors/?limit=1', {}, None),
|
||||
]
|
||||
expect_connectors = [CONNECTOR2]
|
||||
self._validate_list(expect, expect_connectors, volume_connectors)
|
||||
|
||||
def test_volume_connectors_list_marker(self):
|
||||
self.api = utils.FakeAPI(fake_responses_pagination)
|
||||
self.mgr = ironicclient.v1.volume_connector.VolumeConnectorManager(
|
||||
self.api)
|
||||
volume_connectors = self.mgr.list(marker=CONNECTOR1['uuid'])
|
||||
expect = [
|
||||
('GET', '/v1/volume/connectors/?marker=%s' % CONNECTOR1['uuid'],
|
||||
{}, None),
|
||||
]
|
||||
expect_connectors = [CONNECTOR2]
|
||||
self._validate_list(expect, expect_connectors, volume_connectors)
|
||||
|
||||
def test_volume_connectors_list_pagination_no_limit(self):
|
||||
self.api = utils.FakeAPI(fake_responses_pagination)
|
||||
self.mgr = ironicclient.v1.volume_connector.VolumeConnectorManager(
|
||||
self.api)
|
||||
volume_connectors = self.mgr.list(limit=0)
|
||||
expect = [
|
||||
('GET', '/v1/volume/connectors', {}, None),
|
||||
('GET', '/v1/volume/connectors/?limit=1', {}, None)
|
||||
]
|
||||
expect_connectors = [CONNECTOR1, CONNECTOR2]
|
||||
self._validate_list(expect, expect_connectors, volume_connectors)
|
||||
|
||||
def test_volume_connectors_list_sort_key(self):
|
||||
self.api = utils.FakeAPI(fake_responses_sorting)
|
||||
self.mgr = ironicclient.v1.volume_connector.VolumeConnectorManager(
|
||||
self.api)
|
||||
volume_connectors = self.mgr.list(sort_key='updated_at')
|
||||
expect = [
|
||||
('GET', '/v1/volume/connectors/?sort_key=updated_at', {}, None)
|
||||
]
|
||||
expect_connectors = [CONNECTOR2, CONNECTOR1]
|
||||
self._validate_list(expect, expect_connectors, volume_connectors)
|
||||
|
||||
def test_volume_connectors_list_sort_dir(self):
|
||||
self.api = utils.FakeAPI(fake_responses_sorting)
|
||||
self.mgr = ironicclient.v1.volume_connector.VolumeConnectorManager(
|
||||
self.api)
|
||||
volume_connectors = self.mgr.list(sort_dir='desc')
|
||||
expect = [
|
||||
('GET', '/v1/volume/connectors/?sort_dir=desc', {}, None)
|
||||
]
|
||||
expect_connectors = [CONNECTOR2, CONNECTOR1]
|
||||
self._validate_list(expect, expect_connectors, volume_connectors)
|
||||
|
||||
def test_volume_connectors_show(self):
|
||||
volume_connector = self.mgr.get(CONNECTOR1['uuid'])
|
||||
expect = [
|
||||
('GET', '/v1/volume/connectors/%s' % CONNECTOR1['uuid'], {}, None),
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self._validate_obj(CONNECTOR1, volume_connector)
|
||||
|
||||
def test_volume_connector_show_fields(self):
|
||||
volume_connector = self.mgr.get(CONNECTOR1['uuid'],
|
||||
fields=['uuid', 'connector_id'])
|
||||
expect = [
|
||||
('GET', '/v1/volume/connectors/%s?fields=uuid,connector_id' %
|
||||
CONNECTOR1['uuid'], {}, None),
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertEqual(CONNECTOR1['uuid'], volume_connector.uuid)
|
||||
self.assertEqual(CONNECTOR1['connector_id'],
|
||||
volume_connector.connector_id)
|
||||
|
||||
def test_create(self):
|
||||
volume_connector = self.mgr.create(**CREATE_CONNECTOR)
|
||||
expect = [
|
||||
('POST', '/v1/volume/connectors', {}, CREATE_CONNECTOR),
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self._validate_obj(CONNECTOR1, volume_connector)
|
||||
|
||||
def test_create_with_uuid(self):
|
||||
volume_connector = self.mgr.create(**CREATE_CONNECTOR_WITH_UUID)
|
||||
expect = [
|
||||
('POST', '/v1/volume/connectors', {}, CREATE_CONNECTOR_WITH_UUID),
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self._validate_obj(CREATE_CONNECTOR_WITH_UUID, volume_connector)
|
||||
|
||||
def test_delete(self):
|
||||
volume_connector = self.mgr.delete(CONNECTOR1['uuid'])
|
||||
expect = [
|
||||
('DELETE', '/v1/volume/connectors/%s' % CONNECTOR1['uuid'],
|
||||
{}, None),
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertIsNone(volume_connector)
|
||||
|
||||
def test_update(self):
|
||||
patch = {'op': 'replace',
|
||||
'connector_id': NEW_CONNECTOR_ID,
|
||||
'path': '/connector_id'}
|
||||
volume_connector = self.mgr.update(
|
||||
volume_connector_id=CONNECTOR1['uuid'], patch=patch)
|
||||
expect = [
|
||||
('PATCH', '/v1/volume/connectors/%s' % CONNECTOR1['uuid'],
|
||||
{}, patch),
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self._validate_obj(UPDATED_CONNECTOR, volume_connector)
|
@ -23,6 +23,7 @@ from ironicclient.v1 import driver
|
||||
from ironicclient.v1 import node
|
||||
from ironicclient.v1 import port
|
||||
from ironicclient.v1 import portgroup
|
||||
from ironicclient.v1 import volume_connector
|
||||
|
||||
|
||||
class Client(object):
|
||||
@ -62,5 +63,7 @@ class Client(object):
|
||||
self.chassis = chassis.ChassisManager(self.http_client)
|
||||
self.node = node.NodeManager(self.http_client)
|
||||
self.port = port.PortManager(self.http_client)
|
||||
self.volume_connector = volume_connector.VolumeConnectorManager(
|
||||
self.http_client)
|
||||
self.driver = driver.DriverManager(self.http_client)
|
||||
self.portgroup = portgroup.PortgroupManager(self.http_client)
|
||||
|
@ -22,7 +22,7 @@ from ironicclient.common import base
|
||||
from ironicclient.common.i18n import _
|
||||
from ironicclient.common import utils
|
||||
from ironicclient import exc
|
||||
|
||||
from ironicclient.v1 import volume_connector
|
||||
|
||||
_power_states = {
|
||||
'on': 'power on',
|
||||
@ -195,6 +195,62 @@ class NodeManager(base.CreateManager):
|
||||
return self._list_pagination(self._path(path), "ports",
|
||||
limit=limit)
|
||||
|
||||
def list_volume_connectors(self, node_id, marker=None, limit=None,
|
||||
sort_key=None, sort_dir=None, detail=False,
|
||||
fields=None):
|
||||
"""List all the volume connectors for a given node.
|
||||
|
||||
:param node_id: Name or UUID of the node.
|
||||
:param marker: Optional, the UUID of a volume connector, eg the last
|
||||
volume connector from a previous result set. Return
|
||||
the next result set.
|
||||
:param limit: The maximum number of results to return per
|
||||
request, if:
|
||||
|
||||
1) limit > 0, the maximum number of volume connectors to return.
|
||||
2) limit == 0, return the entire list of volume connectors.
|
||||
3) limit param is NOT specified (None), the number of items
|
||||
returned respect the maximum imposed by the Ironic API
|
||||
(see Ironic's api.max_limit option).
|
||||
|
||||
:param sort_key: Optional, field used for sorting.
|
||||
|
||||
:param sort_dir: Optional, direction of sorting, either 'asc' (the
|
||||
default) or 'desc'.
|
||||
|
||||
:param detail: Optional, boolean whether to return detailed information
|
||||
about volume connectors.
|
||||
|
||||
:param fields: Optional, a list with a specified set of fields
|
||||
of the resource to be returned. Can not be used
|
||||
when 'detail' is set.
|
||||
|
||||
:returns: A list of volume connectors.
|
||||
|
||||
"""
|
||||
if limit is not None:
|
||||
limit = int(limit)
|
||||
|
||||
if detail and fields:
|
||||
raise exc.InvalidAttribute(_("Can't fetch a subset of fields "
|
||||
"with 'detail' set"))
|
||||
|
||||
filters = utils.common_filters(marker=marker, limit=limit,
|
||||
sort_key=sort_key, sort_dir=sort_dir,
|
||||
fields=fields, detail=detail)
|
||||
|
||||
path = "%s/volume/connectors" % node_id
|
||||
if filters:
|
||||
path += '?' + '&'.join(filters)
|
||||
|
||||
if limit is None:
|
||||
return self._list(self._path(path), response_key="connectors",
|
||||
obj_class=volume_connector.VolumeConnector)
|
||||
else:
|
||||
return self._list_pagination(
|
||||
self._path(path), response_key="connectors", limit=limit,
|
||||
obj_class=volume_connector.VolumeConnector)
|
||||
|
||||
def get(self, node_id, fields=None):
|
||||
return self._get(resource_id=node_id, fields=fields)
|
||||
|
||||
|
95
ironicclient/v1/volume_connector.py
Normal file
95
ironicclient/v1/volume_connector.py
Normal file
@ -0,0 +1,95 @@
|
||||
# Copyright 2015 Hitachi Data Systems
|
||||
#
|
||||
# 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.
|
||||
|
||||
from ironicclient.common import base
|
||||
from ironicclient.common.i18n import _
|
||||
from ironicclient.common import utils
|
||||
from ironicclient import exc
|
||||
|
||||
|
||||
class VolumeConnector(base.Resource):
|
||||
def __repr__(self):
|
||||
return "<VolumeConnector %s>" % self._info
|
||||
|
||||
|
||||
class VolumeConnectorManager(base.CreateManager):
|
||||
resource_class = VolumeConnector
|
||||
_creation_attributes = ['extra', 'node_uuid', 'type', 'connector_id',
|
||||
'uuid']
|
||||
_resource_name = 'volume/connectors'
|
||||
|
||||
def list(self, node=None, limit=None, marker=None, sort_key=None,
|
||||
sort_dir=None, detail=False, fields=None):
|
||||
"""Retrieve a list of volume connector.
|
||||
|
||||
:param node: Optional, UUID or name of a node, to get volume
|
||||
connectors for this node only.
|
||||
:param marker: Optional, the UUID of a volume connector, eg the last
|
||||
volume connector from a previous result set. Return
|
||||
the next result set.
|
||||
:param limit: The maximum number of results to return per
|
||||
request, if:
|
||||
|
||||
1) limit > 0, the maximum number of volume connectors to return.
|
||||
2) limit == 0, return the entire list of volume connectors.
|
||||
3) limit param is NOT specified (None), the number of items
|
||||
returned respect the maximum imposed by the Ironic API
|
||||
(see Ironic's api.max_limit option).
|
||||
|
||||
:param sort_key: Optional, field used for sorting.
|
||||
|
||||
:param sort_dir: Optional, direction of sorting, either 'asc' (the
|
||||
default) or 'desc'.
|
||||
|
||||
:param detail: Optional, boolean whether to return detailed information
|
||||
about volume connectors.
|
||||
|
||||
:param fields: Optional, a list with a specified set of fields
|
||||
of the resource to be returned. Can not be used
|
||||
when 'detail' is set.
|
||||
|
||||
:returns: A list of volume connectors.
|
||||
|
||||
"""
|
||||
if limit is not None:
|
||||
limit = int(limit)
|
||||
|
||||
if detail and fields:
|
||||
raise exc.InvalidAttribute(_("Can't fetch a subset of fields "
|
||||
"with 'detail' set"))
|
||||
|
||||
filters = utils.common_filters(marker=marker, limit=limit,
|
||||
sort_key=sort_key, sort_dir=sort_dir,
|
||||
fields=fields, detail=detail)
|
||||
if node is not None:
|
||||
filters.append('node=%s' % node)
|
||||
|
||||
path = ''
|
||||
if filters:
|
||||
path += '?' + '&'.join(filters)
|
||||
|
||||
if limit is None:
|
||||
return self._list(self._path(path), "connectors")
|
||||
else:
|
||||
return self._list_pagination(self._path(path), "connectors",
|
||||
limit=limit)
|
||||
|
||||
def get(self, volume_connector_id, fields=None):
|
||||
return self._get(resource_id=volume_connector_id, fields=fields)
|
||||
|
||||
def delete(self, volume_connector_id):
|
||||
return self._delete(resource_id=volume_connector_id)
|
||||
|
||||
def update(self, volume_connector_id, patch):
|
||||
return self._update(resource_id=volume_connector_id, patch=patch)
|
@ -0,0 +1,13 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Adds these python API client methods to support volume connector resources
|
||||
(available starting with API version 1.32):
|
||||
|
||||
* ``client.volume_connector.create`` for creating a volume connector
|
||||
* ``client.volume_connector.list`` for listing volume connectors
|
||||
* ``client.volume_connector.get`` for getting a volume connector
|
||||
* ``client.volume_connector.update`` for updating a volume connector
|
||||
* ``client.volume_connector.delete`` for deleting a volume connector
|
||||
* ``client.node.list_volume_connectors`` for getting volume connectors
|
||||
associated with a node
|
Loading…
x
Reference in New Issue
Block a user