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