Пример #1
0
    def _await_networks(self, cluster, instances):
        if not instances:
            return

        cpo.add_provisioning_step(cluster.id, _("Assign IPs"), len(instances))

        ips_assigned = set()
        while len(ips_assigned) != len(instances):
            if not g.check_cluster_exists(cluster):
                return
            for instance in instances:
                if instance.id not in ips_assigned:
                    if networks.init_instances_ips(instance):
                        ips_assigned.add(instance.id)
                        cpo.add_successful_event(instance)

            context.sleep(1)

        LOG.info(_LI("Cluster '%s': all instances have IPs assigned"),
                 cluster.id)

        cluster = conductor.cluster_get(context.ctx(), cluster)
        instances = g.get_instances(cluster, ips_assigned)

        cpo.add_provisioning_step(cluster.id,
                                  _("Wait for instance accessibility"),
                                  len(instances))

        with context.ThreadGroup() as tg:
            for instance in instances:
                tg.spawn("wait-for-ssh-%s" % instance.instance_name,
                         self._wait_until_accessible, instance)

        LOG.info(_LI("Cluster '%s': all instances are accessible"), cluster.id)
Пример #2
0
 def _check_active(self, active_ids, cluster, instances):
     if not g.check_cluster_exists(cluster):
         return True
     for instance in instances:
         if instance.id not in active_ids:
             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 wrapped(*args, **kwargs):
     instance = _find_argument(instance_reference, *args, **kwargs)
     try:
         result = function(*args, **kwargs)
         cpo.add_successful_event(instance)
         return result
     except Exception as exception:
         cpo.add_fail_event(instance, exception)
         raise exception
Пример #4
0
 def _check_active(self, active_ids, cluster, instances):
     if not g.check_cluster_exists(cluster):
         return True
     for instance in instances:
         if instance.id not in active_ids:
             if self._check_if_active(instance):
                 active_ids.add(instance.id)
                 cpo.add_successful_event(instance)
     return len(instances) == len(active_ids)
Пример #5
0
 def _ips_assign(self, ips_assigned, cluster, instances):
     if not g.check_cluster_exists(cluster):
         return True
     for instance in instances:
         if instance.id not in ips_assigned:
             if networks.init_instances_ips(instance):
                 ips_assigned.add(instance.id)
                 cpo.add_successful_event(instance)
     return len(ips_assigned) == len(instances)
Пример #6
0
 def wrapped(*args, **kwargs):
     instance = _find_argument(instance_reference, *args, **kwargs)
     try:
         result = function(*args, **kwargs)
         cpo.add_successful_event(instance)
         return result
     except Exception as exception:
         cpo.add_fail_event(instance, exception)
         raise exception
Пример #7
0
 def _ips_assign(self, ips_assigned, cluster, instances):
     if not g.check_cluster_exists(cluster):
         return True
     for instance in instances:
         if instance.id not in ips_assigned:
             if networks.init_instances_ips(instance):
                 ips_assigned.add(instance.id)
                 cpo.add_successful_event(instance)
     return len(ips_assigned) == len(instances)
Пример #8
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)
Пример #9
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)
Пример #10
0
    def _check_deleted(self, deleted_ids, cluster, instances):
        if not g.check_cluster_exists(cluster):
            return True

        for instance in instances:
            if instance.id not in deleted_ids:
                if self._check_if_deleted(instance):
                    LOG.debug("Instance {instance} is deleted".format(
                              instance=instance.instance_name))
                    deleted_ids.add(instance.id)
                    cpo.add_successful_event(instance)
        return len(deleted_ids) == len(instances)
Пример #11
0
    def _check_deleted(self, deleted_ids, cluster, instances):
        if not g.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)
Пример #12
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)
Пример #13
0
    def _check_deleted(self, deleted_ids, cluster, instances):
        if not g.check_cluster_exists(cluster):
            return True

        for instance in instances:
            if instance.id not in deleted_ids:
                if self._check_if_deleted(instance):
                    LOG.debug("Instance {instance} is deleted".format(
                        instance=instance.instance_name))
                    deleted_ids.add(instance.id)
                    cpo.add_successful_event(instance)
        return len(deleted_ids) == len(instances)
Пример #14
0
 def wrapped(*args, **kwargs):
     event_instance = instance or _find_argument(
         instance_reference, *args, **kwargs)
     if name:
         cpo.add_provisioning_step(event_instance.node_group.cluster.id,
                                   name, 1)
     try:
         result = function(*args, **kwargs)
         cpo.add_successful_event(event_instance)
         return result
     except Exception as exception:
         cpo.add_fail_event(event_instance, exception)
         raise exception
Пример #15
0
    def test_add_successful_event(self, conductor, get_step, ctx):
        instance = FakeInstance()

        self.override_config("disable_event_log", True)
        cpo.add_successful_event(instance)
        self.assertEqual(0, conductor.cluster_event_add.call_count)

        self.override_config("disable_event_log", False)
        cpo.add_successful_event(instance)
        self.assertEqual(1, conductor.cluster_event_add.call_count)
        args, kwargs = conductor.cluster_event_add.call_args
        self.assertEqual('step_id', args[1])
        req_dict = {
            'successful': True,
            'node_group_id': instance.node_group_id,
            'instance_id': instance.instance_id,
            'instance_name': instance.instance_name,
            'event_info': None,
        }
        self.assertEqual(req_dict, args[2])
Пример #16
0
    def _await_deleted(self, cluster, instances):
        """Await all instances are deleted."""
        if not instances:
            return
        cpo.add_provisioning_step(
            cluster.id, _("Wait for instances to be deleted"), len(instances))

        deleted_ids = set()
        while len(deleted_ids) != len(instances):
            if not g.check_cluster_exists(cluster):
                return
            for instance in instances:
                if instance.id not in deleted_ids:
                    if self._check_if_deleted(instance):
                        LOG.debug("Instance '%s' is deleted" %
                                  instance.instance_name)
                        deleted_ids.add(instance.id)
                        cpo.add_successful_event(instance)

            context.sleep(1)
Пример #17
0
    def _await_active(self, cluster, instances):
        """Await all instances are in Active status and available."""
        if not instances:
            return

        cpo.add_provisioning_step(cluster.id,
                                  _("Wait for instances to become active"),
                                  len(instances))

        active_ids = set()
        while len(active_ids) != len(instances):
            if not g.check_cluster_exists(cluster):
                return
            for instance in instances:
                if instance.id not in active_ids:
                    if self._check_if_active(instance):
                        active_ids.add(instance.id)
                        cpo.add_successful_event(instance)

            context.sleep(1)

        LOG.info(_LI("Cluster '%s': all instances are active"), cluster.id)
Пример #18
0
def add_successful_event(instance, **kwargs):
    ops.add_successful_event(instance)