def __init__(self):
     LOG.debug("Starting RuntimeAgent.")
     # Get monitor name and service
     conf = SysUtil().get_sys_conf()
     monitor_name = conf.get('monitoring')
     self.monitoring_service = FactoryAgent.get_agent(monitor_name)
     self.policy_threads = {}
     self.heat_client = HeatClient()
     self.checker_threads = {}
Beispiel #2
0
    def __init__(self, conf=None):
        if not conf:
            from util.SysUtil import SysUtil

            self.conf = SysUtil().get_sys_conf()
        else:
            self.conf = conf
        self.nova = client.Client('2', self.conf['os_username'], self.conf['os_password'], self.conf['os_tenant'],
                                  self.conf['os_auth_url'], region_name=self.conf['os_region_name'])
Beispiel #3
0
class Client:
    def __init__(self, conf=None):
        if not conf:
            from util.SysUtil import SysUtil

            self.conf = SysUtil().get_sys_conf()
        else:
            self.conf = conf
        self.nova = client.Client('2', self.conf['os_username'], self.conf['os_password'], self.conf['os_tenant'],
                                  self.conf['os_auth_url'], region_name=self.conf['os_region_name'])

    def list_servers(self):
        res = self.nova.servers.list()
        for s in res:
            logger.debug(s)
            for k, v in s.networks.iteritems():
                for ip in v:
                    try:
                        logger.debug(self.get_floating_ip(ip))
                    except:
                        continue

    def get_floating_ip(self, ip):
        res = self.nova.floating_ips.list()
        for _fip in res:
            if _fip.ip == ip:
                return _fip
        raise NotFoundException("Floating ip " + ip + " not found")

    def get_floating_ips(self):
        res = self.nova.floating_ips.list()
        return res

    def set_ips(self, unit):
        for k, v in self.nova.servers.get(unit.ext_id).networks.iteritems():
            for ip in v:
                try:
                    unit.floating_ips[k] = self.get_floating_ip(ip).ip
                    logger.debug(ip + " is a floating ip")
                except NotFoundException as e:
                    unit.ips[k] = ip
                    logger.debug(ip + " is a fixed ip")
        logger.debug("ips: " + str(unit.ips))
        logger.debug("floating_ips: " + str(unit.floating_ips))

    def get_images(self, object=True):
        images_repr = self.nova.images.list()
        images = []
        for image_repr in images_repr:
            if object:
                images.append(Image(name=image_repr.name, ext_id=image_repr.id, status=image_repr.status,
                                    created=image_repr.created, updated=image_repr.updated))
            else:
                images.append(image_repr._info)
        return images

    def get_flavors(self, object=True):
        flavors_repr = self.nova.flavors.list()
        flavors = []
        for flavor_repr in flavors_repr:
            if object:
                flavors.append(Flavor(name=flavor_repr.name, ram=flavor_repr.ram, vcpus=flavor_repr.vcpus))
            else:
                flavors.append(flavor_repr._info)
        return flavors

    def get_keys(self, object=True):
        keys_repr = self.nova.keypairs.list()
        keys = []
        for key_repr in keys_repr:
            if object:
                keys.append(Key(name=(key_repr.name)))
            else:
                keys.append(key_repr._info)
        return keys

    def get_quotas(self, object=True):
        quotas_repr = self.nova.quotas.get(tenant_id=self.conf.get('os_tenant'))
        if object:
            quotas = (Quotas(**quotas_repr._info))
        else:
            quotas = (quotas_repr._info)
        return quotas
import os
from util.SysUtil import SysUtil
import logging


__author__ = 'lto'

PATH = os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir))


if __name__ == '__main__':
    logging.basicConfig(format='%(asctime)s_%(process)d:%(pathname)s:%(lineno)d [%(levelname)s] %(message)s',level=logging.DEBUG)
    logger = logging.getLogger("EMMLogger")
    handler = logging.FileHandler('%s/logs/%s.log' % (PATH, os.path.basename(__file__)))
    handler.setLevel(logging.DEBUG)
    formatter = logging.Formatter('%(asctime)s_%(process)d:%(pathname)s:%(lineno)d [%(levelname)s] %(message)s')
    handler.setFormatter(formatter)
    logger.addHandler(handler)
    sys_util = SysUtil()
    sys_util.init_sys()

    print sys_util.get_sys_conf().props;