def is_ip_assigned(ip_pool_id, is_private): if is_private: private_ip_pool = db.private_ip_pool[ip_pool_id] if (db.vm_data(private_ip = private_ip_pool.id)) or (db.host(host_ip = private_ip_pool.id)): return PRIVATE_IP_DELETE_MESSAGE else: public_ip_pool = db.public_ip_pool[ip_pool_id] if (db.vm_data(public_ip = public_ip_pool.id)) or (db.host(public_ip = public_ip_pool.id)): return PUBLIC_IP_DELETE_MESSAGE
def check_delete_template(template_id): if db.vm_data(saved_template = template_id): add_vm_task_to_queue(-1, VM_TASK_DELETE_TEMPLATE, {'template_id' : template_id}) if db.vm_data(template_id = template_id): db(db.template.id== template_id).update(is_active=False) return False return True
def check_delete_security_domain(sd_id): if db.vm_data(security_domain=sd_id): return SECURITY_DOMAIN_DELETE_MESSAGE elif db.security_domain[sd_id].name in ('Research', 'Private', 'Infrastructure'): return 'Security Domain %s can' 't be deleted.' % ( db.security_domain[sd_id].name)
def get_my_saved_templates(): templates = db(db.template.owner.contains(auth.user.id)).select(db.template.ALL) for template in templates: parent_vm = db.vm_data(saved_template = template.id) template['vm_id'] = parent_vm.id if parent_vm else -1 return templates
def get_private_ip_ref_link(row): """Returns link to VM settings page if IP is assigned to a VM or to host details page if IP is assigned to a Host""" vm_data = db.vm_data(private_ip=row.id) host_data = db.host(host_ip=row.id) if vm_data: return A(vm_data.vm_name, _href=URL(r=request, c='user',f='settings', args=vm_data.id)) elif host_data: return A(host_data.host_name, _href=URL(r=request, c='admin',f='host_config', args=host_data.id)) else: return 'Unassigned'
def create_clone_task(req_data, params): clone_count = req_data.clone_count vm_data = db.vm_data[req_data.parent_id] clone_name = req_data.vm_name cnt = 1 vm_id_list = [] for count in range(0, clone_count): # @UnusedVariable while (db.vm_data(vm_name=(clone_name + str(cnt)))): cnt = cnt + 1 clone_vm_name = clone_name + str(cnt) clone_vm_id = db.vm_data.insert( vm_name=clone_vm_name, vm_identity=get_vm_identity(clone_vm_name, vm_data.owner_id), RAM=vm_data.RAM, HDD=vm_data.HDD, extra_HDD=vm_data.extra_HDD, vCPU=vm_data.vCPU, template_id=vm_data.template_id, owner_id=vm_data.owner_id, requester_id=req_data.requester_id, parent_id=req_data.parent_id, public_ip=None, security_domain=vm_data.security_domain, purpose=req_data.purpose, status=VM_STATUS_IN_QUEUE) vm_id_list.append(clone_vm_id) vm_users = [] for user in db(db.user_vm_map.vm_id == vm_data.id).select( db.user_vm_map.user_id): vm_users.append(user['user_id']) add_vm_users(clone_vm_id, vm_data.requester_id, vm_data.owner_id, vm_users=vm_users) cnt = cnt + 1 params.update({'clone_vm_id': vm_id_list}) add_vm_task_to_queue(req_data.parent_id, VM_TASK_CLONE, params=params, requested_by=req_data.requester_id)
def create_clone_task(req_data, params): clone_count = req_data.clone_count vm_data = db.vm_data[req_data.parent_id] clone_name = req_data.vm_name cnt = 1; vm_id_list = [] for count in range(0, clone_count): # @UnusedVariable while(db.vm_data(vm_name=(clone_name+str(cnt)))): cnt = cnt+1 clone_vm_name = clone_name + str(cnt) clone_vm_id = db.vm_data.insert( vm_name = clone_vm_name, vm_identity = get_vm_identity(clone_vm_name, vm_data.owner_id), RAM = vm_data.RAM, HDD = vm_data.HDD, extra_HDD = vm_data.extra_HDD, vCPU = vm_data.vCPU, template_id = vm_data.template_id, owner_id = vm_data.owner_id, requester_id = req_data.requester_id, parent_id = req_data.parent_id, public_ip = None, security_domain = vm_data.security_domain, purpose = req_data.purpose, status = VM_STATUS_IN_QUEUE) vm_id_list.append(clone_vm_id) vm_users=[] for user in db(db.user_vm_map.vm_id == vm_data.id).select(db.user_vm_map.user_id): vm_users.append(user['user_id']) add_vm_users(clone_vm_id, vm_data.requester_id, vm_data.owner_id, vm_users=vm_users) cnt = cnt+1 params.update({'clone_vm_id':vm_id_list}) add_vm_task_to_queue(req_data.parent_id, VM_TASK_CLONE, params=params, requested_by=req_data.requester_id)
def check_delete_security_domain(sd_id): if db.vm_data(security_domain = sd_id): return SECURITY_DOMAIN_DELETE_MESSAGE elif db.security_domain[sd_id].name in ('Research', 'Private', 'Infrastructure'): return 'Security Domain %s can''t be deleted.' %(db.security_domain[sd_id].name)