Add support attach cinder volume to scale cluster

Partially implement blueprint attach-cinder-volume-scaling-support

Change-Id: I54d23195c208ccd808d83c1d44a45014df5d3bae
This commit is contained in:
Sergey Reshetnyak 2013-07-04 18:54:42 +04:00
parent 46c95693b4
commit ef4536ea98
2 changed files with 38 additions and 18 deletions

View File

@ -62,6 +62,7 @@ def scale_cluster(cluster, node_group_names_map):
instances_list = _scale_cluster_instances( instances_list = _scale_cluster_instances(
cluster, node_groups_map) cluster, node_groups_map)
_await_instances(cluster) _await_instances(cluster)
volumes.attach_to_instances(instances_list)
except Exception as ex: except Exception as ex:
LOG.warn("Can't scale cluster: %s", ex) LOG.warn("Can't scale cluster: %s", ex)
with excutils.save_and_reraise_exception(): with excutils.save_and_reraise_exception():
@ -261,16 +262,21 @@ def _rollback_cluster_creation(cluster, ex):
def _rollback_cluster_scaling(instances): def _rollback_cluster_scaling(instances):
# if some nodes are up we should shut them down and update "count" in try:
# node_group volumes.detach_from_instances(instances)
ng_to_delete = [] except Exception:
for i in instances: raise
ng = i.node_group finally:
_shutdown_instance(i) #if some nodes are up we should shut them down and update "count" in
ng.count -= 1 # node_group
if ng.count == 0: ng_to_delete = []
ng_to_delete.append(ng) for i in instances:
return ng_to_delete ng = i.node_group
_shutdown_instance(i)
ng.count -= 1
if ng.count == 0:
ng_to_delete.append(ng)
return ng_to_delete
def _shutdown_instances(cluster, quiet=False): def _shutdown_instances(cluster, quiet=False):

View File

@ -30,6 +30,11 @@ def attach(cluster):
_attach_volumes_to_node(node_group, instance) _attach_volumes_to_node(node_group, instance)
def attach_to_instances(instances):
for instance in instances:
_attach_volumes_to_node(instance.node_group, instance)
def _await_attach_volume(instance, device_path): def _await_attach_volume(instance, device_path):
timeout = 10 timeout = 10
for _ in six.moves.xrange(timeout): for _ in six.moves.xrange(timeout):
@ -124,11 +129,20 @@ def _mount_volume(instance, device_path, mount_point):
def detach(cluster): def detach(cluster):
for node_group in cluster.node_groups: for node_group in cluster.node_groups:
for instance in node_group.instances: for instance in node_group.instances:
for volume_id in instance.volumes: _detach_volume_from_instance(instance)
volume = cinder.get_volume(volume_id)
try:
volume.detach() def detach_from_instances(instances):
volume.delete() for instance in instances:
except Exception: _detach_volume_from_instance(instance)
LOG.error("Can't detach volume %s" % volume.id)
raise
def _detach_volume_from_instance(instance):
for volume_id in instance.volumes:
volume = cinder.get_volume(volume_id)
try:
volume.detach()
volume.delete()
except Exception:
LOG.error("Can't detach volume %s" % volume.id)
raise