예제 #1
0
 def __init__(self):
     self.clear()
     # Read Yaml File to find all the cloud configurations present
     self.config()
     try:
         self.metric_api = FGMetricsAPI()
     except:
         pass
예제 #2
0
파일: metrics.py 프로젝트: lee212/cloudmesh
 def __init__(self):
     self.clear()
     # Read Yaml File to find all the cloud configurations present
     self.config()
     try:
         self.metric_api = FGMetricsAPI()
     except:
         pass
예제 #3
0
파일: metrics.py 프로젝트: lee212/cloudmesh
class metrics:

    #
    # global variables that define the information managed by this class
    #

    # dict that holds vms, flavors, images for al iaas
    clouds = {}

    # array with keys from the user
    keys = []

    #
    # variables that we can most likely eliminate
    #

    # user needs to come from credential ...
    user = "******"

    #
    # initialization methods
    #

    def __init__(self):
        self.clear()
        # Read Yaml File to find all the cloud configurations present
        self.config()
        try:
            self.metric_api = FGMetricsAPI()
        except:
            pass

    def clear(self):
        self.clouds = {}
        self.keys = []
        self.user = "******"

    #
    # some metric methods
    #

    def get_metrics_cli(self, args):
        """ Get usage data from FG Metric CLI"""
        """ This is replica with get_metrics but using CLI instead of API """
        """
            Args:
                args (dict): parameters for CLI with option
            Return:
                (dict): output of fgmetric in a dict type
            Raise:
                n/a
        """
        try:
            res = fgmetric(
                args)  # args should be list-lized before send it out as a parameter
            return json.loads(res, object_hook=json_util.object_hook)
        except:
            pass

    def get_metrics(self, args):
        """Get usage data from FG Metrics"""

        if not self.metric_api:
            return

        try:
            args["user"] = args["user"] or self.user
            self._set_metric_api_vars(args)
            # print args
            stats = self.metric_api._set_dict_vars()
            metrics = self.metric_api.get_stats()
            stats["stats"] = metrics
            self.metrics = stats
            # print self.metrics
        except:
            print sys.exc_info()
            pass
        return self.metrics

    def get_realtime_metrics(self, args):
        """ get real-time usage data from FG Metrics"""

        # IN DEVELOPMENT
        if not self.metric_api:
            return

        try:
            print 1
        except:
            pass

    def _set_metric_api_vars(self, args):
        self.metric_api.set_date(args["s_date"], args["e_date"])
        self.metric_api.set_metric(
            "count runtime cores mem disks")  # args["metric"])
        self.metric_api.set_user(args["user"])
        self.metric_api.set_cloud(args["cloud"])
        self.metric_api.set_hostname(args["host"])
        self.metric_api.set_period(args["period"])

    #
    # the configuration method that must be called to get the cloud info
    #

    def config(self):
        """
        reads the cloudmesh yaml file that defines which clouds build
        the cloudmesh
        """

        configuration = cm_config()
        pp.pprint(configuration)

        for cloud_name in configuration.keys():
            print "--------------------"

            try:
                credential = configuration.get(key=cloud_name)
                cloud_type = credential['cm_type']

                print credential

                print ">>>>>>>", cloud_name, cloud_type

                if cloud_type in ['openstack', 'eucalyptus']:
                    print "AAAAA"
                    self.clouds[cloud_name] = {
                        'cm_type': cloud_type, 'credential': credential}
                    print "BBBB"
                    try:
                        self.update(cloud_name, cloud_type)
                        self.clouds[cloud_name] = {
                            'cm_type': cloud_type, 'credential': credential}
                    except:
                        print "ERROR: can not connect to", cloud_name
                    print "CCCC"

            except Exception, e:
                print "ERROR: Not a cloud:", cloud_name, e
        return
