Skip to content

Commit 7072b4f

Browse files
author
Steve Martinelli
committed
Add Cinder API V1 Support
made the changes suggested by dtroyer added client modified setup.py entry points updated pip required added support for create/delete/list volume types openstack list type openstack create type typeName openstack delete type typeNameOrId Change-Id: I43655de151582e37f14dc9550151a66db7a009ab
1 parent f432131 commit 7072b4f

8 files changed

Lines changed: 184 additions & 0 deletions

File tree

openstackclient/common/clientmanager.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from openstackclient.compute import client as compute_client
2121
from openstackclient.identity import client as identity_client
2222
from openstackclient.image import client as image_client
23+
from openstackclient.volume import client as volume_client
2324

2425

2526
LOG = logging.getLogger(__name__)
@@ -43,6 +44,7 @@ class ClientManager(object):
4344
compute = ClientCache(compute_client.make_client)
4445
identity = ClientCache(identity_client.make_client)
4546
image = ClientCache(image_client.make_client)
47+
volume = ClientCache(volume_client.make_client)
4648

4749
def __init__(self, token=None, url=None, auth_url=None, tenant_name=None,
4850
tenant_id=None, username=None, password=None,

openstackclient/shell.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
DEFAULT_COMPUTE_API_VERSION = '2'
3737
DEFAULT_IDENTITY_API_VERSION = '2.0'
3838
DEFAULT_IMAGE_API_VERSION = '1.0'
39+
DEFAULT_VOLUME_API_VERSION = '1'
3940

4041

4142
def env(*vars, **kwargs):
@@ -160,6 +161,15 @@ def build_option_parser(self, description, version):
160161
help='Image API version, default=' +
161162
DEFAULT_IMAGE_API_VERSION +
162163
' (Env: OS_IMAGE_API_VERSION)')
164+
parser.add_argument(
165+
'--os-volume-api-version',
166+
metavar='<volume-api-version>',
167+
default=env(
168+
'OS_VOLUME_API_VERSION',
169+
default=DEFAULT_VOLUME_API_VERSION),
170+
help='Volume API version, default=' +
171+
DEFAULT_VOLUME_API_VERSION +
172+
' (Env: OS_VOLUME_API_VERSION)')
163173
parser.add_argument(
164174
'--os-token',
165175
metavar='<token>',
@@ -293,6 +303,7 @@ def initialize_app(self, argv):
293303
'compute': self.options.os_compute_api_version,
294304
'identity': self.options.os_identity_api_version,
295305
'image': self.options.os_image_api_version,
306+
'volume': self.options.os_volume_api_version,
296307
}
297308

298309
# Add the API version-specific commands

openstackclient/volume/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright 2012-2013 OpenStack, LLC.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
4+
# not use this file except in compliance with the License. You may obtain
5+
# a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
# License for the specific language governing permissions and limitations
13+
# under the License.
14+
#

openstackclient/volume/client.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Copyright 2012-2013 OpenStack, LLC.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
4+
# not use this file except in compliance with the License. You may obtain
5+
# a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
# License for the specific language governing permissions and limitations
13+
# under the License.
14+
#
15+
16+
import logging
17+
18+
from openstackclient.common import utils
19+
20+
21+
LOG = logging.getLogger(__name__)
22+
23+
API_NAME = "volume"
24+
API_VERSIONS = {
25+
"1": "cinderclient.v1.client.Client"
26+
}
27+
28+
29+
def make_client(instance):
30+
"""Returns a volume service client."""
31+
volume_client = utils.get_client_class(
32+
API_NAME,
33+
instance._api_version[API_NAME],
34+
API_VERSIONS
35+
)
36+
37+
LOG.debug('instantiating volume client')
38+
client = volume_client(
39+
username=instance._username,
40+
api_key=instance._password,
41+
project_id=instance._tenant_name,
42+
auth_url=instance._auth_url,
43+
)
44+
45+
return client
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright 2012-2013 OpenStack, LLC.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
4+
# not use this file except in compliance with the License. You may obtain
5+
# a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
# License for the specific language governing permissions and limitations
13+
# under the License.
14+
#

openstackclient/volume/v1/type.py

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# Copyright 2012-2013 OpenStack, LLC.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
4+
# not use this file except in compliance with the License. You may obtain
5+
# a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
# License for the specific language governing permissions and limitations
13+
# under the License.
14+
#
15+
16+
"""Volume v1 Type action implementations"""
17+
18+
import logging
19+
20+
from cliff import command
21+
from cliff import lister
22+
from cliff import show
23+
24+
from openstackclient.common import utils
25+
26+
27+
class CreateType(show.ShowOne):
28+
"""Create type command"""
29+
30+
api = 'volume'
31+
log = logging.getLogger(__name__ + '.CreateType')
32+
33+
def get_parser(self, prog_name):
34+
parser = super(CreateType, self).get_parser(prog_name)
35+
parser.add_argument(
36+
'name',
37+
metavar='<name>',
38+
help='New type name',
39+
)
40+
return parser
41+
42+
def take_action(self, parsed_args):
43+
self.log.debug('take_action(%s)' % parsed_args)
44+
volume_client = self.app.client_manager.volume
45+
volume_type = volume_client.volume_types.create(
46+
parsed_args.name
47+
)
48+
49+
info = {}
50+
info.update(volume_type._info)
51+
return zip(*sorted(info.iteritems()))
52+
53+
54+
class DeleteType(command.Command):
55+
"""Delete type command"""
56+
57+
api = 'volume'
58+
log = logging.getLogger(__name__ + '.DeleteType')
59+
60+
def get_parser(self, prog_name):
61+
parser = super(DeleteType, self).get_parser(prog_name)
62+
parser.add_argument(
63+
'type',
64+
metavar='<type>',
65+
help='Name or ID of type to delete',
66+
)
67+
return parser
68+
69+
def take_action(self, parsed_args):
70+
self.log.debug('take_action(%s)' % parsed_args)
71+
volume_client = self.app.client_manager.volume
72+
volume_type = utils.find_resource(
73+
volume_client.volume_types, parsed_args.type)
74+
volume_client.volume_types.delete(volume_type.id)
75+
return
76+
77+
78+
class ListType(lister.Lister):
79+
"""List type command"""
80+
81+
api = 'volume'
82+
log = logging.getLogger(__name__ + '.ListType')
83+
84+
def take_action(self, parsed_args):
85+
self.log.debug('take_action(%s)' % parsed_args)
86+
columns = ('ID', 'Name')
87+
data = self.app.client_manager.volume.volume_types.list()
88+
return (columns,
89+
(utils.get_item_properties(
90+
s, columns,
91+
formatters={},
92+
) for s in data))

setup.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,5 +135,10 @@ def read(fname):
135135
'suspend_server=openstackclient.compute.v2.server:SuspendServer',
136136
'unpause_server=openstackclient.compute.v2.server:UnpauseServer',
137137
],
138+
'openstack.volume.v1': [
139+
'create_type=openstackclient.volume.v1.type:CreateType',
140+
'delete_type=openstackclient.volume.v1.type:DeleteType',
141+
'list_type=openstackclient.volume.v1.type:ListType',
142+
]
138143
}
139144
)

tools/pip-requires

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ pycrypto
44
python-glanceclient>=0.5.1
55
python-keystoneclient>=0.2,<1.0
66
python-novaclient>=2
7+
python-cinderclient>=1

0 commit comments

Comments
 (0)