Exemple #1
0
    banner(name)
    watch.start(name)

    result = execute(hosts, cm_ssh, username=username, command="qstat")

    watch.stop(name)

    pprint(result)

    banner("PRINT")
    for host in result:
        print result[host]["output"]


for timer in watch.keys():
    print timer, watch.get(timer), "s"


"""
######################################################################
banner("SEQUENTIAL")
######################################################################

watch.start("sequential")
#for host in hosts:
#    print host
#    task[host] = cm_ssh(username=username,
#                          host=host,
#                          command="qstat")
result = Sequential(hosts, cm_ssh, username=username, command="qstat")
Exemple #2
0
    def refresh(self, cm_user_id, names=["all"], types=["all"]):
        """
        This method obtains information about servers, images, and
        flavors that build the cloudmesh. The information is held
        internally after a refresh. Than the find method can be used
        to query form this information. To pull new information into
        this data structure a new refresh needs to be called.

        Usage is defined through arrays that are passed along.


        type = "servers", "images", "flavors"

        The type specifies the kind of element that we look for
        (we only look for the first character e.g. s, i, f)

        In all cases None can be used as an alternative to ["all"]

        if cloud name  is None and type = none update everything

        if cloud name !=None and type = none update everything in the
        specified clouds

        if cloud name is not None and type != none
           refresh the given types for the given clouds

        """

        if types == ['all'] or types is None:
            types = ['servers', 'flavors', 'images']

        if names == ['all'] or names is None:
            # names = self.clouds.keys()
            names = self.active_clouds(cm_user_id)

        watch = StopWatch()

        for name in names:
            watch_name = "{0}-{1}".format(cm_user_id, name)
            log.info("-" * 80)
            log.info("Retrieving data for %s" % name)
            log.info("-" * 80)
            cloud = None
            for type in types:
                # for identity management operations, use the keystone class
                if type in ['users', 'tenants', 'roles']:
                    cloud = keystone(name)
                # else try compute/nova class
                elif 'manager' in self.clouds[cm_user_id][name]:
                    cloud = self.clouds[cm_user_id][name]['manager']

                log.info("Refreshing {0} {1} {2} ->".format(
                    cm_user_id, type, name))

                watch.start(watch_name)
                cloud.refresh(type)
                result = cloud.get(type)
                # print "YYYYY", len(result)
                # pprint(result)
                # add result to db,
                watch.stop(watch_name)
                log.info('Refresh time: %s' % watch.get(watch_name))

                watch.start(watch_name)

                if type in ['servers']:
                    self.db_clouds.remove({
                        "cm_user_id": cm_user_id,
                        "cm_cloud": name,
                        "cm_kind": type
                    })
                else:
                    self.db_clouds.remove({"cm_cloud": name, "cm_kind": type})

                for element in result:
                    # Stacks has different key name 'stack_name'
                    if type in ['t_stacks']:
                        t_name = 'stack_name'
                    else:
                        t_name = 'name'
                    id = "{0}-{1}-{2}".format(name, type,
                                              result[element][t_name]).replace(
                                                  ".", "-")
                    # servers or security_groups is for each user.
                    # Stacks as well (10/17/2014)
                    if type in ['servers', 'e_security_groups', 't_stacks']:
                        result[element]['cm_user_id'] = cm_user_id

                    result[element]['cm_id'] = id
                    result[element]['cm_cloud'] = name
                    result[element]['cm_type'] = self.clouds[cm_user_id][name][
                        'cm_type']
                    result[element]['cm_type_version'] = self.clouds[
                        cm_user_id][name]['cm_type_version']
                    result[element]['cm_kind'] = type
                    # print "HPCLOUD_DEBUG", result[element]
                    for key in result[element]:
                        # print key
                        if '.' in key:
                            del result[element][key]
                    if 'metadata' in result[element].keys():
                        for key in result[element]['metadata']:
                            if '.' in key:
                                fixedkey = key.replace(".", "_")
                                # print "%s->%s" % (key,fixedkey)
                                value = result[element]['metadata'][key]
                                del result[element]['metadata'][key]
                                result[element]['metadata'][fixedkey] = value
                    # print "HPCLOUD_DEBUG - AFTER DELETING PROBLEMATIC KEYS",
                    # result[element]

                    # exception.
                    if "_id" in result[element]:
                        del (result[element]['_id'])

                    self.db_clouds.insert(result[element])

                watch.stop(watch_name)
                log.info('Store time: %s' % watch.get(watch_name))
Exemple #3
0
    def refresh(self, cm_user_id, names=["all"], types=["all"]):
        """
        This method obtains information about servers, images, and
        flavors that build the cloudmesh. The information is held
        internally after a refresh. Than the find method can be used
        to query form this information. To pull new information into
        this data structure a new refresh needs to be called.

        Usage is defined through arrays that are passed along.


        type = "servers", "images", "flavors"

        The type specifies the kind of element that we look for
        (we only look for the first character e.g. s, i, f)

        In all cases None can be used as an alternative to ["all"]

        if cloud name  is None and type = none update everything

        if cloud name !=None and type = none update everything in the
        specified clouds

        if cloud name is not None and type != none
           refresh the given types for the given clouds

        """

        if types == ['all'] or types is None:
            types = ['servers', 'flavors', 'images']

        if names == ['all'] or names is None:
            # names = self.clouds.keys()
            names = self.active_clouds(cm_user_id)

        watch = StopWatch()

        for name in names:
            print("*", name)
            watch_name = "{0}-{1}".format(cm_user_id, name)
            log.info("-" * 80)
            log.info("Retrieving data for %s" % name)
            log.info("-" * 80)
            cloud = None
            for type in types:
                # for identity management operations, use the keystone class
                if type in ['users', 'tenants', 'roles']:
                    cloud = keystone(name)
                # else try compute/nova class
                elif 'manager' in self.clouds[cm_user_id][name]:
                    cloud = self.clouds[cm_user_id][name]['manager']

                print("Refreshing {0} {1} {2} ->".format(cm_user_id, type, name))

                watch.start(watch_name)
                cloud.refresh(type)
                result = cloud.get(type)
                # print "YYYYY", len(result)
                # pprint(result)
                # add result to db,
                watch.stop(watch_name)
                print('Refresh time:', watch.get(watch_name))

                watch.start(watch_name)

                if type in ['servers']:
                    self.db_clouds.remove(
                        {"cm_user_id": cm_user_id, "cm_cloud": name, "cm_kind": type})
                else:
                    self.db_clouds.remove({"cm_cloud": name, "cm_kind": type})

                for element in result:
                    id = "{0}-{1}-{2}".format(
                        name, type, result[element]['name']).replace(".", "-")
                    # servers or security_groups is for each user.
                    if type in ['servers', 'e_security_groups']:
                        result[element]['cm_user_id'] = cm_user_id

                    result[element]['cm_id'] = id
                    result[element]['cm_cloud'] = name
                    result[element]['cm_type'] = self.clouds[
                        cm_user_id][name]['cm_type']
                    result[element]['cm_type_version'] = self.clouds[
                        cm_user_id][name]['cm_type_version']
                    result[element]['cm_kind'] = type
                    # print "HPCLOUD_DEBUG", result[element]
                    for key in result[element]:
                        # print key
                        if '.' in key:
                            del result[element][key]
                    if 'metadata' in result[element].keys():
                        for key in result[element]['metadata']:
                            if '.' in key:
                                fixedkey = key.replace(".", "_")
                                # print "%s->%s" % (key,fixedkey)
                                value = result[element]['metadata'][key]
                                del result[element]['metadata'][key]
                                result[element]['metadata'][fixedkey] = value
                    # print "HPCLOUD_DEBUG - AFTER DELETING PROBLEMATIC KEYS",
                    # result[element]

                    # exception.
                    if "_id" in result[element]:
                        del(result[element]['_id'])

                    self.db_clouds.insert(result[element])

                watch.stop(watch_name)
                print('Store time:', watch.get(watch_name))