Beispiel #1
0
    def __init__(self, host=None, header_name=None, header_value=None, cookie=None):

        """
        Constructor of the class.
        """
        self.rest_client = RESTClientObject()
        self.default_headers = {}
        if header_name is not None:
            self.default_headers[header_name] = header_value
        if host is None:
            config = ServiceContext().getConfigService()
            self.host = config.get("DSO","url")
        else:
            self.host = host
        self.cookie = cookie
        # Set default User-Agent.
        self.user_agent = 'Python-Swagger/1.0.0'
Beispiel #2
0
 def __init__(self,
              host=None,
              header_name=None,
              header_value=None,
              cookie=None):
     """
     Constructor of the class.
     """
     self.rest_client = RESTClientObject()
     self.default_headers = {}
     if header_name is not None:
         self.default_headers[header_name] = header_value
     if host is None:
         config = ServiceContext().getConfigService()
         self.host = config.get("DSO", "url")
     else:
         self.host = host
     self.cookie = cookie
     # Set default User-Agent.
     self.user_agent = 'Python-Swagger/1.0.0'
Beispiel #3
0
    def _buildcontext(cls,tenant):
        """
        build {svc:context}
        :param tenant:
        :return:
        """
        svclist = tenant.services
        modelmgr = ModelManager()
        svcmap = {}
        context = {}
        config = ServiceContext().getConfigService()
        tenant_path = os.path.join(config.get("File","local_temp_path"),tenant.id)
        items = config.items("Agent")
        paras = {}
        for key,value in items:
            paras[key] = value

        for svc in svclist:
            svcmap[svc.name] = svc
            context[svc.name] = {}

        for svc in svclist:
            if svc.name == "vpc":
                logger.info("build sa jobs--skip the vpc")
                continue
            svcdef = modelmgr.getsvfdefbyname(svc.name)
            sn = svcdef.service_neighbors
            mn = svcdef.manage_neighbors
            global_para = paras.copy()
            if config.has_section(svc.name):
                items = config.items(svc.name)
                for key,value in items:
                    global_para[key] = value
            ctx = context[svc.name]
            ctx["neighbors_manageip"] = []
            ctx["neighbors_serviceip"] = []
            ctx["account_id"] = tenant.id
            ctx.update(global_para)
            instances = svc.nodes
            for instance in instances:
                ctx["host_name"] = instance.manageip
                ctx["vm_type"] = svc.name
                node_path = os.path.join(tenant_path,instance.manageip)
                if not os.path.exists(node_path):
                    os.makedirs(node_path)
                ctx["node_temp_home"] = node_path

            for nb in sn:
                corrresponding_svc = svcmap[nb]
                nodes = corrresponding_svc.nodes
                for node in nodes:
                    if node.serviceip is not None:
                         ctx["neighbors_serviceip"].append(node.serviceip)

            for nb in mn:
                corrresponding_svc = svcmap[nb]
                nodes = corrresponding_svc.nodes
                for node in nodes:
                    ctx["neighbors_manageip"].append(node.manageip)

            ctx["neighbors_manageip"] = ",".join(ctx["neighbors_manageip"])
            ctx["neighbors_serviceip"] = ",".join(ctx["neighbors_serviceip"])

            ctx["os"] = svcdef.os

        return context
Beispiel #4
0
 def __init__(self):
     config = ServiceContext().getConfigService()
     self.zk_address = config.get("Inventory", "zk_address")
     self.root_path = config.get("Inventory", "zk_root_path")
     self.zk_client = KazooClient(hosts=self.zk_address)
Beispiel #5
0
 def _initializeSession(self):
     config = ServiceContext().getConfigService()
     db_url = config.get("DB","mysql_url")
     engine = create_engine(db_url)
     self.sessionmaker = sessionmaker(bind=engine)
     self.session = self.sessionmaker()
Beispiel #6
0
 def __init__(self):
     config = ServiceContext().getConfigService()
     self.zk_address = config.get("Inventory","zk_address")
     self.root_path = config.get("Inventory","zk_root_path")
     self.zk_client = KazooClient(hosts=self.zk_address)
Beispiel #7
0
 def __init__(self):
     config = ServiceContext().getConfigService()
     self.remote_path_base = config.get("File","remote_path")
Beispiel #8
0
    def _buildcontext(cls, tenant):
        """
        build {svc:context}
        :param tenant:
        :return:
        """
        svclist = tenant.services
        modelmgr = ModelManager()
        svcmap = {}
        context = {}
        config = ServiceContext().getConfigService()
        tenant_path = os.path.join(config.get("File", "local_temp_path"),
                                   tenant.id)
        items = config.items("Agent")
        paras = {}
        for key, value in items:
            paras[key] = value

        for svc in svclist:
            svcmap[svc.name] = svc
            context[svc.name] = {}

        for svc in svclist:
            if svc.name == "vpc":
                logger.info("build sa jobs--skip the vpc")
                continue
            svcdef = modelmgr.getsvfdefbyname(svc.name)
            sn = svcdef.service_neighbors
            mn = svcdef.manage_neighbors
            global_para = paras.copy()
            if config.has_section(svc.name):
                items = config.items(svc.name)
                for key, value in items:
                    global_para[key] = value
            ctx = context[svc.name]
            ctx["neighbors_manageip"] = []
            ctx["neighbors_serviceip"] = []
            ctx["account_id"] = tenant.id
            ctx.update(global_para)
            instances = svc.nodes
            for instance in instances:
                ctx["host_name"] = instance.manageip
                ctx["vm_type"] = svc.name
                node_path = os.path.join(tenant_path, instance.manageip)
                if not os.path.exists(node_path):
                    os.makedirs(node_path)
                ctx["node_temp_home"] = node_path

            for nb in sn:
                corrresponding_svc = svcmap[nb]
                nodes = corrresponding_svc.nodes
                for node in nodes:
                    if node.serviceip is not None:
                        ctx["neighbors_serviceip"].append(node.serviceip)

            for nb in mn:
                corrresponding_svc = svcmap[nb]
                nodes = corrresponding_svc.nodes
                for node in nodes:
                    ctx["neighbors_manageip"].append(node.manageip)

            ctx["neighbors_manageip"] = ",".join(ctx["neighbors_manageip"])
            ctx["neighbors_serviceip"] = ",".join(ctx["neighbors_serviceip"])

            ctx["os"] = svcdef.os

        return context
Beispiel #9
0
 def __init__(self):
     config = ServiceContext().getConfigService()
     self.remote_path_base = config.get("File", "remote_path")