def __init__(self,id, type, name, description, is_deleted, scope, bridge_info=dynamic_map(), vlan_info=dynamic_map(), bond_info=dynamic_map(), ipv4_info=dynamic_map(), dhcp_info=dynamic_map(), nat_info=dynamic_map(), status=None): self.id = id if self.id is None: self.id = getHexID() self.type = type self.name = name self.description = description self.is_deleted = is_deleted self.bridge_info = bridge_info self.vlan_info = vlan_info self.bond_info = bond_info self.ipv4_info = ipv4_info self.dhcp_info = dhcp_info self.nat_info = nat_info self.status = status #definition status to be displayed in the grid - IN_SYNC/ OUT_OF_SYNC self.scope = scope #To identify definition scope of definition since we are showing all the definitions (server and pool level) at server level.
def __init__(self, id, type, name, description, is_deleted, scope, bridge_info=dynamic_map(), vlan_info=dynamic_map(), bond_info=dynamic_map(), ipv4_info=dynamic_map(), dhcp_info=dynamic_map(), nat_info=dynamic_map(), status=None): self.id = id if self.id is None: self.id = getHexID() self.type = type self.name = name self.description = description self.is_deleted = is_deleted self.bridge_info = bridge_info self.vlan_info = vlan_info self.bond_info = bond_info self.ipv4_info = ipv4_info self.dhcp_info = dhcp_info self.nat_info = nat_info self.status = status #definition status to be displayed in the grid - IN_SYNC/ OUT_OF_SYNC self.scope = scope #To identify definition scope of definition since we are showing all the definitions (server and pool level) at server level.
def refresh(self, id, pid_filename=None): pid = id pid_string = to_str(pid) cmd_line_file = os.path.join('/proc',pid_string,'cmdline') if pid_filename is not None: if self.node_proxy.file_exists(cmd_line_file)==False: self.node_proxy.remove(pid_filename) return None cmd = None cmd = self._get_file_content(cmd_line_file, 2048) if cmd is None or cmd.strip() == '': return None if cmd.split(chr(0),1)[0].endswith("qemu"): type = "qemu" elif cmd.find("kvm") > -1 or cmd.find("qemu-system-x86") > -1: #later look at fds and see if /dev/kvm used type = "kvm" else: return None info = dynamic_map() info.type = type info.cmdline= cmd.strip().replace(chr(0), " ") info.pid = to_str(pid) info.domid = to_str(pid) self.populate_info_from_cmdline(info, cmd) if info.name is None: info.name = info.pid info.id = info.name # will need to change once the client changes # to use proper id return info
def refresh(self, id, pid_filename=None): pid = id pid_string = to_str(pid) cmd_line_file = os.path.join('/proc', pid_string, 'cmdline') if pid_filename is not None: if self.node_proxy.file_exists(cmd_line_file) == False: self.node_proxy.remove(pid_filename) return None cmd = None cmd = self._get_file_content(cmd_line_file, 2048) if cmd is None or cmd.strip() == '': return None if cmd.split(chr(0), 1)[0].endswith("qemu"): type = "qemu" elif cmd.find("kvm") > -1 or cmd.find("qemu-system-x86") > -1: #later look at fds and see if /dev/kvm used type = "kvm" else: return None info = dynamic_map() info.type = type info.cmdline = cmd.strip().replace(chr(0), " ") info.pid = to_str(pid) info.domid = to_str(pid) self.populate_info_from_cmdline(info, cmd) if info.name is None: info.name = info.pid info.id = info.name # will need to change once the client changes # to use proper id return info
def add_nw_defn(self,auth,nw_name,nw_desc,nw_device,nw_address_space,nw_dhcp_range,nat_radio,nw_nat_fwding,site_id,group_id,node_id,scope=None): # print "nw_desc,nw_device,nw_address_space,nw_dhcp_range,nw_nat_fwding,pool_id,node_id", nw_name=(nw_name) nw_desc=(nw_desc) nw_device=(nw_device) nw_address_space=(nw_address_space) nw_dhcp_range=(nw_dhcp_range) node_id=(node_id) ## Jd ## For now create host private networks. ## This needs to be revisited when we add VLAN support. scope=constants.SCOPE_S if site_id == 'data_center': site = self.manager.getSiteByGroupId(group_id) if site: site_id = site.id else: site = self.manager.getSite(site_id) group_list = self.manager.getGroupList(auth, site_id) try: nw_id = None group = None managed_node = None new_nw_def = None #we were getting server pool None so we have added this query here if group_id: group= DBSession.query(ServerGroup).filter_by(id = group_id).first() managed_node=NodeService().get_managed_node(auth,node_id) # if is_public=='true': # nw_type = NwDef.PUBLIC_NW # else: # nw_type = NwDef.HOST_PRIVATE_NW #nw_type= self.get_nw_type() nw_type=NwDef.HOST_PRIVATE_NW #Set to Private Network for now errors=self.validate_new_nw_def(auth,"ADD",nw_type,nw_name,nw_desc,nw_device,nw_address_space,nw_dhcp_range,nat_radio,nw_nat_fwding,site_id,group_id,node_id, scope) if errors: if len(errors)>0: return {'success':False,'msg':to_str(errors).replace("'","")} if nw_type == NwDef.PUBLIC_NW: # nw_device = nw_device_entry nw_phy_if = nw_phy_if_entry bridge_info = dynamic_map() bridge_info.name = nw_device bridge_info.phy_list = nw_phy_if new_nw_def = NwDef(nw_id,nw_type,nw_name,nw_desc,False,scope, bridge_info=bridge_info) else: # bridge_info = dynamic_map() bridge_info.name = nw_device ipv4_info = dynamic_map() ipv4_info.ip_network = nw_address_space # assign first address in the range to the # bridge ip = IP(nw_address_space) bridge_info.ip_address = ip[1].strNormal() bridge_info.netmask = ip.netmask().strNormal() dhcp_info = dynamic_map() r = nw_dhcp_range.split("-") if len(r) == 2: dhcp_info.dhcp_start = r[0].strip() dhcp_info.dhcp_end = r[1].strip() nat_info = dynamic_map() nat_info.interface = nw_nat_fwding new_nw_def = NwDef(nw_id,nw_type,nw_name,nw_desc,False,scope, bridge_info=bridge_info,ipv4_info=ipv4_info,dhcp_info=dhcp_info,nat_info=nat_info) #convert following parameters into dictionary object to save into network_definitions table. new_nw_def.bridge_info = self.get_dic(new_nw_def.bridge_info) new_nw_def.vlan_info = self.get_dic(new_nw_def.vlan_info) new_nw_def.bond_info = self.get_dic(new_nw_def.bond_info) new_nw_def.ipv4_info = self.get_dic(new_nw_def.ipv4_info) new_nw_def.dhcp_info = self.get_dic(new_nw_def.dhcp_info) new_nw_def.nat_info = self.get_dic(new_nw_def.nat_info) # manager = Basic.getGridManager() # group=manager.getGroup(pool_id) # print "pool_id==",pool_id,"node_id==",node_id errs = [] #Validations if scope == constants.SCOPE_S: alldefns = DBSession.query(ServerDefLink).filter_by(server_id = managed_node.id, def_type = to_unicode(constants.NETWORK)) elif scope == constants.SCOPE_SP: alldefns = DBSession.query(SPDefLink).filter_by(group_id = group_id, def_type = to_unicode(constants.NETWORK)) elif scope == constants.SCOPE_DC: alldefns = DBSession.query(DCDefLink).filter_by(site_id=site_id, def_type = to_unicode(constants.NETWORK)) for node_defn in alldefns: #Check for duplicate name rowNF = DBSession.query(NwDef).filter_by(id=node_defn.def_id, name=new_nw_def.name).first() if rowNF: return {'success':False,'msg':"Network definition with the same name already exists"} #raise Exception("Network definition with the same name already exists") #Check for address range rowNF = DBSession.query(NwDef).filter_by(id=node_defn.def_id).first() if rowNF: if new_nw_def.ipv4_info.get("ip_network") == rowNF.ipv4_info.get("ip_network"): return {'success':False,'msg':"Network definition with the same address space already exists"} #raise Exception("Network definition with the same address space already exists") errs = self.sync_manager.add_defn(new_nw_def, site, group, managed_node, auth, to_unicode(constants.NETWORK), constants.ATTACH, "ADD_NETWORK_DEF", self.nw_manager, self.manager, scope) if scope == constants.SCOPE_DC or scope == constants.SCOPE_SP: oos_count = 0 status = to_unicode(constants.IN_SYNC) details = None self.sync_manager.add_node_defn(managed_node.id, new_nw_def.id, to_unicode(constants.NETWORK), status, details, constants.SCOPE_S) op = constants.ATTACH update_status=True errs=[] self.nw_manager.sync_node_defn(managed_node, group_id, site_id, new_nw_def, to_unicode(constants.NETWORK), op, self.nw_manager, update_status, errs) if errs: if len(errs) > 0: add_mode=True self.sync_manager.remove_defn(new_nw_def, site, group, managed_node, auth, to_unicode(constants.NETWORK), constants.DETACH, "REMOVE_NETWORK_DEF", self.nw_manager, self.manager, add_mode, group_list, scope) return {'success':False,'msg':to_str(errs).replace("'","")} print "WEb New definition ",new_nw_def except Exception, ex: import traceback print print_traceback() print "Exception===",ex LOGGER.error(to_str(ex).replace("'","")) #if we get any exception while adding/ sync definition then are removing the definition. add_mode=True if new_nw_def: self.sync_manager.remove_defn(new_nw_def, site, group, managed_node, auth, to_unicode(constants.NETWORK), constants.DETACH, "REMOVE_NETWORK_DEF", self.nw_manager, self.manager, add_mode, group_list, scope) return {'success':False,'msg':to_str(ex).replace("'","")}