Commit 8801f83b authored by Stavros Sachtouris's avatar Stavros Sachtouris Committed by Giorgos Korfiatis

Set archipelago as default volume type in create

There are three cases when creating a volume:
* A volume type is explicitly set by the user. In that case, the
provided value is used.
* A server id is provided, but no volume type. In that case, the
server can figure out the correct volume type, so kamaki does not
have to set one.
* Neither a server id or a a volume type is set. In this case,
kamaki uses the "ext_archipelago" volume type as default.
parent 857ab368
......@@ -121,7 +121,11 @@ class volume_create(_BlockStorageInit, OptionalOutput, _VolumeWait):
'Associate a snapshot to the new volume', '--snapshot-id'),
image_id=argument.ValueArgument(
'Associate an image to the new volume', '--image-id'),
volume_type=argument.ValueArgument('Volume type', '--volume-type'),
volume_type=argument.ValueArgument(
'default: if combined with --server-id, the default is '
'automatically configured to match the server, otherwise it is '
'ext_archipelago',
'--volume-type'),
metadata=argument.KeyValueArgument(
'Metadata of key=value form (can be repeated)', '--metadata'),
project_id=argument.ValueArgument(
......@@ -133,13 +137,21 @@ class volume_create(_BlockStorageInit, OptionalOutput, _VolumeWait):
@errors.Generic.all
def _run(self, size, name):
# Figure out volume type
volume_type = self['volume_type']
if not (self['server_id'] or volume_type):
for vtype in self.client.list_volume_types():
if vtype['name'] in ('ext_archipelago'):
volume_type = vtype['id']
break
r = self.client.create_volume(
size, name,
server_id=self['server_id'],
display_description=self['description'],
snapshot_id=self['snapshot_id'],
imageRef=self['image_id'],
volume_type=self['volume_type'],
volume_type=volume_type,
metadata=self['metadata'],
project=self['project_id'])
self.print_dict(r)
......@@ -210,10 +222,10 @@ class volume_delete(_BlockStorageInit, _VolumeWait):
@errors.Generic.all
def _run(self, volume_id):
r = self.client.get_volume_details(volume_id)
self.client.delete_volume(volume_id)
if self['wait']:
try:
r = self.client.get_volume_details(volume_id)
self.wait_while(volume_id, r['status'])
r = self.client.get_volume_details(volume_id)
if r['status'] != 'deleted':
......@@ -255,7 +267,7 @@ class volume_wait(_BlockStorageInit, _VolumeWait):
volume_id, self['status_u'].lower(),
timeout=self['timeout'])
else:
status_w = self['status_w'].lower() or 'creating'
status_w = (self['status_w'] or '').lower() or 'creating'
if r['status'] == status_w.lower():
self.wait_while(volume_id, status_w, timeout=self['timeout'])
else:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment