本文整理汇总了Python中stackone.model.DBSession类的典型用法代码示例。如果您正苦于以下问题:Python DBSession类的具体用法?Python DBSession怎么用?Python DBSession使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DBSession类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: get_vm_restore_task_result
def get_vm_restore_task_result(self, auth, vm_id):
task_backup_info = {}
tasklist_info = []
msg = " Number of VM's backed up= 2 \n Number of VM backup suceeded = 2\n Number of VM backup failed = 0"
vmrestore_result_obj_list = DBSession.query(VMRestoreResult, VMBackupResult).join((VMBackupResult, VMRestoreResult.backup_result_id == VMBackupResult.id)).filter(VMRestoreResult.vm_id == vm_id).order_by(VMRestoreResult.start_time).all()
if vmrestore_result_obj_list:
for vm_result_obj in vmrestore_result_obj_list:
vmrestore_result_obj = vm_result_obj[0]
vmbackup_result_obj = vm_result_obj[1]
sp_bkp_conf = DBSession.query(SPBackupConfig).filter_by(id=vmrestore_result_obj.backup_id).first()
if sp_bkp_conf:
detailResult_obj_list = DBSession.query(VMRestoreDetailResult).filter_by(result_id=vmrestore_result_obj.id).order_by(VMRestoreDetailResult.details).all()
msg2 = ''
if detailResult_obj_list:
for detailResult_obj in detailResult_obj_list:
if detailResult_obj:
msg2 += detailResult_obj.details + '\n'
task_info = {}
task_info['taskid'] = vmrestore_result_obj.id
task_info['status'] = vmrestore_result_obj.status
task_info['name'] = sp_bkp_conf.name
location = ''
exec_context = vmbackup_result_obj.execution_context
location = exec_context['SERVER'] + ':' + exec_context['BACKUP_DESTINATION']
task_info['location'] = location
task_info['backup_size'] = 0
task_info['starttime'] = vmrestore_result_obj.start_time
task_info['endtime'] = vmrestore_result_obj.end_time
task_info['errmsg'] = msg2
task_info['restore'] = vmrestore_result_obj.id
tasklist_info.append(task_info)
task_backup_info['rows'] = tasklist_info
return task_backup_info
开发者ID:smarkm,项目名称:ovm,代码行数:33,代码来源:Restore.py
示例2: create_vmw_server_pool
def create_vmw_server_pool(self, auth, name, actual_name, moid, vcenter_id, parent_ent=None):
msg = ''
entityType = to_unicode(constants.SERVER_POOL)
sp = None
update_name = False
sp_ent = auth.get_entity_by_entity_attributes(self.get_entity_attributes_dict(vcenter_id, moid), entityType)
if not sp_ent:
dup_ent = auth.get_entity_by_name(name, entityType=entityType)
if dup_ent:
msg += '\nERROR: Could not import Server Pool:%s. It is already exist,please choose different name' % name
return (msg, None, None)
if sp_ent:
update_name = self.can_update_managed_object_name(auth, name, actual_name, sp_ent.name)
msg += '\nServer Pool: %s already exist' % name
sp = DBSession.query(VMWServerGroup).filter(VMWServerGroup.id == sp_ent.entity_id).first()
if sp:
if update_name:
sp.name = name
if not sp:
msg += '\nCreating Server Pool: %s' % name
sp = VMWServerGroup(name)
DBSession.add(sp)
if not sp_ent:
cntx = {'external_manager_id': vcenter_id, 'external_id': moid}
sp_ent = self.add_vcenter_entity(auth, cntx, sp.name, sp.id, to_unicode(constants.SERVER_POOL), parent_ent)
else:
if not update_name:
name = None
auth.update_entity(sp_ent, name=name, parent=parent_ent)
return (msg, sp, sp_ent)
开发者ID:smarkm,项目名称:ovm,代码行数:31,代码来源:VcenterManager.py
示例3: sync_defn
def sync_defn(self, auth, server_ids, def_id, site_id, group_id):
server_id_list = server_ids.split(',')
for server_id in server_id_list:
node = DBSession.query(ManagedNode).filter_by(id=server_id).first()
defn = DBSession.query(StorageDef).filter_by(id=def_id).first()
self.sync_manager.sync_node_defn(auth, node, group_id, site_id, defn, constants.STORAGE, constants.ATTACH, self.storage_manager)
return dict(success='true')
开发者ID:smarkm,项目名称:ovm,代码行数:7,代码来源:StorageService.py
示例4: get_next_id
def get_next_id(self, pool_tag, context):
available_id = None
interface = None
if pool_tag == constants.VLAN_ID_POOL:
LOGGER.info("Get next vlan id from pool...")
pool_id = context.get("pool_id")
nw_def_id = context.get("nw_def_id")
null_value = None
LOGGER.info("Getting CMS Lock...")
LockManager().get_lock(
constants.VLAN_ID_POOL, pool_id, constants.NEXT_VLAN_ID, constants.Table_vlan_id_pools
)
interface = VLANManager().get_interface(pool_id)
rs = (
DBSession.query(func.min(VLANID.vlan_id).label("vlan_id"))
.join((VLANIDPool, VLANIDPool.id == VLANID.vlan_id_pool_id))
.filter(VLANID.used_by == null_value)
.filter(VLANIDPool.id == pool_id)
.first()
)
is_tuple = isinstance(rs, tuple)
if is_tuple and rs[0]:
available_id = rs.vlan_id
LOGGER.info("Available vlan id is " + to_str(available_id))
context["vlan_id"] = available_id
self.mark_used(pool_tag, context)
vlan = DBSession.query(VLANIDPool).filter(VLANIDPool.id == pool_id).first()
if vlan:
vlan.used = int(vlan.used) + 1
LOGGER.info("Releasing CMS Lock...")
LockManager().release_lock()
return (available_id, interface)
开发者ID:yangliang913,项目名称:ovm,代码行数:32,代码来源:VLANManager.py
示例5: 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
示例6: create_vlan_network_info
def create_vlan_network_info(self, vlan_id_pool, cidr, num_networks, network_size, vlan_start, interface):
vlan_nw_infos = self.get_vlan_network_info(cidr, num_networks, network_size, vlan_start, interface)
for info_dict in vlan_nw_infos:
vlan_nw_info_db = self.create_vlan_network_info_db(info_dict)
vlan_nw_info_db.vlan_pool_id = vlan_id_pool.id
DBSession.add(vlan_nw_info_db)
LOGGER.info("created vlan_network_info for vlan_id_pool:%s" % vlan_id_pool.name)
开发者ID:yangliang913,项目名称:ovm,代码行数:7,代码来源:VLANManager.py
示例7: delete_pool
def delete_pool(self, pool_ids):
if not isinstance(pool_ids, list):
pool_ids = [pool_ids]
pools = DBSession.query(IPPool).filter(IPPool.id.in_(pool_ids)).all()
DBSession.query(IPS).filter(IPS.pool_id.in_(pool_ids)).delete()
for pool in pools:
DBSession.delete(pool)
开发者ID:smarkm,项目名称:ovm,代码行数:7,代码来源:IPManager.py
示例8: add_firewall_for_entity
def add_firewall_for_entity(self, entity_id):
LOGGER.info("Add firewall for CSEP/ Data Center...")
if entity_id:
csep = DBSession.query(CSEP).filter_by(id=entity_id).first()
if csep:
LOGGER.info("Got CSEP")
nw_service_host = csep.get_nw_service_host()
if nw_service_host:
fw = IptablesManager(csep.name)
self.fw_map[entity_id] = fw
LOGGER.info("Firewall is added to CSEP")
self.set_nw_service_host(fw, nw_service_host)
LOGGER.info("Network service host is added to firewall")
return fw
dc = DBSession.query(Site).filter_by(id=entity_id).first()
if dc:
LOGGER.info("Got DC")
nw_service_host = get_cms_network_service_node()
if nw_service_host:
fw = IptablesManager(dc.name)
self.fw_map[entity_id] = fw
LOGGER.info("Firewall is added to DC")
self.set_nw_service_host(fw, nw_service_host)
LOGGER.info("Network service host is added to firewall")
return fw
开发者ID:yangliang913,项目名称:ovm,代码行数:25,代码来源:FirewallManager.py
示例9: remove_context
def remove_context(cls, context_id):
try:
DBSession.query(cls).filter(cls.id == context_id).delete()
except Exception as e:
LOGGER.error(e)
traceback.print_exc()
raise e
开发者ID:smarkm,项目名称:ovm,代码行数:7,代码来源:Entity.py
示例10: update_avail
def update_avail(node, new_state, monit_state, timestamp, reason, logger, update=True, auth=None):
sv_point = transaction.savepoint()
try:
strt = p_task_timing_start(logger, "UpdateAvailability", node.id, log_level="DEBUG")
node.current_state.avail_state = new_state
node.current_state.timestamp = timestamp
node.current_state.description = reason
avh=DBSession.query(AvailHistory).filter(AvailHistory.entity_id==node.id).\
order_by(AvailHistory.timestamp.desc()).first()
if avh is not None:
avh.endtime=timestamp
time_diff=timestamp-avh.timestamp
avh.period=time_diff.days*24*60+time_diff.seconds/60
DBSession.add(avh)
#insert availability history
ah = AvailHistory(node.id, new_state, monit_state, timestamp, reason)
DBSession.add(ah)
DBSession.add(node)
if update==True:
487
ev_contents = {'state':new_state}
ev = AvailabilityEvent(node.id, ev_contents, timestamp)
DBSession.add(ev)
ent = DBSession.query(Entity).filter(Entity.entity_id==node.id).first()
from stackone.model.ManagedNode import ManagedNode
if ent.type.name == constants.MANAGED_NODE and new_state == ManagedNode.DOWN:
if node.is_maintenance():
logger.info('Node:%s is in Maintenance mode' %node.hostname)
else:
notify_node_down(ent,reason)
except Exception, e:
import traceback
traceback.print_exc()
logger.error(e)
sv_point.rollback()
开发者ID:smarkm,项目名称:ovm,代码行数:35,代码来源:availability.py
示例11: 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
示例12: delete_restore_single_result
def delete_restore_single_result(self, result_id):
try:
DBSession.query(VMRestoreResult).filter(VMRestoreResult.id == result_id).delete()
LOGGER.info('VM restore single result is deleted.')
transaction.commit()
except Exception as ex:
LOGGER.error(to_str(ex).replace("'", ''))
开发者ID:smarkm,项目名称:ovm,代码行数:7,代码来源:Restore.py
示例13: get_storage_usage
def get_storage_usage(self, auth, site_id, group_id, scope, defn):
usage = 0
vm_id_list = []
if scope==constants.SCOPE_DC:
site_entity = auth.get_entity(site_id)
groups = auth.get_entities(constants.SERVER_POOL, parent=site_entity)
for eachgroup in groups:
nodes = auth.get_entities(constants.MANAGED_NODE, parent=eachgroup)
vm_id_list = self.get_vm_id_list(auth, nodes, vm_id_list)
if scope == constants.SCOPE_SP:
group_entity = auth.get_entity(group_id)
nodes = auth.get_entities(constants.MANAGED_NODE, parent=group_entity)
vm_id_list = self.get_vm_id_list(auth, nodes, vm_id_list)
storage_disks = DBSession.query(StorageDisks).filter_by(storage_id=defn.id)
if storage_disks:
for each_disk in storage_disks:
vm_storage_link = DBSession.query(VMStorageLinks).filter_by(storage_disk_id=each_disk.id).first()
if vm_storage_link:
vm_id = None
vm_disk = DBSession.query(VMDisks).filter_by(id=vm_storage_link.vm_disk_id).first()
if vm_disk:
vm_id = vm_disk.vm_id
for each_vm_id in vm_id_list:
if each_vm_id == vm_id:
usage += vm_disk.disk_size
return usage
开发者ID:smarkm,项目名称:ovm,代码行数:27,代码来源:StorageService.py
示例14: delete_vlan_network_info
def delete_vlan_network_info(self, vlan_id_pool, vlan_ids):
if not isinstance(vlan_ids, list):
vlan_ids = [vlan_ids]
DBSession.query(VLANNetworkInfo).filter(VLANNetworkInfo.vlan_id.in_(vlan_ids)).filter(
VLANNetworkInfo.vlan_pool_id == vlan_id_pool.id
).delete()
LOGGER.info("deleted vlan_network_info for vlan_id_pool:%s" % vlan_id_pool.name)
开发者ID:yangliang913,项目名称:ovm,代码行数:7,代码来源:VLANManager.py
示例15: check_for_updates
def check_for_updates(self, send_mail=False):
update_items = []
dep = None
try:
deps = DBSession.query(Deployment).all()
if len(deps) > 0:
dep = deps[0]
edition = get_product_edition()
new_updates,max_dt = self.get_new_updates(dep.deployment_id, dep.update_checked_date, edition)
if send_mail and new_updates:
self.send_update_mails(new_updates)
else:
LOGGER.error('Deployment table is not set. Update can not proceed.')
return None
except Exception as ex:
traceback.print_exc()
LOGGER.error('Error fetching updates:' + to_str(ex))
return None
try:
dep.update_checked_date = datetime.now()
DBSession.add(dep)
except:
pass
return update_items
开发者ID:smarkm,项目名称:ovm,代码行数:26,代码来源:UpdateManager.py
示例16: on_add_node
def on_add_node(self, nodeId, groupId, site_id, auth, def_manager):
op = constants.ATTACH
if not(nodeId or groupId):
return None
defn_list = []
errs = []
sync_manager = SyncDef()
defType = def_manager.getType()
sp_defns = DBSession.query(SPDefLink).filter_by(group_id=to_unicode(groupId))
if sp_defns:
for eachdefn in sp_defns:
defn = def_manager.get_defn(eachdefn.def_id)
if defn:
defn_list.append(defn)
status = to_unicode(constants.OUT_OF_SYNC)
details = None
sync_manager.add_node_defn(nodeId, defn.id, defType, status, details)
node = DBSession.query(ManagedNode).filter_by(id=nodeId).first()
if node:
update_status = True
try:
sync_manager.sync_node(defn_list, node, groupId, site_id, auth, defType, op, def_manager, update_status, errs)
except Exception as ex:
if errs:
if len(errs)>0:
LOGGER.error('Error in syncing definition while adding node: ' + to_str(errs))
开发者ID:smarkm,项目名称:ovm,代码行数:26,代码来源:SyncDefinition.py
示例17: manage_public_ip
def manage_public_ip(self, vm_id, public_ip_id, public_ip, csep_id, add_flag):
LOGGER.info('Calling network service...')
if vm_id:
nw_vm_rel = DBSession.query(NetworkVMRelation).filter_by(vm_id=vm_id).first()
elif public_ip:
nw_vm_rel = DBSession.query(NetworkVMRelation).filter_by(public_ip_id=public_ip_id).first()
if nw_vm_rel:
LOGGER.info('Got network VM relation')
nw_def_id = nw_vm_rel.nw_def_id
private_ip_id = nw_vm_rel.private_ip_id
nw_defn = NwManager().get_defn(nw_def_id)
public_interface = ''
if nw_defn:
bridge_name = nw_defn.bridge_info.get('name')
private_ip = ''
ip_rec = self.get_ip_by_id(private_ip_id)
if ip_rec:
private_ip = self.remove_cidr_format_from_ip(ip_rec.ip)
dom_id = None
nw_service_host = NwManager().get_nw_service_host(csep_id)
if nw_service_host:
LOGGER.info('Got network service host')
public_interface = self.get_public_interface(csep_id)
ctx = {}
ctx['public_ip'] = public_ip
ctx['private_ip'] = private_ip
ctx['public_interface'] = public_interface
ctx['bridge_name'] = bridge_name
ctx['add_flag'] = add_flag
ctx['csep_id'] = csep_id
LOGGER.info('context=' + to_str(ctx))
NwManager().manage_public_ip(nw_service_host, ctx)
开发者ID:smarkm,项目名称:ovm,代码行数:32,代码来源:IPManager.py
示例18: 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
示例19: get_vm_linked_with_storage
def get_vm_linked_with_storage(self, storage_disk_id):
vm = None
if storage_disk_id:
vm_storage_link = DBSession.query(VMStorageLinks).filter_by(storage_disk_id=storage_disk_id).first()
if vm_storage_link:
vm_disk = DBSession.query(VMDisks).filter_by(id=vm_storage_link.vm_disk_id).first()
if vm_disk:
vm = DBSession.query(VM).filter_by(id=vm_disk.vm_id).first()
return vm
开发者ID:smarkm,项目名称:ovm,代码行数:9,代码来源:StorageService.py
示例20: migrate_to_servers
def migrate_to_servers(self, grpid, tried_sb_nodes=[], failed_doms=[], dom_ids=[]):
msg = 'Starting Maintenance migration on Node ' + self.nodename + '. Checking for VMs.'
self.msg += '\n' + msg
LOGGER.info(msg)
node = DBSession.query(ManagedNode).filter(ManagedNode.id == self.entity_id).first()
grp = DBSession.query(ServerGroup).filter(ServerGroup.id == grpid).first()
gretry_count = grp.getAttributeValue(constants.retry_count, 3)
gwait_interval = grp.getAttributeValue(constants.wait_interval, 3)
if grp.use_standby == True:
while len(failed_doms) > 0:
msg = 'Finding standby node.'
self.msg += '\n' + msg
LOGGER.info(msg)
new_node = self.find_standby_node(self.auth, None, node, exclude_ids=tried_sb_nodes)
if new_node is None:
msg = 'All standby nodes are exhausted.'
self.msg += '\n' + msg
LOGGER.info(msg)
break
failed_doms = self.dom_fail_over(failed_doms, node, new_node, gretry_count, gwait_interval, self.FENCING)
tried_sb_nodes.append(new_node.id)
tot_failed = failed_doms
tmp_failed_doms = [d for d in failed_doms]
if len(failed_doms) > 0:
tot_failed = []
for domid in tmp_failed_doms:
self.step = self.PAUSE_IN_STANDBY
dom = DBSession.query(VM).filter(VM.id == domid).first()
domname = dom.name
msg = 'Starting initial placement for ' + domname
self.msg += '\n' + msg
LOGGER.info(msg)
new_node = self.get_allocation_candidate(self.auth,dom,node)
failed = self.dom_fail_over(domid, node, new_node, gretry_count, gwait_interval, self.PAUSE_IN_STANDBY)
if len(failed) == 1:
tot_failed.append(failed[0])
if len(tot_failed)>0:
doms = DBSession.query(VM).filter(VM.id.in_(tot_failed)).all()
domnames = [d.name for d in doms]
msg = 'Failed to migrate following VMs' + to_str(domnames)
self.msg += '\n' + msg
LOGGER.info(msg)
else:
self.status = self.SUCCESS
msg = 'Successfully migrated all VMs'
self.msg += '\n' + msg
LOGGER.info(msg)
if len(tot_failed) != 0 and len(tot_failed) < len(dom_ids):
self.status = self.PARTIAL
vm_info_tup = self.get_maint_task_context(key='migrated_vms')
vm_ids = [x[0] for x in vm_info_tup]
self.add_vm_states(vm_ids)
return True
开发者ID:smarkm,项目名称:ovm,代码行数:56,代码来源:Maintenance.py
注:本文中的stackone.model.DBSession类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论