本文整理汇总了Python中stackone.core.utils.utils.to_str函数的典型用法代码示例。如果您正苦于以下问题:Python to_str函数的具体用法?Python to_str怎么用?Python to_str使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了to_str函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: set_transient_state
def set_transient_state(self, defn, transient_state, op, site_id=None, group_id=None, node_id=None):
scope = defn.scope
if op==constants.SCOPE_LEVEL:
if scope == constants.SCOPE_S:
def_link = DBSession.query(ServerDefLink).filter_by(server_id=node_id, def_id=defn.id).first()
else:
if scope == constants.SCOPE_SP:
def_link = DBSession.query(SPDefLink).filter_by(group_id=group_id, def_id=defn.id).first()
else:
if scope == constants.SCOPE_DC:
def_link = DBSession.query(DCDefLink).filter_by(site_id=site_id, def_id=defn.id).first()
if def_link:
if transient_state:
def_link.transient_state = to_unicode(transient_state)
else:
def_link.transient_state = None
LOGGER.info('Transient state of ' + to_str(defn.name) + ' is changed to ' + to_str(transient_state) + ' at definition scope level')
if op==constants.NODE_LEVEL:
def_link = DBSession.query(ServerDefLink).filter_by(server_id=node_id, def_id=defn.id).first()
if def_link:
if transient_state:
def_link.transient_state = to_unicode(transient_state)
else:
def_link.transient_state = None
LOGGER.info('Transient state of ' + to_str(defn.name) + ' is changed to ' + to_str(transient_state) + ' at node level')
开发者ID:smarkm,项目名称:ovm,代码行数:25,代码来源:SyncDefinition.py
示例2: associate_defns
def associate_defns(self, site_id, group_id, def_type, def_ids, auth, op_level=None):
error_desc = ''
site = self.manager.getSite(site_id)
group = self.manager.getGroup(auth, group_id)
group_list = self.manager.getGroupList(auth, site_id)
def_id_list = def_ids.split(',')
for def_id in def_id_list:
new_sd = DBSession.query(StorageDef).filter_by(id=def_id).first()
node = None
sp_ids = group_id
try:
self.sync_manager.add_defn(new_sd, site, group, node, auth, to_unicode(constants.STORAGE), constants.ATTACH, 'ADD_STORAGE_DEF', self.storage_manager, self.manager, op_level, sp_ids)
except Exception as ex:
error_desc = to_str(ex)
print_traceback()
LOGGER.error(to_str(ex).replace("'", ''))
add_mode = True
try:
self.sync_manager.remove_defn(new_sd, site, group, node, auth, to_unicode(constants.STORAGE), constants.DETACH, 'REMOVE_STORAGE_DEF', self.storage_manager, self.manager, add_mode, group_list, op_level)
except Exception as ex1:
print_traceback()
LOGGER.error(to_str(ex1).replace("'", ''))
raise Exception(to_str(ex1))
if error_desc:
raise Exception(error_desc)
return {'success':True,'msg':'Storage Added'}
开发者ID:smarkm,项目名称:ovm,代码行数:26,代码来源:StorageService.py
示例3: update_dc_params
def update_dc_params(self, res_id, fencing_name, fencing_id, params):
try:
params = json.loads(params).get('param_obj')
hafr = DBSession.query(HAFenceResource).filter(HAFenceResource.id == res_id).one()
hafr.name = fencing_name
params_list = []
for hp in hafr.params:
params_list.append(hp)
for i in range(len(params_list)):
hafr.params.remove(params_list[i])
for param in params:
name = param.get('attribute')
value = param.get('value')
type = param.get('type')
field = param.get('field')
field_datatype = param.get('field_datatype')
sequence = param.get('sequence')
harp = HAFenceResourceParam(name, value, type, field, field_datatype, sequence)
hafr.params.append(harp)
DBSession.add(hafr)
except Exception as ex:
print_traceback()
LOGGER.error(to_str(ex).replace("'", ''))
return ("{success: false,msg: '", to_str(ex).replace("'", ''), "'}")
return dict(success=True)
开发者ID:smarkm,项目名称:ovm,代码行数:28,代码来源:HAService.py
示例4: get_fw_info
def get_fw_info(self):
fw_main_data = []
LOGGER.info("Getting firewall rules info for all csep and Data Center...")
print "Getting firewall rules info for all csep and Data Center..."
sites = DBSession.query(Site)
if sites[0]:
LOGGER.info("Got the site. Site name is " + to_str(sites[0L].name))
site_id = sites[0L].id
site_name = sites[0L].name
nw_service_host = get_cms_network_service_node()
if nw_service_host:
fw = self.get_firewall(site_id)
fw.set_chain_name(site_name)
fw_data = self.dump(fw)
fw_main_data.append(fw_data)
csep_list = DBSession.query(CSEP)
for each_csep in csep_list:
LOGGER.info("Got the CSEP. CSEP name is " + to_str(each_csep.name))
nw_service_host = each_csep.get_nw_service_host()
if nw_service_host:
fw = self.get_firewall(each_csep.id)
fw.set_chain_name(each_csep.name)
fw_data = self.dump(fw)
fw_main_data.append(fw_data)
return fw_main_data
开发者ID:yangliang913,项目名称:ovm,代码行数:25,代码来源:FirewallManager.py
示例5: get_target_images
def get_target_images(self, auth, nodeId, imageGroupId):
try:
manager = Basic.getGridManager()
managed_node = manager.getNode(auth, nodeId)
if managed_node is None:
raise Exception('Cannot find the Managed Node.')
result = []
image_groups = {}
if imageGroupId is not None:
image_group = self.image_store.get_image_group(auth, imageGroupId)
image_groups = {image_group.get_id():image_group}
else:
image_groups = self.image_store.get_image_groups(auth)
for image_group in image_groups.itervalues():
images = self.image_store.get_group_images(auth, image_group.id)
for image in images.itervalues():
if managed_node.is_image_compatible(image) and not image.is_template:
result.append(dict(name=image.get_name(), id=image.get_id(), group_id=image_group.get_id()))
except Exception as ex:
print_traceback()
LOGGER.error(to_str(ex).replace("'", ''))
return ("{success: false,msg: '", to_str(ex).replace("'", ''), "'}")
return dict(success='true', images=result)
开发者ID:smarkm,项目名称:ovm,代码行数:25,代码来源:ImageService.py
示例6: get_target_image_groups
def get_target_image_groups(self, auth, nodeId):
try:
manager = Basic.getGridManager()
managed_node = manager.getNode(auth, nodeId)
result = []
if managed_node is None:
raise Exception('Cannot find the Managed Node.')
result = []
mnode_ent = auth.get_entity(managed_node.id)
dc_ent = mnode_ent.parents[0].parents[0]
image_groups = self.image_store.get_image_groups(auth,dc_ent.entity_id)
for image_group in image_groups.itervalues():
count = 0
images = self.get_group_images(auth, image_group.id)
for image in images.itervalues():
if managed_node.is_image_compatible(image):
count = count + 1
break
if count > 0:
result.append(dict(name=image_group.get_name(), id=image_group.get_id()))
except Exception as ex:
print_traceback()
LOGGER.error(to_str(ex).replace("'", ''))
return ("{success: false,msg: '", to_str(ex).replace("'", ''), "'}")
return dict(success='true', image_groups=result)
开发者ID:smarkm,项目名称:ovm,代码行数:31,代码来源:ImageService.py
示例7: exec_cmd
def exec_cmd(self, cmd, exec_path=None, timeout=-1, params=None, cd=False, env=None, pid_file=None):
evn_str = ''
if env is not None:
for env_var in env.keys():
evn_str += 'export ' + env_var + '=' + env.get(env_var) + ';'
if self.use_bash_timeout:
bash_script = os.path.join(self.local_bash_dir, 'bash_timeout.sh')
if self.isRemote:
bash_script = os.path.join(self.bash_dir, 'bash_timeout.sh')
bash_cmd = ''
if timeout == -1:
bash_cmd = bash_script + ' -t ' + to_str(self.default_bash_timeout) + ' '
elif timeout is not None:
bash_cmd = bash_script + ' -t ' + to_str(timeout) + ' '
if pid_file is not None:
bash_cmd = bash_cmd + '-p ' + pid_file + ' '
cmd = bash_cmd + cmd
if timeout == -1:
timeout = None
if exec_path is not None and exec_path is not '':
exec_cmd = 'PATH=$PATH:%s; %s' % (exec_path, cmd)
if cd == True:
exec_cmd = 'cd ' + exec_path + ';' + exec_cmd
else:
exec_cmd = cmd
exec_cmd = evn_str + exec_cmd
if self.isRemote:
return self.remote_exec_cmd(exec_cmd, timeout, params)
else:
return self.local_exec_cmd(exec_cmd, timeout, params)
开发者ID:smarkm,项目名称:ovm,代码行数:33,代码来源:NodeProxy.py
示例8: send_test_email
def send_test_email(self, desc, servername, port, useremail, password, secure):
self.sender = useremail
Record = DBSession.query(User.email_address).filter(User.user_name == 'admin').first()
self.receivers = Record.email_address
self.mail_server = servername
if port:
self.port = int(port)
self.secure_type = int(secure)
self.password = password
self.subject = 'Test Email'
self.content = "\Test message Sent on " + to_str(ct_time())
self.msg = MIMEText(self.content, self.text_subtype)
self.msg['Subject'] = 'stackone Test Email'
try:
if self.secure_type == NONSECURE:
EmailManager().send_nonsecure(servername, self.port, useremail, Record.email_address, self.msg.as_string())
else:
if self.secure_type == TLS:
EmailManager().send_tls(servername, self.port, useremail, password, Record.email_address, self.msg.as_string())
else:
EmailManager().send_ssl(servername, self.port, useremail, password, Record.email_address, self.msg.as_string())
except Exception as ex:
LOGGER.error('Error sending mails:' + to_str(ex).replace("'", ''))
raise ex
message = 'mail send to ' + Record.email_address
return message
开发者ID:smarkm,项目名称:ovm,代码行数:29,代码来源:EmailService.py
示例9: add_image_group
def add_image_group(self, group_name,store_id):
try:
result = self.template_controller.add_image_group(group_name,store_id)
except Exception,ex:
print_traceback()
LOGGER.error(to_str(ex).replace("'",''))
return "{success: false,msg: '" + to_str(ex).replace("'",'') +"'}"
开发者ID:smarkm,项目名称:ovm,代码行数:7,代码来源:TemplateAjaxController.py
示例10: save_image_script
def save_image_script(self, auth, image_id, content):
try:
mgd_node = Basic.local_node
self.image_store.save_image_script(auth, mgd_node, image_id, content)
except Exception as ex:
LOGGER.error(to_str(ex).replace("'", ''))
return ("{success: false,msg: '", to_str(ex).replace("'", ''), "'}")
return "{success: true,msg: 'Success'}"
开发者ID:smarkm,项目名称:ovm,代码行数:8,代码来源:ImageService.py
示例11: clone_image
def clone_image(self, image_id, image_name, group_id,group_name):
try:
result = None
result = self.template_controller.clone_image(image_id, image_name, group_id, group_name)
except Exception, ex:
print_traceback()
LOGGER.error(to_str(ex).replace("'",""))
return "{success: false,msg: '",to_str(ex).replace("'",""),"'}"
开发者ID:smarkm,项目名称:ovm,代码行数:8,代码来源:TemplateAjaxController.py
示例12: transfer_image
def transfer_image(self, auth, image_id, source_group_id, dest_group_id):
try:
self.image_store.transfer_image(auth, image_id, source_group_id, dest_group_id)
except Exception as ex:
LOGGER.error(to_str(ex).replace("'", ''))
return ("{success: false,msg: '", to_str(ex).replace("'", ''), "'}")
return "{success: true,msg: 'Success'}"
开发者ID:smarkm,项目名称:ovm,代码行数:8,代码来源:ImageService.py
示例13: remove_image_group
def remove_image_group(self, auth, group_id):
try:
self.image_store.delete_group(auth, group_id)
except Exception as ex:
LOGGER.error(to_str(ex).replace("'", ''))
return "{success: false,msg: '" + to_str(ex).replace("'", '') + "'}"
return "{success: true,msg: 'Success'}"
开发者ID:smarkm,项目名称:ovm,代码行数:8,代码来源:ImageService.py
示例14: remove_csep_context
def remove_csep_context(self, context):
try:
result = self.csep_service.remove_csep_context(session['auth'],context)
return {'success':True,'result':result,'msg':'','error_msg':''}
except Exception as ex:
print_traceback()
LOGGER.error(to_str(ex))
return {'success':False,'result':None,'msg':'','error_msg':to_str(ex)}
开发者ID:smarkm,项目名称:ovm,代码行数:8,代码来源:CMSCloudXMLRPC.py
示例15: check_image_exists
def check_image_exists(self, auth, image_name):
try:
if self.image_store.image_exists_by_name(image_name):
return "{success: true,exists:true,msg: 'Image with the same name exists.'}"
except Exception as ex:
print_traceback()
LOGGER.error(to_str(ex).replace("'", ''))
return "{success: false,msg: '" + to_str(ex).replace("'", '') + "'}"
return "{success: true,exists:false,msg: 'Success'}"
开发者ID:smarkm,项目名称:ovm,代码行数:9,代码来源:ImageService.py
示例16: rename_image
def rename_image(self, auth, image_id, image_name, group_id):
try:
self.image_store.rename_image(auth, group_id, image_id, image_name)
except Exception as ex:
print_traceback()
LOGGER.error(to_str(ex).replace("'", ''))
return "{success: false,msg: '" + to_str(ex).replace("'", '') + "'}"
return "{success: true,msg: 'Success'}"
开发者ID:smarkm,项目名称:ovm,代码行数:9,代码来源:ImageService.py
示例17: restore_vm
def restore_vm(self, node_id, file, date=None, time=None):
self.authenticate()
try:
result = to_str(self.tc.restore_vm(session['auth'], node_id, file, date, time))
except Exception as ex:
print_traceback()
return dict(success=False, msg=to_str(ex))
return dict(success=True, msg='Restore Virtual Machine task submitted.', taskid=result)
开发者ID:smarkm,项目名称:ovm,代码行数:9,代码来源:NodeController.py
示例18: get_default_bridge
def get_default_bridge(self):
try:
default_bridge = self.environ['default_bridge']
return default_bridge
except Exception as e:
LOGGER.error('Exception : ' + to_str(e) + ' on ' + self.hostname)
print 'Exception : ' + to_str(e) + ' on ' + self.hostname
traceback.print_exc()
return None
开发者ID:smarkm,项目名称:ovm,代码行数:9,代码来源:ManagedNode.py
示例19: remove_image
def remove_image(self, image_id, group_id):
try:
result = None
result = self.template_controller.remove_image(image_id, group_id)
except Exception as ex:
print_traceback()
LOGGER.error(to_str(ex).replace("'",''))
return "{success: false,msg:'"+ to_str(ex).replace("'",'') + "'}"
return "{success: true,msg: 'Task Submitted'}"
开发者ID:smarkm,项目名称:ovm,代码行数:9,代码来源:TemplateAjaxController.py
示例20: server_action
def server_action(self, node_id, action, date=None, time=None):
self.authenticate()
try:
result = to_str(self.tc.server_action(session['auth'], node_id, action, date, time))
except Exception as ex:
print_traceback()
return dict(success=False, msg=to_str(ex))
return dict(success=True, msg='Task submitted.', taskid=result)
开发者ID:smarkm,项目名称:ovm,代码行数:10,代码来源:NodeController.py
注:本文中的stackone.core.utils.utils.to_str函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论