本文整理汇总了Python中sm.config.CONFIG类的典型用法代码示例。如果您正苦于以下问题:Python CONFIG类的具体用法?Python CONFIG怎么用?Python CONFIG使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CONFIG类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_service_credentials
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
示例2: get_service_credentials
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
示例3: run
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
示例4: run
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))
示例5: run
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))
示例6: __deploy_app
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)
示例7: __init__
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())
示例8: __init__
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', '')
示例9: __init__
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)
示例10: __init__
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)
示例11: __init__
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())
示例12: getOrchestrator
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
示例13: get_deployer
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)
示例14: __call__
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)
示例15: __extract_public_key
def __extract_public_key(self):
ssh_key_file = CONFIG.get('service_manager', 'ssh_key_location', '')
if ssh_key_file == '':
raise Exception('No ssh_key_location parameter supplied in sm.cfg')
LOG.debug('Using SSH key file: ' + ssh_key_file)
with open(ssh_key_file, 'r') as content_file:
content = content_file.read()
content = content.split()
if content[0] == 'ssh-dsa':
raise Exception("The supplied key is not a RSA ssh key. Location: " + ssh_key_file)
key_content = content[1]
key_name = 'servicemanager'
if len(content) == 3:
key_name = content[2]
return key_name, key_content