예제 #4
0
class cloudmesh:

    #
    # global variables that define the information managed by this class
    #

    datastore = "data/clouds.txt"

    # dict that holds vms, flavors, images for al iaas
    clouds = {}

    # array with keys from the user
    keys = []

    #
    # variables that we can most likely eliminate
    #

    # user needs to come from credential ...
    user = "******"

    #
    # initialization methods
    #

    def __init__(self):
        self.clear()
        # Read Yaml File to find all the cloud configurations present
        self.config()
        try:
            self.metric_api = FGMetricsAPI()
        except:
            pass

    def clear(self):
        self.clouds = {}
        self.keys = []
        self.user = "******"

    #
    # some metric methods
    #

    def get_metrics_cli(self, args):
        """ Get usage data from FG Metric CLI"""
        """ This is replica with get_metrics but using CLI instead of API """
        """
            Args:
                args (dict): parameters for CLI with option
            Return:
                (dict): output of fgmetric in a dict type
            Raise:
                n/a
        """
        try:
            res = fgmetric(
                args)  # args should be list-lized before send it out as a parameter
            return json.loads(res, object_hook=json_util.object_hook)
        except:
            pass

    def get_metrics(self, args):
        """Get usage data from FG Metrics"""

        if not self.metric_api:
            return

        try:
            args["user"] = args["user"] or self.user
            self._set_metric_api_vars(args)
            # print args
            stats = self.metric_api._set_dict_vars()
            metrics = self.metric_api.get_stats()
            stats["stats"] = metrics
            self.metrics = stats
            # print self.metrics
        except:
            print sys.exc_info()
            pass
        return self.metrics

    def _set_metric_api_vars(self, args):
        self.metric_api.set_date(args["s_date"], args["e_date"])
        self.metric_api.set_metric(
            "count runtime cores mem disks")  # args["metric"])
        self.metric_api.set_user(args["user"])
        self.metric_api.set_cloud(args["cloud"])
        self.metric_api.set_hostname(args["host"])
        self.metric_api.set_period(args["period"])

    #
    # the configuration method that must be called to get the cloud info
    #

    # Updated the config method. Now It reads the config correctly.
    def config(self):
        """
        reads the cloudmesh yaml file that defines which clouds build
        the cloudmesh
        """
        configuration = cm_config()
        all_keys = configuration.keys()
        all_keys = all_keys[2:]
        for name in all_keys:
            if str(name) != 'username' and str(name) != 'default':
                credential = configuration.get(name)
                print name
                type = credential['cm_type']
                self.clouds[name] = {'cm_type': type, 'credential': credential}
            # self.update(name, type)
        return

    #
    # importnat get methods
    #

    def get(self):
        """returns the dict that contains all the information"""
        return self.clouds

    #
    # important print methods
    #
    # includes sanitizing to remove the credentials
    #

    def __str__(self):
        tmp = self._sanitize()
        print tmp

    def _sanitize(self):
        # copy the self.cloud
        # delete the attributes called credential for all clouds
        all_keys = self.clouds.keys()
        for cloud in all_keys:
            self.clouds[cloud]['credential'] = {}
        return self.clouds

    def dump(self):
        tmp = self._sanitize()
        print json.dumps(tmp, indent=4)

    #
    # the refresh method that gets upto date information for cloudmesh
    # If cloudname is provided only that cloud will be refreshed
    # else all the clouds will be refreshed
    #

    def refresh(self, cloudname=None):
        print "Refershing cloudname %s" % cloudname
        servers = {}
        cloud = None

        if(cloudname is None):
            all_clouds = self.clouds.keys()
            for cloud_name in all_clouds:
                try:
                    type = self.clouds[cloud_name]['cm_type']

                    if type == 'openstack':
                        cloud = openstack(cloud_name)

                    elif type == 'eucalyptus':
                        # Where do i find the project name ? Is there a defaul
                        # one ?
                        cloud = eucalyptus(cloud_name, 'fg-82')

                    elif type == 'azure':
                        cloud = azure.cm_azure()

                    cloud.refresh()
                    self.clouds[cloud_name]['flavors'] = cloud.flavors
                    self.clouds[cloud_name]['images'] = cloud.images
                    self.clouds[cloud_name]['servers'] = cloud.servers

                except Exception, e:
                    print e
        else:
예제 #5
0
class metrics:

    #
    # global variables that define the information managed by this class
    #

    # dict that holds vms, flavors, images for al iaas
    clouds = {}

    # array with keys from the user
    keys = []

    #
    # variables that we can most likely eliminate
    #

    # user needs to come from credential ...
    user = "******"

    #
    # initialization methods
    #

    def __init__(self):
        self.clear()
        # Read Yaml File to find all the cloud configurations present
        self.config()
        try:
            self.metric_api = FGMetricsAPI()
        except:
            pass

    def clear(self):
        self.clouds = {}
        self.keys = []
        self.user = "******"

    #
    # some metric methods
    #

    def get_metrics_cli(self, args):
        """ Get usage data from FG Metric CLI"""
        """ This is replica with get_metrics but using CLI instead of API """
        """
            Args:
                args (dict): parameters for CLI with option
            Return:
                (dict): output of fgmetric in a dict type
            Raise:
                n/a
        """
        try:
            res = fgmetric(
                args
            )  # args should be list-lized before send it out as a parameter
            return json.loads(res, object_hook=json_util.object_hook)
        except:
            pass

    def get_metrics(self, args):
        """Get usage data from FG Metrics"""

        if not self.metric_api:
            return

        try:
            args["user"] = args["user"] or self.user
            self._set_metric_api_vars(args)
            # print args
            stats = self.metric_api._set_dict_vars()
            metrics = self.metric_api.get_stats()
            stats["stats"] = metrics
            self.metrics = stats
            # print self.metrics
        except:
            print sys.exc_info()
            pass
        return self.metrics

    def get_realtime_metrics(self, args):
        """ get real-time usage data from FG Metrics"""

        # IN DEVELOPMENT
        if not self.metric_api:
            return

        try:
            print 1
        except:
            pass

    def _set_metric_api_vars(self, args):
        self.metric_api.set_date(args["s_date"], args["e_date"])
        self.metric_api.set_metric(
            "count runtime cores mem disks")  # args["metric"])
        self.metric_api.set_user(args["user"])
        self.metric_api.set_cloud(args["cloud"])
        self.metric_api.set_hostname(args["host"])
        self.metric_api.set_period(args["period"])

    #
    # the configuration method that must be called to get the cloud info
    #

    def config(self):
        """
        reads the cloudmesh yaml file that defines which clouds build
        the cloudmesh
        """

        configuration = cm_config()
        pp.pprint(configuration)

        for cloud_name in configuration.keys():
            print "--------------------"

            try:
                credential = configuration.get(key=cloud_name)
                cloud_type = credential['cm_type']

                print credential

                print ">>>>>>>", cloud_name, cloud_type

                if cloud_type in ['openstack', 'eucalyptus']:
                    print "AAAAA"
                    self.clouds[cloud_name] = {
                        'cm_type': cloud_type,
                        'credential': credential
                    }
                    print "BBBB"
                    try:
                        self.update(cloud_name, cloud_type)
                        self.clouds[cloud_name] = {
                            'cm_type': cloud_type,
                            'credential': credential
                        }
                    except:
                        print "ERROR: can not connect to", cloud_name
                    print "CCCC"

            except Exception, e:
                print "ERROR: Not a cloud:", cloud_name, e
        return