當前位置: 首頁>>代碼示例>>Python>>正文


Python CONFIG.get方法代碼示例

本文整理匯總了Python中sm.config.CONFIG.get方法的典型用法代碼示例。如果您正苦於以下問題:Python CONFIG.get方法的具體用法?Python CONFIG.get怎麽用?Python CONFIG.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在sm.config.CONFIG的用法示例。


在下文中一共展示了CONFIG.get方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_service_credentials

# 需要導入模塊: from sm.config import CONFIG [as 別名]
# 或者: from sm.config.CONFIG import get [as 別名]
    def get_service_credentials(self):
        token = CONFIG.get('service_manager_admin', 'service_token', '')
        if token == '':
            raise Exception('No service_token parameter supplied in sm.cfg')
        tenant_name = CONFIG.get('service_manager_admin', 'service_tenant_name', '')
        if tenant_name == '':
            raise Exception('No tenant_name parameter supplied in sm.cfg')

        return token, tenant_name
開發者ID:AleDanish,項目名稱:sm-0.4,代碼行數:11,代碼來源:service.py

示例2: get_service_credentials

# 需要導入模塊: from sm.config import CONFIG [as 別名]
# 或者: from sm.config.CONFIG import get [as 別名]
    def get_service_credentials(self):
        token = CONFIG.get("service_manager_admin", "service_token", "")
        if token == "":
            raise Exception("No service_token parameter supplied in sm.cfg")
        tenant_name = CONFIG.get("service_manager_admin", "service_tenant_name", "")
        if tenant_name == "":
            raise Exception("No tenant_name parameter supplied in sm.cfg")

        return token, tenant_name
開發者ID:MobileCloudNetworking,項目名稱:dssaas,代碼行數:11,代碼來源:service.py

示例3: run

# 需要導入模塊: from sm.config import CONFIG [as 別名]
# 或者: from sm.config.CONFIG import get [as 別名]
    def run(self):
        LOG.debug("running retrieve")
        self.start_time = time.time()
        infoDict = {
                    'sm_name': self.entity.kind.term,
                    'phase': 'retrieve',
                    'phase_event': 'start',
                    'response_time': 0,
                    }
        LOG.debug(json.dumps(infoDict))
        self.entity.attributes['mcn.service.state'] = 'retrieve'

        argument = {
            'design_uri': CONFIG.get('service_manager', 'design_uri', ''),
            'username': self.entity.attributes['icclab.disco.deployer.username'],
            'tenant_name': self.extras['tenant_name'],
            'password': self.entity.attributes['icclab.disco.deployer.password'],
            'stack_name': 'disco_' + str(uuid.uuid1()),
            'region': self.entity.attributes['icclab.disco.deployer.region'],
            'token': self.extras['token']
            }
        deployer = OpenstackDeployer(argument)

        framework_directory = CONFIG.get('disco','framework_directory','')

        disco_config = {"deployer": deployer, "framework_directory": framework_directory, "root_component": "heat", "root_component_state": "end"}
        discoinst = OpenstackDisco(disco_config, self.entity.attributes)

        if 'stackid' in self.entity.attributes and \
            self.entity.attributes['stackid'] is not "":
            stackinfo = discoinst.retrieve(self.entity.attributes['stackid'])
            try:
                for output in stackinfo:
                    if output['output_value'] == None:
                        output['output_value'] = ""
                    self.entity.attributes[output['output_key']] = output['output_value']
                current_stack = deployer.hc.stacks.get(                    self.entity.attributes['stackid'])
                self.entity.attributes['stack_status'] = copy.deepcopy(                    current_stack.stack_status)

            except:
                self.entity.attributes['external_ip'] = 'none'
        else:
            self.entity.attributes['disco_status'] = 'nothing here right now'

        # this has to be done because Hurtle doesn't convert a multiline string into a valid JSON
        if "ssh_private_key" in self.entity.attributes:
            self.entity.attributes["ssh_private_key"] = self.entity.attributes["ssh_private_key"].replace("\n","\\n")

        return self.entity, self.extras
開發者ID:icclab,項目名稱:disco,代碼行數:51,代碼來源:hurtledisco.py

示例4: run

