예제 #1
0
    def create_host_group(self, name, members, policies):
        """
        Create a host group
        """
        member_uuids = []
        for instance_uuid, instance in self._instance_table.iteritems():
            if instance.name in members:
                member_uuids.append(instance_uuid)

        nfvi_host_group = nfvi.objects.v1.HostGroup(name=name,
                                                    member_names=members,
                                                    policies=policies)

        host_group = objects.HostGroup(nfvi_host_group)
        self._host_group_table[host_group.name] = host_group
def database_host_group_get_list():
    """
    Fetch all the host group objects from the database
    """
    db = database_get()
    session = db.session()
    query = session.query(model.HostGroup)

    host_group_objs = list()
    for host_group in query.all():
        nfvi_data = json.loads(host_group.nfvi_host_group_data)
        nfvi_host_group = nfvi.objects.v1.HostGroup(
            nfvi_data['name'], nfvi_data['member_names'],
            nfvi_data['policies'])
        host_group_obj = objects.HostGroup(nfvi_host_group)
        host_group_objs.append(host_group_obj)
    return host_group_objs
예제 #3
0
def _audit_nfvi_hosts_callback(timer_id):
    """
    Audit Hosts
    """
    global _main_audit_inprogress

    response = (yield)
    DLOG.verbose("Audit-Hosts callback, responses=%s." % response)

    if response['completed']:
        host_table = tables.tables_get_host_table()
        deletable_host_groups = list(host_table)

        for host_name in response['incomplete-hosts']:
            if host_name in deletable_host_groups:
                deletable_host_groups.remove(host_name)
                DLOG.info("Not deleting host %s, incomplete information "
                          "returned." % host_name)

        for nfvi_host in response['result-data']:
            host = host_table.get(nfvi_host.name, None)
            if host is None:
                host = objects.Host(nfvi_host)
                host_table[host.name] = host
            else:
                if not host.is_deleted():
                    deletable_host_groups.remove(host.name)

            if 30 <= host.elapsed_time_in_state:
                # Only process the audited host information if the host has
                # been in the current state for at least 30 seconds. This is
                # necessary because the host state information comes from
                # maintenance and the maintenance states may lag the states in
                # the VIM because the VIM and maintenance process some actions
                # at the same time (e.g. when a host is locked).
                host.nfvi_host_update(nfvi_host)
            else:
                DLOG.info("Ignoring audit reply for host %s" % nfvi_host.name)

        for host_name in deletable_host_groups:
            host = host_table[host_name]
            host.nfvi_host_delete()
            if host.is_deleted():
                del host_table[host.name]

        # Manage host groups
        host_group_table = tables.tables_get_host_group_table()
        deletable_host_groups = list(host_group_table)

        for host_name in response['incomplete-hosts']:
            host_group = next(
                (x for x in host_group_table if host_name in x.member_names),
                None)
            if host_group is not None:
                if host_group.name in deletable_host_groups:
                    deletable_host_groups.remove(host_group.name)
                    DLOG.info(
                        "Not deleting host group %s, incomplete information "
                        "returned for host %s." % (host_group.name, host_name))

        for nfvi_host_group in response['host-groups']:
            host_group = host_group_table.get(nfvi_host_group.name, None)
            if host_group is None:
                host_group = objects.HostGroup(nfvi_host_group)
                host_group_table[host_group.name] = host_group
            else:
                deletable_host_groups.remove(host_group.name)

            host_group.nfvi_host_group_update(nfvi_host_group)

        for host_group_name in deletable_host_groups:
            del host_group_table[host_group_name]

    else:
        DLOG.error("Audit-Hosts callback, not completed, responses=%s." %
                   response)

    _main_audit_inprogress = False
    timers.timers_reschedule_timer(timer_id, 2)  # 2 seconds later
예제 #4
0
def _audit_nfvi_hosts_callback(timer_id):
    """
    Audit Hosts
    """
    global _main_audit_inprogress

    response = (yield)
    DLOG.verbose("Audit-Hosts callback, responses=%s." % response)

    if response['completed']:
        host_table = tables.tables_get_host_table()
        deletable_host_groups = host_table.keys()

        for host_name in response['incomplete-hosts']:
            if host_name in deletable_host_groups:
                deletable_host_groups.remove(host_name)
                DLOG.info("Not deleting host %s, incomplete information "
                          "returned." % host_name)

        for nfvi_host in response['result-data']:
            host = host_table.get(nfvi_host.name, None)
            if host is None:
                host = objects.Host(nfvi_host)
                host_table[host.name] = host
            else:
                if not host.is_deleted():
                    deletable_host_groups.remove(host.name)

            host.nfvi_host_update(nfvi_host)

        for host_name in deletable_host_groups:
            host = host_table[host_name]
            host.nfvi_host_delete()
            if host.is_deleted():
                del host_table[host.name]

        # Manage host groups
        host_group_table = tables.tables_get_host_group_table()
        deletable_host_groups = host_group_table.keys()

        for host_name in response['incomplete-hosts']:
            host_group = next((x for x in host_group_table
                               if host_name in x.member_names), None)
            if host_group is not None:
                if host_group.name in deletable_host_groups:
                    deletable_host_groups.remove(host_group.name)
                    DLOG.info("Not deleting host group %s, incomplete information "
                              "returned for host %s." % (host_group.name,
                                                         host_name))

        for nfvi_host_group in response['host-groups']:
            host_group = host_group_table.get(nfvi_host_group.name, None)
            if host_group is None:
                host_group = objects.HostGroup(nfvi_host_group)
                host_group_table[host_group.name] = host_group
            else:
                deletable_host_groups.remove(host_group.name)

            host_group.nfvi_host_group_update(nfvi_host_group)

        for host_group_name in deletable_host_groups:
            del host_group_table[host_group_name]

    else:
        DLOG.error("Audit-Hosts callback, not completed, responses=%s."
                   % response)

    _main_audit_inprogress = False
    timers.timers_reschedule_timer(timer_id, 2)  # 2 seconds later