本文整理汇总了Python中stackone.core.utils.utils.to_str函数的典型用法代码示例。如果您正苦于以下问题:Python to_str函数的具体用法?Python to_str怎么用?Python to_str使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了to_str函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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')
示例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'}
示例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)
示例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
示例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)
示例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)
示例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)
示例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
示例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("'",'') +"'}"
示例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'}"
示例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("'",""),"'}"
示例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'}"
示例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'}"
示例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)}
示例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'}"