# 需要導入模塊: from sm.config import CONFIG [as 別名]
# 或者: from sm.config.CONFIG import get [as 別名]
    def run(self):
        self.app.register_backend(self.srv_type, self.service_backend)

        if self.reg_srv:
            self.register_service()

        # setup shutdown handler for de-registration of service
        for sig in [signal.SIGTERM, signal.SIGINT, signal.SIGHUP, signal.SIGQUIT]:
            signal.signal(sig, self.shutdown_handler)

        up = urlparse(self.stg["service_endpoint"])
        dep_port = CONFIG.get("general", "port")
        if dep_port != "":
            LOG.warn(
                "DEPRECATED: parameter general: port in service manager config. "
                "Service port number (" + str(up.port) + ") is taken from the service manifest"
            )

        if self.DEBUG:
            from wsgiref.simple_server import make_server

            httpd = make_server("", int(up.port), self.app)
            httpd.serve_forever()
        else:
            container = wsgi.WSGIContainer(self.app)
            http_server = httpserver.HTTPServer(container)
            http_server.listen(int(up.port))
            ioloop.IOLoop.instance().start()

        LOG.info("Service Manager running on interfaces, running on port: " + int(up.port))
開發者ID:MobileCloudNetworking,項目名稱:dssaas,代碼行數:32,代碼來源:service.py

示例5: run

# 需要導入模塊: from sm.config import CONFIG [as 別名]
# 或者: from sm.config.CONFIG import get [as 別名]
    def run(self):
        self.app.register_backend(self.srv_type, self.service_backend)

        if self.reg_srv:
            self.register_service()

            # setup shutdown handler for de-registration of service
            for sig in [signal.SIGTERM, signal.SIGINT, signal.SIGHUP, signal.SIGQUIT]:
                signal.signal(sig, self.shutdown_handler)

        up = urlparse(self.stg['service_endpoint'])
        dep_port = CONFIG.get('general', 'port')
        if dep_port != '':
            LOG.warn('DEPRECATED: parameter general: port in service manager config. '
                     'Service port number (' + str(up.port) + ') is taken from the service manifest')

        if self.DEBUG:
            LOG.debug('Using WSGI reference implementation')
            httpd = make_server('', int(up.port), self.app)
            httpd.serve_forever()
        else:
            LOG.debug('Using tornado implementation')
            container = wsgi.WSGIContainer(self.app)
            http_server = httpserver.HTTPServer(container)
            http_server.listen(int(up.port))
            ioloop.IOLoop.instance().start()

        LOG.info('Service Manager running on interfaces, running on port: ' + str(up.port))
開發者ID:AleDanish,項目名稱:sm-0.4,代碼行數:30,代碼來源:service.py

示例6: __deploy_app

# 需要導入模塊: from sm.config import CONFIG [as 別名]
# 或者: from sm.config.CONFIG import get [as 別名]
    def __deploy_app(self):
        """
            Deploy the local SO bundle
            assumption here
            - a git repo is returned
            - the bundle is not managed by git
        """
        # create temp dir...and clone the remote repo provided by OpS
        tmp_dir = tempfile.mkdtemp()
        LOG.debug('Cloning git repository: ' + self.repo_uri + ' to: ' + tmp_dir)
        cmd = ' '.join(['git', 'clone', self.repo_uri, tmp_dir])
        os.system(cmd)

        # Get the SO bundle
        bundle_loc = CONFIG.get('service_manager', 'bundle_location', '')
        if bundle_loc == '':
            raise Exception('No bundle_location parameter supplied in sm.cfg')
        LOG.debug('Bundle to add to repo: ' + bundle_loc)
        dir_util.copy_tree(bundle_loc, tmp_dir)

        self.__add_openshift_files(bundle_loc, tmp_dir)

        # add & push to OpenShift
        os.system(' '.join(['cd', tmp_dir, '&&', 'git', 'add', '-A']))
        os.system(' '.join(['cd', tmp_dir, '&&', 'git', 'commit', '-m', '"deployment of SO for tenant ' +
                            self.extras['tenant_name'] + '"', '-a']))
        LOG.debug('Pushing new code to remote repository...')
        os.system(' '.join(['cd', tmp_dir, '&&', 'git', 'push']))

        shutil.rmtree(tmp_dir)
開發者ID:AleDanish,項目名稱:sm-0.4,代碼行數:32,代碼來源:so_manager.py

示例7: __init__

