示例#1
0
 def _ips_assign(self, ips_assigned, cluster, instances):
     if not cluster_utils.check_cluster_exists(cluster):
         return True
     for instance in instances:
         if instance.id not in ips_assigned:
             with context.set_current_instance_id(instance.instance_id):
                 if networks.init_instances_ips(instance):
                     ips_assigned.add(instance.id)
                     cpo.add_successful_event(instance)
     return len(ips_assigned) == len(instances)
示例#2
0
 def _check_active(self, active_ids, cluster, instances):
     if not c_u.check_cluster_exists(cluster):
         return True
     for instance in instances:
         if instance.id not in active_ids:
             with context.set_current_instance_id(instance.instance_id):
                 if self._check_if_active(instance):
                     active_ids.add(instance.id)
                     cpo.add_successful_event(instance)
     return len(instances) == len(active_ids)
示例#3
0
 def _ips_assign(self, ips_assigned, cluster, instances):
     if not cluster_utils.check_cluster_exists(cluster):
         return True
     for instance in instances:
         if instance.id not in ips_assigned:
             with context.set_current_instance_id(instance.instance_id):
                 if networks.init_instances_ips(instance):
                     ips_assigned.add(instance.id)
                     cpo.add_successful_event(instance)
     return len(ips_assigned) == len(instances)
示例#4
0
    def _check_deleted(self, deleted_ids, cluster, instances):
        if not cluster_utils.check_cluster_exists(cluster):
            return True

        for instance in instances:
            if instance.id not in deleted_ids:
                with context.set_current_instance_id(instance.instance_id):
                    if self._check_if_deleted(instance):
                        LOG.debug("Instance is deleted")
                        deleted_ids.add(instance.id)
                        cpo.add_successful_event(instance)
        return len(deleted_ids) == len(instances)
示例#5
0
文件: engine.py 项目: Imperat/sahara
    def _check_deleted(self, deleted_ids, cluster, instances):
        if not cluster_utils.check_cluster_exists(cluster):
            return True

        for instance in instances:
            if instance.id not in deleted_ids:
                with context.set_current_instance_id(instance.instance_id):
                    if self._check_if_deleted(instance):
                        LOG.debug("Instance is deleted")
                        deleted_ids.add(instance.id)
                        cpo.add_successful_event(instance)
        return len(deleted_ids) == len(instances)
示例#6
0
    def _is_accessible(self, instance):
        if not cluster_utils.check_cluster_exists(instance.cluster):
            return True
        try:
            # check if ssh is accessible and cloud-init
            # script is finished generating authorized_keys
            exit_code, stdout = instance.remote().execute_command(
                "ls .ssh/authorized_keys", raise_when_error=False)

            if exit_code == 0:
                LOG.debug('Instance is accessible')
                return True
        except Exception as ex:
            LOG.debug("Can't login to node, IP: {mgmt_ip}, "
                      "reason {reason}".format(mgmt_ip=instance.management_ip,
                                               reason=ex))
            return False

        return False
示例#7
0
def add_provisioning_step(cluster_id, step_name, total):
    if (CONF.disable_event_log
            or not cluster_utils.check_cluster_exists(cluster_id)):
        return

    prev_step = get_current_provisioning_step(cluster_id)
    if prev_step:
        conductor.cluster_provision_step_update(context.ctx(), prev_step)

    step_type = context.ctx().current_instance_info.step_type
    new_step = conductor.cluster_provision_step_add(
        context.ctx(), cluster_id, {
            'step_name': step_name,
            'step_type': step_type,
            'total': total,
            'started_at': timeutils.utcnow(),
        })
    context.current().current_instance_info.step_id = new_step
    return new_step
示例#8
0
文件: engine.py 项目: Imperat/sahara
    def _is_accessible(self, instance):
        if not cluster_utils.check_cluster_exists(instance.cluster):
            return True
        try:
            # check if ssh is accessible and cloud-init
            # script is finished generating authorized_keys
            exit_code, stdout = instance.remote().execute_command(
                "ls .ssh/authorized_keys", raise_when_error=False)

            if exit_code == 0:
                LOG.debug('Instance is accessible')
                return True
        except Exception as ex:
            LOG.debug("Can't login to node, IP: {mgmt_ip}, "
                      "reason {reason}".format(mgmt_ip=instance.management_ip,
                                               reason=ex))
            return False

        return False
