Add support for volume types
* Depends on https://review.openstack.org/4600 Change-Id: I56eace59f774623a2cb878657b3b797420c48408
This commit is contained in:
parent
6d8e445b79
commit
30e1133203
@ -17,6 +17,7 @@ from novaclient.v1_1 import usage
|
||||
from novaclient.v1_1 import virtual_interfaces
|
||||
from novaclient.v1_1 import volumes
|
||||
from novaclient.v1_1 import volume_snapshots
|
||||
from novaclient.v1_1 import volume_types
|
||||
|
||||
|
||||
class Client(object):
|
||||
@ -57,6 +58,7 @@ class Client(object):
|
||||
self.floating_ip_pools = floating_ip_pools.FloatingIPPoolManager(self)
|
||||
self.volumes = volumes.VolumeManager(self)
|
||||
self.volume_snapshots = volume_snapshots.SnapshotManager(self)
|
||||
self.volume_types = volume_types.VolumeTypeManager(self)
|
||||
self.keypairs = keypairs.KeypairManager(self)
|
||||
self.quotas = quotas.QuotaSetManager(self)
|
||||
self.security_groups = security_groups.SecurityGroupManager(self)
|
||||
|
@ -723,7 +723,7 @@ def _print_volume_snapshot(cs, snapshot):
|
||||
|
||||
|
||||
def _translate_volume_keys(collection):
|
||||
convert = [('displayName', 'display_name')]
|
||||
convert = [('displayName', 'display_name'), ('volumeType', 'volume_type')]
|
||||
for item in collection:
|
||||
keys = item.__dict__.keys()
|
||||
for from_key, to_key in convert:
|
||||
@ -751,7 +751,7 @@ def do_volume_list(cs, args):
|
||||
servers = [server.get('serverId') for server in vol.attachments]
|
||||
setattr(vol, 'attached_to', ','.join(map(str, servers)))
|
||||
utils.print_list(volumes, ['ID', 'Status', 'Display Name',
|
||||
'Size', 'Attached to'])
|
||||
'Size', 'Volume Type', 'Attached to'])
|
||||
|
||||
|
||||
@utils.arg('volume', metavar='<volume>', help='ID of the volume.')
|
||||
@ -776,13 +776,18 @@ def do_volume_show(cs, args):
|
||||
@utils.arg('--display_description', metavar='<display_description>',
|
||||
help='Optional volume description. (Default=None)',
|
||||
default=None)
|
||||
@utils.arg('--volume_type',
|
||||
metavar='<volume_type>',
|
||||
help='Optional volume type. (Default=None)',
|
||||
default=None)
|
||||
@utils.service_type('volume')
|
||||
def do_volume_create(cs, args):
|
||||
"""Add a new volume."""
|
||||
cs.volumes.create(args.size,
|
||||
args.snapshot_id,
|
||||
args.display_name,
|
||||
args.display_description)
|
||||
args.display_description,
|
||||
args.volume_type)
|
||||
|
||||
|
||||
@utils.arg('volume', metavar='<volume>', help='ID of the volume to delete.')
|
||||
@ -873,6 +878,36 @@ def do_volume_snapshot_delete(cs, args):
|
||||
snapshot.delete()
|
||||
|
||||
|
||||
def _print_volume_type_list(vtypes):
|
||||
utils.print_list(vtypes, ['ID', 'Name'])
|
||||
|
||||
|
||||
@utils.service_type('volume')
|
||||
def do_volume_type_list(cs, args):
|
||||
"""Print a list of available 'volume types'."""
|
||||
vtypes = cs.volume_types.list()
|
||||
_print_volume_type_list(vtypes)
|
||||
|
||||
|
||||
@utils.arg('name',
|
||||
metavar='<name>',
|
||||
help="Name of the new flavor")
|
||||
@utils.service_type('volume')
|
||||
def do_volume_type_create(cs, args):
|
||||
"""Create a new volume type."""
|
||||
vtype = cs.volume_types.create(args.name)
|
||||
_print_volume_type_list([vtype])
|
||||
|
||||
|
||||
@utils.arg('id',
|
||||
metavar='<id>',
|
||||
help="Unique ID of the volume type to delete")
|
||||
@utils.service_type('volume')
|
||||
def do_volume_type_delete(cs, args):
|
||||
"""Delete a specific flavor"""
|
||||
cs.volume_types.delete(args.id)
|
||||
|
||||
|
||||
@utils.arg('server', metavar='<server>', help='Name or ID of server.')
|
||||
@utils.arg('console_type',
|
||||
metavar='<console_type>',
|
||||
|
77
novaclient/v1_1/volume_types.py
Normal file
77
novaclient/v1_1/volume_types.py
Normal file
@ -0,0 +1,77 @@
|
||||
# Copyright (c) 2011 Rackspace US, Inc.
|
||||
#
|
||||
# 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.
|
||||
|
||||
|
||||
"""
|
||||
Volume Type interface.
|
||||
"""
|
||||
|
||||
from novaclient import base
|
||||
|
||||
|
||||
class VolumeType(base.Resource):
|
||||
"""
|
||||
A Volume Type is the type of volume to be created
|
||||
"""
|
||||
def __repr__(self):
|
||||
return "<Volume Type: %s>" % self.name
|
||||
|
||||
|
||||
class VolumeTypeManager(base.ManagerWithFind):
|
||||
"""
|
||||
Manage :class:`VolumeType` resources.
|
||||
"""
|
||||
resource_class = VolumeType
|
||||
|
||||
def list(self):
|
||||
"""
|
||||
Get a list of all volume types.
|
||||
|
||||
:rtype: list of :class:`VolumeType`.
|
||||
"""
|
||||
return self._list("/types", "volume_types")
|
||||
|
||||
def get(self, volume_type):
|
||||
"""
|
||||
Get a specific volume type.
|
||||
|
||||
:param volume_type: The ID of the :class:`VolumeType` to get.
|
||||
:rtype: :class:`VolumeType`
|
||||
"""
|
||||
return self._get("/types/%s" % base.getid(volume_type), "volume_type")
|
||||
|
||||
def delete(self, volume_type):
|
||||
"""
|
||||
Delete a specific volume_type.
|
||||
|
||||
:param volume_type: The ID of the :class:`VolumeType` to get.
|
||||
"""
|
||||
self._delete("/types/%s" % base.getid(volume_type))
|
||||
|
||||
def create(self, name):
|
||||
"""
|
||||
Create a volume type.
|
||||
|
||||
:param name: Descriptive name of the volume type
|
||||
:rtype: :class:`VolumeType`
|
||||
"""
|
||||
|
||||
body = {
|
||||
"volume_type": {
|
||||
"name": name,
|
||||
}
|
||||
}
|
||||
|
||||
return self._create("/types", body, "volume_type")
|
@ -41,7 +41,8 @@ class VolumeManager(base.ManagerWithFind):
|
||||
resource_class = Volume
|
||||
|
||||
def create(self, size, snapshot_id=None,
|
||||
display_name=None, display_description=None):
|
||||
display_name=None, display_description=None,
|
||||
volume_type=None):
|
||||
"""
|
||||
Create a volume.
|
||||
|
||||
@ -49,12 +50,14 @@ class VolumeManager(base.ManagerWithFind):
|
||||
:param snapshot_id: ID of the snapshot
|
||||
:param display_name: Name of the volume
|
||||
:param display_description: Description of the volume
|
||||
:param volume_type: Type of volume
|
||||
:rtype: :class:`Volume`
|
||||
"""
|
||||
body = {'volume': {'size': size,
|
||||
'snapshot_id': snapshot_id,
|
||||
'display_name': display_name,
|
||||
'display_description': display_description}}
|
||||
'display_description': display_description,
|
||||
'volume_type': volume_type}}
|
||||
return self._create('/volumes', body, 'volume')
|
||||
|
||||
def get(self, volume_id):
|
||||
|
Loading…
Reference in New Issue
Block a user