# 需要導入模塊: from sm.config import CONFIG [as 別名]
# 或者: from sm.config.CONFIG import get [as 別名]
    def __init__(self):
        try:
            # added try as many sm.cfg still have no mongo section
            mongo_addr = CONFIG.get('mongo', 'host', None)
        except NoSectionError:
            mongo_addr = None

        sm_name = os.environ.get('SM_NAME', 'SAMPLE_SM')
        mongo_service_name = sm_name.upper().replace('-', '_')

        db_host_key = mongo_service_name + '_MONGO_SERVICE_HOST'
        db_port_key = mongo_service_name + '_MONGO_SERVICE_PORT'
        db_host = os.environ.get(db_host_key, False)
        db_port = os.environ.get(db_port_key, False)
        db_user = os.environ.get('DB_USER', False)
        db_password = os.environ.get('DB_PASSWORD', False)

        if db_host and db_port and db_user and db_password:
            mongo_addr = 'mongodb://%s:%[email protected]%s:%s' % (db_user, db_password, db_host, db_port)

        if mongo_addr is None:
            reg = SMRegistry()
        else:
            reg = SMMongoRegistry(mongo_addr)
        super(MApplication, self).__init__(reg)

        self.register_backend(Link.kind, KindBackend())
開發者ID:Pentadactylus,項目名稱:sm_openstack,代碼行數:29,代碼來源:service.py

示例8: __init__

# 需要導入模塊: from sm.config import CONFIG [as 別名]
# 或者: from sm.config.CONFIG import get [as 別名]
 def __init__(self, entity, extras):
     Task.__init__(self, entity, extras, state='destroy')
     if self.entity.extras['ops_version'] == 'v2':
         self.repo_uri = self.entity.extras['repo_uri']
         self.host = urlparse(self.repo_uri).netloc.split('@')[1]
     elif self.entity.extras['ops_version'] == 'v3':
         self.host = self.entity.extras['loc']
     self.nburl = CONFIG.get('cloud_controller', 'nb_api', '')
開發者ID:AleDanish,項目名稱:sm-0.4,代碼行數:10,代碼來源:so_manager.py

示例9: __init__

# 需要導入模塊: from sm.config import CONFIG [as 別名]
# 或者: from sm.config.CONFIG import get [as 別名]
    def __init__(self, app, srv_type=None):
        # openstack objects tracking the keystone service and endpoint
        self.srv_ep = None
        self.ep = None
        self.DEBUG = True

        self.app = app
        self.service_backend = ServiceBackend(app)
        LOG.info("Using configuration file: " + CONFIG_PATH)

        self.token, self.tenant_name = self.get_service_credentials()
        self.design_uri = CONFIG.get("service_manager", "design_uri", "")
        if self.design_uri == "":
            LOG.fatal("No design_uri parameter supplied in sm.cfg")
            raise Exception("No design_uri parameter supplied in sm.cfg")

        self.stg = None
        stg_path = CONFIG.get("service_manager", "manifest", "")
        if stg_path == "":
            raise RuntimeError("No STG specified in the configuration file.")
        with open(stg_path) as stg_content:
            self.stg = json.load(stg_content)
            stg_content.close()

        if not srv_type:
            srv_type = self.create_service_type()
        self.srv_type = srv_type

        self.reg_srv = CONFIG.getboolean("service_manager_admin", "register_service")
        if self.reg_srv:
            self.region = CONFIG.get("service_manager_admin", "region", "")
            if self.region == "":
                LOG.info("No region parameter specified in sm.cfg, defaulting to an OpenStack default: RegionOne")
                self.region = "RegionOne"
            self.service_endpoint = CONFIG.get("service_manager_admin", "service_endpoint")
            if self.service_endpoint != "":
                LOG.warn(
                    "DEPRECATED: service_endpoint parameter supplied in sm.cfg! Endpoint is now specified in "
                    "service manifest as service_endpoint"
                )
            LOG.info(
                "Using " + self.stg["service_endpoint"] + " as the service_endpoint value " "from service manifest"
            )
            up = urlparse(self.stg["service_endpoint"])
            self.service_endpoint = up.scheme + "://" + up.hostname + ":" + str(up.port)
開發者ID:MobileCloudNetworking,項目名稱:dssaas,代碼行數:47,代碼來源:service.py