def add_provisioning_step(cluster_id, step_name, total):
    if (CONF.disable_event_log or
            not cluster_utils.check_cluster_exists(cluster_id)):
        return

    prev_step = get_current_provisioning_step(cluster_id)
    if prev_step:
        conductor.cluster_provision_step_update(context.ctx(), prev_step)

    step_type = context.ctx().current_instance_info.step_type
    new_step = conductor.cluster_provision_step_add(
        context.ctx(), cluster_id, {
            'step_name': step_name,
            'step_type': step_type,
            'total': total,
            'started_at': timeutils.utcnow(),
        })
    context.current().current_instance_info.step_id = new_step
    return new_step
示例#10
0
    def _is_accessible(self, instance):
        if not cluster_utils.check_cluster_exists(instance.cluster):
            return True
        try:
            # check if ssh is accessible and cloud-init
            # script is finished generating authorized_keys
            exit_code, stdout = instance.remote().execute_command(
                "ls .ssh/authorized_keys", raise_when_error=False)

            if exit_code == 0:
                LOG.debug('Instance is accessible')
                return True
        except Exception as ex:
            ip_used = "internal_ip" if CONF.proxy_command and \
                CONF.proxy_command_use_internal_ip else "management_ip"
            LOG.debug("Can't login to node, IP: {ip}, reason {reason}".format(
                ip=getattr(instance, ip_used), reason=ex))
            return False

        return False
示例#11
0
    def _is_accessible(self, instance):
        if not cluster_utils.check_cluster_exists(instance.cluster):
            return True
        try:
            # check if ssh is accessible and cloud-init
            # script is finished generating authorized_keys
            exit_code, stdout = instance.remote().execute_command(
                "ls .ssh/authorized_keys", raise_when_error=False)

            if exit_code == 0:
                LOG.debug('Instance is accessible')
                return True
        except Exception as ex:
            ip_used = "internal_ip" if CONF.proxy_command and \
                CONF.proxy_command_use_internal_ip else "management_ip"
            LOG.debug("Can't login to node, IP: {ip}, reason {reason}"
                      .format(ip=getattr(instance, ip_used),
                              reason=ex))
            return False

        return False
示例#12
0
        def handler(*args, **kwargs):
            if CONF.disable_event_log:
                return func(*args, **kwargs)
            step_name = spec.get('step', None)
            instance = _find_in_args(spec, *args, **kwargs)
            cluster_id = instance.cluster_id

            if not cluster_utils.check_cluster_exists(cluster_id):
                return func(*args, **kwargs)

            if step_name:
                # It's single process, let's add provisioning step here
                add_provisioning_step(cluster_id, step_name, 1)

            try:
                value = func(*args, **kwargs)
            except Exception as e:
                with excutils.save_and_reraise_exception():
                    add_fail_event(instance, e)

            if mark_successful_on_exit:
                add_successful_event(instance)

            return value
示例#13
0
        def handler(*args, **kwargs):
            if CONF.disable_event_log:
                return func(*args, **kwargs)
            step_name = spec.get('step', None)
            instance = _find_in_args(spec, *args, **kwargs)
            cluster_id = instance.cluster_id

            if not cluster_utils.check_cluster_exists(cluster_id):
                return func(*args, **kwargs)

            if step_name:
                # It's single process, let's add provisioning step here
                add_provisioning_step(cluster_id, step_name, 1)

            try:
                value = func(*args, **kwargs)
            except Exception as e:
                with excutils.save_and_reraise_exception():
                    add_fail_event(instance, e)

            if mark_successful_on_exit:
                add_successful_event(instance)

            return value
示例#14
0
 def _get(n_cluster, n_kwargs):
     if not cluster_utils.check_cluster_exists(n_cluster):
         return True
     return get_status(**n_kwargs)
示例#15
0
def get_current_provisioning_step(cluster_id):
    if (CONF.disable_event_log or
            not cluster_utils.check_cluster_exists(cluster_id)):
        return None
    current_instance_info = context.ctx().current_instance_info
    return current_instance_info.step_id
示例#16
0
def get_current_provisioning_step(cluster_id):
    if (CONF.disable_event_log
            or not cluster_utils.check_cluster_exists(cluster_id)):
        return None
    current_instance_info = context.ctx().current_instance_info
    return current_instance_info.step_id
示例#17
0
 def test_check_cluster_exists(self):
     ctx = context.ctx()
     cluster = self._make_sample()
     self.assertTrue(cluster_utils.check_cluster_exists(cluster))
     self.api.cluster_destroy(ctx, cluster)
     self.assertFalse(cluster_utils.check_cluster_exists(cluster))
示例#18
0
 def _get(n_cluster, n_kwargs):
     if not cluster_utils.check_cluster_exists(n_cluster):
         return True
     return get_status(**n_kwargs)
示例#19
0
def check_cluster_exists(cluster, **kwargs):
    return cluster_utils.check_cluster_exists(cluster)