本文整理汇总了Python中sm.config.CONFIG类的典型用法代码示例。如果您正苦于以下问题:Python CONFIG类的具体用法?Python CONFIG怎么用?Python CONFIG使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CONFIG类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:MobileCloudNetworking,项目名称:dssaas,代码行数:9,代码来源:service.py
示例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
开发者ID:AleDanish,项目名称:sm-0.4,代码行数:9,代码来源:service.py
示例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
开发者ID:icclab,项目名称:disco,代码行数:49,代码来源:hurtledisco.py
示例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))
开发者ID:MobileCloudNetworking,项目名称:dssaas,代码行数:30,代码来源:service.py
示例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))
开发者ID:AleDanish,项目名称:sm-0.4,代码行数:28,代码来源:service.py
示例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)
开发者ID:AleDanish,项目名称:sm-0.4,代码行数:30,代码来源:so_manager.py
示例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())
开发者ID:Pentadactylus,项目名称:sm_openstack,代码行数:27,代码来源:service.py
示例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', '')
开发者ID:AleDanish,项目名称:sm-0.4,代码行数:8,代码来源:so_manager.py
示例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)
开发者ID:MobileCloudNetworking,项目名称:dssaas,代码行数:45,代码来源:service.py
示例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)
开发者ID:MobileCloudNetworking,项目名称:mobaas,代码行数:44,代码来源:service.py
示例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())
开发者ID:AleDanish,项目名称:sm-0.4,代码行数:14,代码来源:service.py
示例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
开发者ID:Pentadactylus,项目名称:sm_openstack,代码行数:20,代码来源:openstack_so_manager.py
示例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)
开发者ID:icclab,项目名称:disco,代码行数:20,代码来源:hurtledisco.py
示例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)
开发者ID:Pentadactylus,项目名称:sm_openstack,代码行数:41,代码来源:service.py
示例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
开发者ID:AleDanish,项目名称:sm-0.4,代码行数:21,代码来源:so_manager.py
示例16: __deploy_to_so
def __deploy_to_so(self):
# from this point on, the SO will be contacted in order to deploy the
# distributed computing cluster
heads = {
'X-Auth-Token':self.extras['token'],
'X-Tenant-Name':CONFIG.get('openstackso','tenantname'),
'Content-Type':'text/occi',
'Accept':'text/occi',
'Category':'orchestrator; scheme="http://schemas.mobile-cloud-networking.eu/occi/service#"'
}
# TODO: "http://" and / or port will result in a problem
r = requests.put("http://"+self.sofloatingip+':8080/orchestrator/default', headers=heads)
# everything that has to be changed in the head is the Category which
# is switched to deploy
heads['Category']='deploy; scheme="http://schemas.mobile-cloud-networking.eu/occi/service#"'
# the attributes for the SO have to be transferred to it as well
attributeString = ",".join("%s=\"%s\"" % (key,val) for (key,val) in self.entity.attributes.iteritems())
heads['X-OCCI-Attribute']=attributeString
# TODO: "http://" and / or port will result in a problem
r = requests.post("http://"+self.sofloatingip+':8080/orchestrator/default?action=deploy', headers=heads)
开发者ID:zioproto,项目名称:sm_openstack,代码行数:22,代码来源:openstack_so_manager.py
示例17: __add_openshift_files
def __add_openshift_files(self, bundle_loc, tmp_dir):
# put OpenShift stuff in place
# build and pre_start_python comes from 'support' directory in bundle
LOG.debug('Adding OpenShift support files from: ' + bundle_loc + '/support')
# 1. Write build
LOG.debug('Writing build to: ' + os.path.join(tmp_dir, '.openshift', 'action_hooks', 'build'))
shutil.copyfile(bundle_loc+'/support/build', os.path.join(tmp_dir, '.openshift', 'action_hooks', 'build'))
# 1. Write pre_start_python
LOG.debug('Writing pre_start_python to: ' +
os.path.join(tmp_dir, '.openshift', 'action_hooks', 'pre_start_python'))
pre_start_template = Template(filename=bundle_loc+'/support/pre_start_python')
design_uri = CONFIG.get('service_manager', 'design_uri', '')
content = pre_start_template.render(design_uri=design_uri)
LOG.debug('Writing pre_start_python content as: ' + content)
pre_start_file = open(os.path.join(tmp_dir, '.openshift', 'action_hooks', 'pre_start_python'), "w")
pre_start_file.write(content)
pre_start_file.close()
os.system(' '.join(['chmod', '+x', os.path.join(tmp_dir, '.openshift', 'action_hooks', '*')]))
开发者ID:AleDanish,项目名称:sm-0.4,代码行数:22,代码来源:so_manager.py
示例18: __call__
def __call__(self, environ, response):
token = environ.get("HTTP_X_AUTH_TOKEN", "")
if token == "":
LOG.error("No X-Auth-Token header supplied.")
raise HTTPError(400, "No X-Auth-Token header supplied.")
tenant = environ.get("HTTP_X_TENANT_NAME", "")
if tenant == "":
LOG.error("No X-Tenant-Name header supplied.")
raise HTTPError(400, "No X-Tenant-Name header supplied.")
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")
auth = KeyStoneAuthService(design_uri)
if not auth.verify(token=token, tenant_name=tenant):
raise HTTPError(401, "Token is not valid. You likely need an updated token.")
return self._call_occi(environ, response, token=token, tenant_name=tenant, registry=self.registry)
开发者ID:MobileCloudNetworking,项目名称:dssaas,代码行数:23,代码来源:service.py
示例19: __call__
def __call__(self, environ, response):
token = environ.get('HTTP_X_AUTH_TOKEN', '')
if token == '':
LOG.error('No X-Auth-Token header supplied.')
raise HTTPError(400, 'No X-Auth-Token header supplied.')
tenant = environ.get('HTTP_X_TENANT_NAME', '')
if tenant == '':
LOG.error('No X-Tenant-Name header supplied.')
raise HTTPError(400, 'No X-Tenant-Name header supplied.')
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')
auth = KeyStoneAuthService(design_uri)
if not auth.verify(token=token, tenant_name=tenant):
raise HTTPError(401, 'Token is not valid. You likely need an updated token.')
return self._call_occi(environ, response, token=token, tenant_name=tenant, registry=self.registry)
开发者ID:AleDanish,项目名称:sm-0.4,代码行数:23,代码来源:service.py
示例20: config_logger
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,代码行数:18,代码来源:log.py
注:本文中的sm.config.CONFIG类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论