示例10: config_logger

# 需要導入模塊: from sm.config import CONFIG [as 別名]
# 或者: from sm.config.CONFIG import get [as 別名]
def config_logger(log_level=logging.DEBUG):
    logging.basicConfig(format='%(levelname)s %(asctime)s: \t%(message)s',
                        datefmt='%m/%d/%Y %I:%M:%S %p',
                        log_level=log_level)
    logger = logging.getLogger(__name__)
    logger.setLevel(log_level)

    if CONFIG.get('general', 'log_file', '') != '':
        hdlr = logging.FileHandler(CONFIG.get('general', 'log_file', ''))
        formatter = logging.Formatter(fmt='%(levelname)s %(asctime)s: %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p')
        hdlr.setFormatter(formatter)
        logger.addHandler(hdlr)

    if CONFIG.get('general', 'graylog_api', '') != '' and CONFIG.get('general', 'graylog_port', '') != '':
        gray_handler = graypy.GELFHandler(CONFIG.get('general', 'graylog_api', ''), CONFIG.getint('general', 'graylog_port'))
        logger.addHandler(gray_handler)

    return logger
開發者ID:AleDanish,項目名稱:sm-0.4,代碼行數:20,代碼來源:log.py

示例11: __init__

# 需要導入模塊: from sm.config import CONFIG [as 別名]
# 或者: from sm.config.CONFIG import get [as 別名]
    def __init__(self, app, srv_type=None):
        # openstack objects tracking the keystone service and endpoint
        self.srv_ep = None
        self.ep = None
        self.DEBUG = True

        self.app = app
        self.service_backend = ServiceBackend(app)
        LOG.info('Using configuration file: ' + CONFIG_PATH)

        self.token, self.tenant_name = self.get_service_credentials()
        self.design_uri = CONFIG.get('service_manager', 'design_uri', '')
        if self.design_uri == '':
                LOG.fatal('No design_uri parameter supplied in sm.cfg')
                raise Exception('No design_uri parameter supplied in sm.cfg')

        self.stg = None
        stg_path = CONFIG.get('service_manager', 'manifest', '')
        if stg_path == '':
            raise RuntimeError('No STG specified in the configuration file.')
        with open(stg_path) as stg_content:
            self.stg = json.load(stg_content)
            stg_content.close()

        if not srv_type:
            srv_type = self.create_service_type()
        self.srv_type = srv_type

        self.reg_srv = CONFIG.getboolean('service_manager_admin', 'register_service')
        if self.reg_srv:
            self.region = CONFIG.get('service_manager_admin', 'region', '')
            if self.region == '':
                LOG.info('No region parameter specified in sm.cfg, defaulting to an OpenStack default: RegionOne')
                self.region = 'RegionOne'
            self.service_endpoint = CONFIG.get('service_manager_admin', 'service_endpoint')
            if self.service_endpoint != '':
                LOG.warn('DEPRECATED: service_endpoint parameter supplied in sm.cfg! Endpoint is now specified in '
                         'service manifest as service_endpoint')
            LOG.info('Using ' + self.stg['service_endpoint'] + ' as the service_endpoint value '
                                                               'from service manifest')
            up = urlparse(self.stg['service_endpoint'])
            
            self.service_endpoint = up.scheme + '://' + up.hostname + ':' + str(up.port) + '/' + str('mobaas')
	    LOG.info(self.service_endpoint)
開發者ID:MobileCloudNetworking,項目名稱:mobaas,代碼行數:46,代碼來源:service.py

示例12: __init__

# 需要導入模塊: from sm.config import CONFIG [as 別名]
# 或者: from sm.config.CONFIG import get [as 別名]
    def __init__(self):
        try:
            # added try as many sm.cfg still have no mongo section
            mongo_addr = CONFIG.get('mongo', 'host', None)
        except NoSectionError:
            mongo_addr = None

        if mongo_addr is None:
            reg = SMRegistry()
        else:
            reg = SMMongoRegistry(mongo_addr)
        super(MApplication, self).__init__(reg)

        self.register_backend(Link.kind, KindBackend())
開發者ID:AleDanish,項目名稱:sm-0.4,代碼行數:16,代碼來源:service.py

示例13: getOrchestrator

