2424from openstackclient .common import utils
2525
2626
27- class CreateType (show .ShowOne ):
28- """Create type command"""
27+ class CreateVolumeType (show .ShowOne ):
28+ """Create volume type command"""
2929
3030 api = 'volume'
31- log = logging .getLogger (__name__ + '.CreateType ' )
31+ log = logging .getLogger (__name__ + '.CreateVolumeType ' )
3232
3333 def get_parser (self , prog_name ):
34- parser = super (CreateType , self ).get_parser (prog_name )
34+ parser = super (CreateVolumeType , self ).get_parser (prog_name )
3535 parser .add_argument (
3636 'name' ,
3737 metavar = '<name>' ,
38- help = 'New type name' ,
38+ help = 'New volume type name' ,
3939 )
4040 return parser
4141
@@ -51,59 +51,71 @@ def take_action(self, parsed_args):
5151 return zip (* sorted (info .iteritems ()))
5252
5353
54- class DeleteType (command .Command ):
55- """Delete type command"""
54+ class DeleteVolumeType (command .Command ):
55+ """Delete volume type command"""
5656
5757 api = 'volume'
58- log = logging .getLogger (__name__ + '.DeleteType ' )
58+ log = logging .getLogger (__name__ + '.DeleteVolumeType ' )
5959
6060 def get_parser (self , prog_name ):
61- parser = super (DeleteType , self ).get_parser (prog_name )
61+ parser = super (DeleteVolumeType , self ).get_parser (prog_name )
6262 parser .add_argument (
63- 'type ' ,
64- metavar = '<type>' ,
65- help = 'Name or ID of type to delete' ,
63+ 'volume_type ' ,
64+ metavar = '<volume- type>' ,
65+ help = 'Name or ID of volume type to delete' ,
6666 )
6767 return parser
6868
6969 def take_action (self , parsed_args ):
7070 self .log .debug ('take_action(%s)' % parsed_args )
7171 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 )
72+ volume_type_id = utils .find_resource (
73+ volume_client .volume_types , parsed_args .volume_type ). id
74+ volume_client .volume_types .delete (volume_type_id )
7575 return
7676
7777
78- class ListType (lister .Lister ):
79- """List type command"""
78+ class ListVolumeType (lister .Lister ):
79+ """List volume type command"""
8080
8181 api = 'volume'
82- log = logging .getLogger (__name__ + '.ListType' )
82+ log = logging .getLogger (__name__ + '.ListVolumeType' )
83+
84+ def get_parser (self , prog_name ):
85+ parser = super (ListVolumeType , self ).get_parser (prog_name )
86+ parser .add_argument (
87+ '--long' ,
88+ action = 'store_true' ,
89+ default = False ,
90+ help = 'Additional fields are listed in output' )
91+ return parser
8392
8493 def take_action (self , parsed_args ):
8594 self .log .debug ('take_action(%s)' % parsed_args )
86- columns = ('ID' , 'Name' )
95+ if parsed_args .long :
96+ columns = ('ID' , 'Name' , 'Extra Specs' )
97+ else :
98+ columns = ('ID' , 'Name' )
8799 data = self .app .client_manager .volume .volume_types .list ()
88100 return (columns ,
89101 (utils .get_item_properties (
90102 s , columns ,
91- formatters = {},
103+ formatters = {'Extra Specs' : _format_type_list_extra_specs },
92104 ) for s in data ))
93105
94106
95- class SetType (command .Command ):
96- """Set type command"""
107+ class SetVolumeType (command .Command ):
108+ """Set volume type command"""
97109
98110 api = 'volume'
99- log = logging .getLogger (__name__ + '.SetType ' )
111+ log = logging .getLogger (__name__ + '.SetVolumeType ' )
100112
101113 def get_parser (self , prog_name ):
102- parser = super (SetType , self ).get_parser (prog_name )
114+ parser = super (SetVolumeType , self ).get_parser (prog_name )
103115 parser .add_argument (
104- 'type ' ,
105- metavar = '<type>' ,
106- help = 'Type ID to update' ,
116+ 'volume_type ' ,
117+ metavar = '<volume- type>' ,
118+ help = 'Volume type name or ID to update' ,
107119 )
108120 parser .add_argument (
109121 'meta_data' ,
@@ -117,27 +129,26 @@ def take_action(self, parsed_args):
117129
118130 meta = dict (v .split ('=' ) for v in parsed_args .meta_data .split (' ' ))
119131 volume_client = self .app .client_manager .volume
120- volume_type = volume_client .volume_types .get (
121- parsed_args .type
122- )
132+ volume_type = utils .find_resource (
133+ volume_client .volume_types , parsed_args .volume_type )
123134
124135 volume_type .set_keys (meta )
125136
126137 return
127138
128139
129- class UnsetType (command .Command ):
130- """Unset type command"""
140+ class UnsetVolumeType (command .Command ):
141+ """Unset volume type command"""
131142
132143 api = 'volume'
133- log = logging .getLogger (__name__ + '.UnsetType ' )
144+ log = logging .getLogger (__name__ + '.UnsetVolumeType ' )
134145
135146 def get_parser (self , prog_name ):
136- parser = super (UnsetType , self ).get_parser (prog_name )
147+ parser = super (UnsetVolumeType , self ).get_parser (prog_name )
137148 parser .add_argument (
138- 'type ' ,
139- metavar = '<type>' ,
140- help = 'Type ID to update' ,
149+ 'volume_type ' ,
150+ metavar = '<volume- type>' ,
151+ help = 'Type ID or name to update' ,
141152 )
142153 parser .add_argument (
143154 'meta_data' ,
@@ -149,11 +160,25 @@ def get_parser(self, prog_name):
149160 def take_action (self , parsed_args ):
150161 self .log .debug ('take_action(%s)' % parsed_args )
151162 volume_client = self .app .client_manager .volume
152- volume_type = volume_client . volume_types . get (
153- parsed_args .type
154- )
163+ volume_type = utils . find_resource (
164+ volume_client . volume_types , parsed_args .volume_type )
165+
155166 key_list = []
156167 key_list .append (parsed_args .meta_data )
157168 volume_type .unset_keys (key_list )
158169
159170 return
171+
172+
173+ def _format_type_list_extra_specs (vol_type ):
174+ """Return a string containing the key value pairs
175+
176+ :param server: a single VolumeType resource
177+ :rtype: a string formatted to key=value
178+ """
179+
180+ keys = vol_type .get_keys ()
181+ output = ""
182+ for s in keys :
183+ output = output + s + "=" + keys [s ] + "; "
184+ return output
0 commit comments