def scale_cluster(self, cluster, node_group_id_map): ctx = context.ctx() cluster = g.change_cluster_status(cluster, "Scaling") instance_ids = self._scale_cluster_instances(cluster, node_group_id_map) self._update_rollback_strategy(cluster, instance_ids=instance_ids) cluster = conductor.cluster_get(ctx, cluster) g.clean_cluster_from_empty_ng(cluster) cluster = conductor.cluster_get(ctx, cluster) instances = g.get_instances(cluster, instance_ids) self._await_active(cluster, instances) self._assign_floating_ips(instances) self._await_networks(cluster, instances) cluster = conductor.cluster_get(ctx, cluster) volumes.attach_to_instances(g.get_instances(cluster, instance_ids)) # we should be here with valid cluster: if instances creation # was not successful all extra-instances will be removed above if instance_ids: self._configure_instances(cluster) self._update_rollback_strategy(cluster) return instance_ids
def scale_cluster(self, cluster, node_group_id_map): ctx = context.ctx() cluster = g.change_cluster_status(cluster, "Scaling") instance_ids = self._scale_cluster_instances(cluster, node_group_id_map) self._update_rollback_strategy(cluster, instance_ids=instance_ids) cluster = conductor.cluster_get(ctx, cluster) g.clean_cluster_from_empty_ng(cluster) cluster = conductor.cluster_get(ctx, cluster) instances = g.get_instances(cluster, instance_ids) self._await_active(cluster, instances) self._assign_floating_ips(instances) self._await_networks(cluster, instances) cluster = conductor.cluster_get(ctx, cluster) volumes.attach_to_instances( g.get_instances(cluster, instance_ids)) # we should be here with valid cluster: if instances creation # was not successful all extra-instances will be removed above if instance_ids: self._configure_instances(cluster) self._update_rollback_strategy(cluster) return instance_ids
def create_cluster(self, cluster): ctx = context.ctx() self._update_rollback_strategy(cluster, shutdown=True) # create all instances cluster = g.change_cluster_status(cluster, "Spawning") self._create_instances(cluster) # wait for all instances are up and networks ready cluster = g.change_cluster_status(cluster, "Waiting") instances = g.get_instances(cluster) self._await_active(cluster, instances) self._assign_floating_ips(instances) self._await_networks(cluster, instances) cluster = conductor.cluster_get(ctx, cluster) # attach volumes volumes.attach_to_instances(g.get_instances(cluster)) # prepare all instances cluster = g.change_cluster_status(cluster, "Preparing") self._configure_instances(cluster) self._update_rollback_strategy(cluster)
def test_attach(self, p_create_attach_vol, p_await, p_mount): p_create_attach_vol.side_effect = ['/dev/vdb', '/dev/vdc'] * 2 p_await.return_value = None p_mount.return_value = None instance1 = {'id': '1', 'instance_id': '123', 'instance_name': 'inst_1'} instance2 = {'id': '2', 'instance_id': '456', 'instance_name': 'inst_2'} ng = {'volumes_per_node': 2, 'volumes_size': 2, 'volume_mount_prefix': '/mnt/vols', 'name': 'master', 'instances': [instance1, instance2]} cluster = r.ClusterResource({'node_groups': [ng]}) volumes.attach_to_instances(g.get_instances(cluster)) self.assertEqual(p_create_attach_vol.call_count, 4) self.assertEqual(p_await.call_count, 2) self.assertEqual(p_mount.call_count, 4)
def create_cluster(self, cluster): _warning_logger() ctx = context.ctx() self._update_rollback_strategy(cluster, shutdown=True) # create all instances cluster = c_u.change_cluster_status( cluster, c_u.CLUSTER_STATUS_SPAWNING) self._create_instances(cluster) # wait for all instances are up and networks ready cluster = c_u.change_cluster_status( cluster, c_u.CLUSTER_STATUS_WAITING) instances = c_u.get_instances(cluster) self._await_active(cluster, instances) self._assign_floating_ips(instances) self._await_networks(cluster, instances) cluster = conductor.cluster_get(ctx, cluster) # attach volumes volumes.attach_to_instances(c_u.get_instances(cluster)) # prepare all instances cluster = c_u.change_cluster_status( cluster, c_u.CLUSTER_STATUS_PREPARING) self._configure_instances(cluster) self._update_rollback_strategy(cluster)
def test_attach(self, add_step, add_event, p_create_attach_vol, p_await, p_mount): p_create_attach_vol.side_effect = ['/dev/vdb', '/dev/vdc'] * 2 p_await.return_value = None p_mount.return_value = None add_event.return_value = None add_step.return_value = None instance1 = {'id': '1', 'instance_id': '123', 'instance_name': 'inst_1'} instance2 = {'id': '2', 'instance_id': '456', 'instance_name': 'inst_2'} ng = {'volumes_per_node': 2, 'volumes_size': 2, 'volumes_availability_zone': None, 'volume_mount_prefix': '/mnt/vols', 'volume_type': None, 'name': 'master', 'cluster_id': '11', 'instances': [instance1, instance2], 'volume_local_to_instance': False} cluster = r.ClusterResource({'node_groups': [ng]}) volumes.attach_to_instances(cluster_utils.get_instances(cluster)) self.assertEqual(4, p_create_attach_vol.call_count) self.assertEqual(2, p_await.call_count) self.assertEqual(1, p_mount.call_count)
def test_attach(self, add_step, add_event, p_create_attach_vol, p_await, p_mount): p_create_attach_vol.side_effect = ['/dev/vdb', '/dev/vdc'] * 2 p_await.return_value = None p_mount.return_value = None add_event.return_value = None add_step.return_value = None instance1 = {'id': '1', 'instance_id': '123', 'instance_name': 'inst_1'} instance2 = {'id': '2', 'instance_id': '456', 'instance_name': 'inst_2'} ng = {'volumes_per_node': 2, 'volumes_size': 2, 'volumes_availability_zone': None, 'volume_mount_prefix': '/mnt/vols', 'volume_type': None, 'name': 'master', 'cluster_id': '11', 'instances': [instance1, instance2], 'volume_local_to_instance': False} cluster = r.ClusterResource({'node_groups': [ng]}) volumes.attach_to_instances(g.get_instances(cluster)) self.assertEqual(4, p_create_attach_vol.call_count) self.assertEqual(2, p_await.call_count) self.assertEqual(4, p_mount.call_count)
def test_attach(self, add_step, add_event, p_create_attach_vol, p_await, p_mount): p_create_attach_vol.side_effect = ["/dev/vdb", "/dev/vdc"] * 2 p_await.return_value = None p_mount.return_value = None add_event.return_value = None add_step.return_value = None instance1 = {"id": "1", "instance_id": "123", "instance_name": "inst_1"} instance2 = {"id": "2", "instance_id": "456", "instance_name": "inst_2"} ng = { "volumes_per_node": 2, "volumes_size": 2, "volumes_availability_zone": None, "volume_mount_prefix": "/mnt/vols", "volume_type": None, "name": "master", "cluster_id": "11", "instances": [instance1, instance2], "volume_local_to_instance": False, } cluster = r.ClusterResource({"node_groups": [ng]}) volumes.attach_to_instances(cluster_utils.get_instances(cluster)) self.assertEqual(4, p_create_attach_vol.call_count) self.assertEqual(2, p_await.call_count) self.assertEqual(1, p_mount.call_count)
def scale_cluster(self, cluster, node_group_id_map): ctx = context.ctx() instance_ids = [] try: instance_ids = self._scale_cluster_instances(cluster, node_group_id_map) cluster = conductor.cluster_get(ctx, cluster) g.clean_cluster_from_empty_ng(cluster) cluster = conductor.cluster_get(ctx, cluster) instances = g.get_instances(cluster, instance_ids) self._await_active(cluster, instances) if not g.check_cluster_exists(cluster): LOG.info(g.format_cluster_deleted_message(cluster)) return [] self._assign_floating_ips(instances) self._await_networks(cluster, instances) if not g.check_cluster_exists(cluster): LOG.info(g.format_cluster_deleted_message(cluster)) return [] cluster = conductor.cluster_get(ctx, cluster) volumes.attach_to_instances( g.get_instances(cluster, instance_ids)) except Exception as ex: with excutils.save_and_reraise_exception(): if not g.check_cluster_exists(cluster): LOG.info(g.format_cluster_deleted_message(cluster)) return [] self._log_operation_exception( "Can't scale cluster '%s' (reason: %s)", cluster, ex) cluster = conductor.cluster_get(ctx, cluster) self._rollback_cluster_scaling( cluster, g.get_instances(cluster, instance_ids), ex) instance_ids = [] cluster = conductor.cluster_get(ctx, cluster) g.clean_cluster_from_empty_ng(cluster) cluster = conductor.cluster_update(ctx, cluster, {"status": "Active"}) LOG.info(g.format_cluster_status(cluster)) # we should be here with valid cluster: if instances creation # was not successful all extra-instances will be removed above if instance_ids: self._configure_instances(cluster) return instance_ids
def create_cluster(self, cluster): ctx = context.ctx() try: # create all instances conductor.cluster_update(ctx, cluster, {"status": "Spawning"}) LOG.info(g.format_cluster_status(cluster)) self._create_instances(cluster) # wait for all instances are up and networks ready cluster = conductor.cluster_update(ctx, cluster, {"status": "Waiting"}) LOG.info(g.format_cluster_status(cluster)) instances = g.get_instances(cluster) self._await_active(cluster, instances) if not g.check_cluster_exists(cluster): LOG.info(g.format_cluster_deleted_message(cluster)) return self._assign_floating_ips(instances) self._await_networks(cluster, instances) if not g.check_cluster_exists(cluster): LOG.info(g.format_cluster_deleted_message(cluster)) return cluster = conductor.cluster_get(ctx, cluster) # attach volumes volumes.attach_to_instances(g.get_instances(cluster)) # prepare all instances cluster = conductor.cluster_update(ctx, cluster, {"status": "Preparing"}) LOG.info(g.format_cluster_status(cluster)) self._configure_instances(cluster) except Exception as ex: with excutils.save_and_reraise_exception(): if not g.check_cluster_exists(cluster): LOG.info(g.format_cluster_deleted_message(cluster)) return self._log_operation_exception( "Can't start cluster '%s' (reason: %s)", cluster, ex) cluster = conductor.cluster_update( ctx, cluster, {"status": "Error", "status_description": str(ex)}) LOG.info(g.format_cluster_status(cluster)) self._rollback_cluster_creation(cluster, ex)
def scale_cluster(self, cluster, node_group_id_map): ctx = context.ctx() instance_ids = [] try: instance_ids = self._scale_cluster_instances(cluster, node_group_id_map) cluster = conductor.cluster_get(ctx, cluster) g.clean_cluster_from_empty_ng(cluster) cluster = conductor.cluster_get(ctx, cluster) instances = g.get_instances(cluster, instance_ids) self._await_active(cluster, instances) self._assign_floating_ips(instances) self._await_networks(cluster, instances) cluster = conductor.cluster_get(ctx, cluster) volumes.attach_to_instances( g.get_instances(cluster, instance_ids)) except Exception as ex: with excutils.save_and_reraise_exception(): self._log_operation_exception( "Can't scale cluster '%s' (reason: %s)", cluster, ex) cluster = conductor.cluster_get(ctx, cluster) self._rollback_cluster_scaling( cluster, g.get_instances(cluster, instance_ids), ex) instance_ids = [] cluster = conductor.cluster_get(ctx, cluster) g.clean_cluster_from_empty_ng(cluster) if cluster.status == 'Decommissioning': cluster = conductor.cluster_update(ctx, cluster, {"status": "Error"}) else: cluster = conductor.cluster_update(ctx, cluster, {"status": "Active"}) LOG.info(g.format_cluster_status(cluster)) # we should be here with valid cluster: if instances creation # was not successful all extra-instances will be removed above if instance_ids: self._configure_instances(cluster) return instance_ids