def terminate_cluster(ctx, cluster, description): if CONF.use_identity_api_v3: trusts.use_os_admin_auth_token(cluster) LOG.debug('Terminating {description} cluster {cluster} ' 'in "{status}" state with id {id}' .format(cluster=cluster.name, id=cluster.id, status=cluster.status, description=description)) try: ops.terminate_cluster(cluster.id) except Exception as e: LOG.warning(_LW('Failed to terminate {description} cluster ' '{cluster} in "{status}" state with id {id}: ' '{error}.').format(cluster=cluster.name, id=cluster.id, error=six.text_type(e), status=cluster.status, description=description)) else: if cluster.status != 'AwaitingTermination': conductor.cluster_update( ctx, cluster, {'status': 'AwaitingTermination'})
def terminate_cluster(ctx, cluster, description): if CONF.use_identity_api_v3: trusts.use_os_admin_auth_token(cluster) LOG.debug( 'Terminating %(description)s cluster %(cluster)s ' 'in "%(status)s" state with id %(id)s', { 'cluster': cluster.name, 'id': cluster.id, 'status': cluster.status, 'description': description }) try: ops.terminate_cluster(cluster.id) except Exception as e: LOG.warn( _LW('Failed to terminate %(description)s cluster ' '%(cluster)s in "%(status)s" state with id %(id)s: ' '%(error)s.'), { 'cluster': cluster.name, 'id': cluster.id, 'error': six.text_type(e), 'status': cluster.status, 'description': description }) else: if cluster.status != 'AwaitingTermination': conductor.cluster_update(ctx, cluster, {'status': 'AwaitingTermination'})
def test_terminate_cluster(self, p_ctx, p_delete_trust, p_conf, p_set): del self.SEQUENCE[:] base_plugins.PLUGINS = FakePlugin() base_plugins.PLUGINS.get_plugin.return_value = FakePlugin() ops.INFRA = FakeINFRA() ops.conductor = FakePlugin() ops.terminate_cluster('123') # checking that order of calls is right self.assertEqual(['on_terminate_cluster', 'shutdown_cluster', 'cluster_destroy'], self.SEQUENCE, 'Order of calls is wrong')
def test_terminate_cluster(self, p_ctx, p_delete_trust, p_conf): del self.SEQUENCE[:] base_plugins.PLUGINS = FakePlugin() base_plugins.PLUGINS.get_plugin.return_value = FakePlugin() ops.INFRA = FakeINFRA() ops.conductor = FakePlugin() ops.terminate_cluster('123') # checking that order of calls is right self.assertEqual(['on_terminate_cluster', 'shutdown_cluster', 'cluster_destroy'], self.SEQUENCE, 'Order of calls is wrong')
def test_terminate_cluster(self, p_ctx, p_delete_trust, p_conf, p_set): del self.SEQUENCE[:] base_plugins.PLUGINS = FakePlugin() base_plugins.PLUGINS.get_plugin.return_value = FakePlugin() ops.INFRA = FakeINFRA() ops.conductor = FakePlugin() ops.terminate_cluster("123") # checking that order of calls is right self.assertEqual( ["on_terminate_cluster", "shutdown_cluster", "cluster_destroy"], self.SEQUENCE, "Order of calls is wrong" )
def terminate_unneeded_clusters(self, ctx): LOG.debug('Terminating unneeded transient clusters') ctx = context.get_admin_context() context.set_ctx(ctx) for cluster in conductor.cluster_get_all(ctx, status='Active'): if not cluster.is_transient: continue jc = conductor.job_execution_count(ctx, end_time=None, cluster_id=cluster.id) if jc > 0: continue cluster_updated_at = timeutils.normalize_time( timeutils.parse_isotime(cluster.updated_at)) current_time = timeutils.utcnow() spacing = timeutils.delta_seconds(cluster_updated_at, current_time) if spacing < CONF.min_transient_cluster_active_time: continue if CONF.use_identity_api_v3: trusts.use_os_admin_auth_token(cluster) LOG.info( _LI('Terminating transient cluster %(cluster)s ' 'with id %(id)s'), { 'cluster': cluster.name, 'id': cluster.id }) try: ops.terminate_cluster(cluster.id) except Exception as e: LOG.info( _LI('Failed to terminate transient cluster ' '%(cluster)s with id %(id)s: %(error)s.'), { 'cluster': cluster.name, 'id': cluster.id, 'error': six.text_type(e) }) else: if cluster.status != 'AwaitingTermination': conductor.cluster_update( ctx, cluster, {'status': 'AwaitingTermination'}) context.set_ctx(None)
def terminate_unneeded_clusters(self, ctx): LOG.debug('Terminating unneeded transient clusters') ctx = context.get_admin_context() context.set_ctx(ctx) for cluster in conductor.cluster_get_all(ctx, status='Active'): if not cluster.is_transient: continue jc = conductor.job_execution_count(ctx, end_time=None, cluster_id=cluster.id) if jc > 0: continue cluster_updated_at = timeutils.normalize_time( timeutils.parse_isotime(cluster.updated_at)) current_time = timeutils.utcnow() spacing = timeutils.delta_seconds(cluster_updated_at, current_time) if spacing < CONF.min_transient_cluster_active_time: continue if CONF.use_identity_api_v3: trusts.use_os_admin_auth_token(cluster) LOG.info(_LI('Terminating transient cluster %(cluster)s ' 'with id %(id)s'), {'cluster': cluster.name, 'id': cluster.id}) try: ops.terminate_cluster(cluster.id) except Exception as e: LOG.info(_LI('Failed to terminate transient cluster ' '%(cluster)s with id %(id)s: %(error)s.'), {'cluster': cluster.name, 'id': cluster.id, 'error': six.text_type(e)}) else: if cluster.status != 'AwaitingTermination': conductor.cluster_update( ctx, cluster, {'status': 'AwaitingTermination'}) context.set_ctx(None)
def terminate_cluster(ctx, cluster, description): if CONF.use_identity_api_v3 and cluster.trust_id: trusts.use_os_admin_auth_token(cluster) context.set_current_cluster_id(cluster.id) LOG.debug('Terminating {description} cluster ' 'in "{status}" state'.format(status=cluster.status, description=description)) try: ops.terminate_cluster(cluster.id) except Exception as e: LOG.warning( _LW('Failed to terminate {description} cluster in "{status}" ' 'state: {error}.').format(error=six.text_type(e), status=cluster.status, description=description)) else: if cluster.status != 'AwaitingTermination': conductor.cluster_update(ctx, cluster, {'status': 'AwaitingTermination'})
def terminate_cluster(ctx, cluster, description): if CONF.use_identity_api_v3: trusts.use_os_admin_auth_token(cluster) context.set_current_cluster_id(cluster.id) LOG.debug('Terminating {description} cluster ' 'in "{status}" state'.format(status=cluster.status, description=description)) try: ops.terminate_cluster(cluster.id) except Exception as e: LOG.warning(_LW( 'Failed to terminate {description} cluster in "{status}" ' 'state: {error}.').format(error=six.text_type(e), status=cluster.status, description=description)) else: if cluster.status != 'AwaitingTermination': conductor.cluster_update( ctx, cluster, {'status': 'AwaitingTermination'})
def terminate_cluster(ctx, cluster, description): if CONF.use_identity_api_v3 and cluster.trust_id: trusts.use_os_admin_auth_token(cluster) context.set_current_cluster_id(cluster.id) LOG.debug('Terminating {description} cluster ' 'in "{status}" state'.format(status=cluster.status, description=description)) try: ops.terminate_cluster(cluster.id) except Exception as e: LOG.warning(_LW( 'Failed to terminate {description} cluster in "{status}" ' 'state: {error}.').format(error=six.text_type(e), status=cluster.status, description=description)) else: if (cluster.status != c_u.CLUSTER_STATUS_AWAITINGTERMINATION): conductor.cluster_update( ctx, cluster, {'status': c_u.CLUSTER_STATUS_AWAITINGTERMINATION})