# 需要導入模塊: from sm.config import CONFIG [as 別名]
# 或者: from sm.config.CONFIG import get [as 別名]
    def getOrchestrator( extras ):

        # first, a connection to keystone has to be established in order to load the service catalog for the orchestration endpoint (heat)
        # the design_uri has to be given in the sm.cfg file so that no other OpenStack deployment can be used
        kc = keystoneclient.Client(auth_url=CONFIG.get('service_manager','design_uri',''),
                                   username=extras['username'],
                                   password=extras['password'],
                                   tenant_name=extras['tenant_name']
                                   )

        # get the orchestration part of the service catalog
        orch = kc.service_catalog.get_endpoints(service_type='orchestration',
                                                region_name=extras['region'],
                                                endpoint_type='publicURL'
                                                )

        # create a heat client with acquired public endpoint
        # if the correct region had been given, there is supposed to be but one entry for the orchestrator URLs
        hc = heatclient.Client(HEAT_VERSION, endpoint=orch['orchestration'][0]['publicURL'],token=kc.auth_token)
        return hc
開發者ID:Pentadactylus,項目名稱:sm_openstack,代碼行數:22,代碼來源:openstack_so_manager.py

示例14: get_deployer

# 需要導入模塊: from sm.config import CONFIG [as 別名]
# 或者: from sm.config.CONFIG import get [as 別名]
    def get_deployer(arguments, extras):
        attributes = {}
        # the HTTP parameters starting with icclab.disco.deployer. will be
        # handled here
        for key, value in arguments.iteritems():
            if key.startswith("icclab.disco.deployer."):
                attributes[key.replace("icclab.disco.deployer.","")] = value

        # icclab.disco.deployer.type contains the deployer type
        if "type" in attributes:
            if attributes["type"]=="FileDeployer":
                return FileDeployer(attributes)

        # default case: OpenstackDeployer (if no deployer is mentioned)
        attributes["design_uri"] = CONFIG.get('service_manager', 'design_uri',
                                              '')
        attributes["token"] = extras["token"]
        attributes["stack_name"] = 'disco_' + str(uuid.uuid1())
        attributes["tenant_name"] = extras["tenant_name"]
        return OpenstackDeployer(attributes)
開發者ID:icclab,項目名稱:disco,代碼行數:22,代碼來源:hurtledisco.py

示例15: __call__

# 需要導入模塊: from sm.config import CONFIG [as 別名]
# 或者: from sm.config.CONFIG import get [as 別名]
    def __call__(self, environ, response):
        token = environ.get('HTTP_X_AUTH_TOKEN', '')

        # design_uri is needed for the case that no token was given
        design_uri = CONFIG.get('service_manager', 'design_uri', '')
        if design_uri == '':
                LOG.fatal('No design_uri parameter supplied in sm.cfg')
                raise Exception('No design_uri parameter supplied in sm.cfg')
        tenantname = environ.get('HTTP_X_TENANT_NAME', '')
        region = environ.get('HTTP_X_REGION_NAME','')
        username = environ.get('HTTP_X_USER_NAME','')
        password = environ.get('HTTP_X_PASSWORD','')

        # for checking the authenticity
        auth = KeyStoneAuthService(design_uri)

        # get the token from username, tenant and region combination from HTTP
        # headers
        if token is '':
            try:
                # get all the required variables - as the tenant name has a
                # special role, it's queried separately

                kc = client.Client(auth_url=design_uri,
                                   username=username,
                                   password=password,
                                   tenant_name=tenantname
                                   )
                environ['HTTP_X_AUTH_TOKEN'] = kc.auth_token
                token = kc.auth_token
            except:
                raise Exception('Either no design uri, username, '
                                'password, or tenant name respectively '
                                'provided or the login didn\'t succeed')
        else:
            if not auth.verify(token=token, tenant_name=tenantname):
                LOG.error('Token has probably expired')
                raise HTTPError(401, 'Token is not valid. You likely need an updated token.')

        # the arguments at the back will become the extras variable within the individual SM classes
        return self._call_occi(environ, response, username=username, design_uri=design_uri, password=password, token=token, tenant_name=tenantname, registry=self.registry, region=region)
開發者ID:Pentadactylus,項目名稱:sm_openstack,代碼行數:43,代碼來源:service.py


注:本文中的sm.config.CONFIG.get方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。