def terminate_unneeded_clusters(self, ctx): LOG.debug('Terminating unneeded 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) api.terminate_cluster(cluster.id) LOG.debug('Terminated cluster %s with id %s' % (cluster.name, cluster.id)) 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: 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 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 _prepare_provisioning(cluster_id): ctx = context.ctx() cluster = conductor.cluster_get(ctx, cluster_id) plugin = plugin_base.PLUGINS.get_plugin(cluster.plugin_name) for nodegroup in cluster.node_groups: update_dict = {} update_dict["image_username"] = INFRA.get_node_group_image_username( nodegroup) conductor.node_group_update(ctx, nodegroup, update_dict) if CONF.use_identity_api_v3: trusts.create_trust_for_cluster(cluster, expires=not cluster.is_transient) trusts.use_os_admin_auth_token(cluster) cluster = conductor.cluster_get(ctx, cluster_id) return ctx, cluster, plugin
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 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: api.terminate_cluster(cluster.id) except Exception as e: LOG.warning( '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})
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 _setup_trust_for_cluster(cluster): cluster = conductor.cluster_get(context.ctx(), cluster) trusts.create_trust_for_cluster(cluster) trusts.use_os_admin_auth_token(cluster)