def _set_defaults(self, devlist_func): # Default file backed PV guests to tap driver for d in devlist_func(VirtualDevice.VIRTUAL_DEV_DISK): if (d.type == VirtualDisk.TYPE_FILE and _util.is_blktap_capable() and d.driver_name == None): d.driver_name = VirtualDisk.DRIVER_TAP Guest._set_defaults(self, devlist_func)
def __init__(self, type=None, arch=None, connection=None, hypervisorURI=None, emulator=None, installer=None, caps=None, conn=None): Guest.__init__(self, type, connection, hypervisorURI, installer, caps=caps, conn=conn) self.emulator = emulator if arch: self.arch = arch
def _set_defaults(self, devlist_func): # Default file backed PV guests to tap driver for d in devlist_func(VirtualDevice.VIRTUAL_DEV_DISK): if (d.type == VirtualDisk.TYPE_FILE and _util.is_blktap_capable() and d.driver_name == None): d.driver_name = VirtualDisk.DRIVER_TAP Guest._set_defaults(self, devlist_func)
def __init__(self, type=None, connection=None, hypervisorURI=None, installer=None): if not installer: installer = DistroInstaller(type = type, os_type = "xen", conn=connection) Guest.__init__(self, type, connection, hypervisorURI, installer) self.disknode = "xvd" self._diskbus = "xen" self.features = {"acpi": False, "apic": False, "pae": False}
def Sistema(): u = Usuario("Eduardo") u.boasVindas() g1 = Guest("Caio") g1.boasVindas() g1.descreve() g1.despedida() r1 = Regular("Felipe") r1.boasVindas() r1.dashboard() r1.descreve() r1.despedida() g2 = Group("Grupo Python") g2.boasVindas() g2.descreve() g2.groupBoard() g2.despedida() r2 = Root("root") r2.boasVindas() r2.descreve() r2.excluirTodos() r2.despedida()
def __init__(self, type=None, connection=None, hypervisorURI=None, installer=None): if not installer: installer = DistroInstaller(type=type, os_type="xen", conn=connection) Guest.__init__(self, type, connection, hypervisorURI, installer) self.disknode = "xvd" self._diskbus = "xen" self.features = {"acpi": False, "apic": False, "pae": False}
def __init__( self, type=None, arch=None, connection=None, hypervisorURI=None, emulator=None, installer=None, caps=None, conn=None, ): Guest.__init__(self, type, connection, hypervisorURI, installer, caps=caps, conn=conn) self.emulator = emulator if arch: self.arch = arch
def addAGuest(): name = input("Write a name: ") surname = input("Write a surname: ") phone = input("Write a phone number: ") guest = Guest(name, surname, phone) interfaceDB.addGuest(guest)
def __init__(self, type=None, arch=None, connection=None, hypervisorURI=None, emulator=None, installer=None): if not installer: installer = DistroInstaller.DistroInstaller(type=type, os_type="hvm", conn=connection) Guest.__init__(self, type, connection, hypervisorURI, installer) self.disknode = "hd" self._diskbus = "ide" self.features = { "acpi": None, "pae": _util.is_pae_capable(self.conn), "apic": None } self.emulator = emulator if arch: self.arch = arch self.loader = None guest = self._caps.guestForOSType(type=self.installer.os_type, arch=self.arch) if (not self.emulator) and guest: for dom in guest.domains: if dom.hypervisor_type == self.installer.type: self.emulator = dom.emulator self.loader = dom.loader # Fall back to default hardcoding if self.emulator is None: if self.type == "xen": if self._caps.host.arch in ("x86_64"): self.emulator = "/usr/lib64/xen/bin/qemu-dm" else: self.emulator = "/usr/lib/xen/bin/qemu-dm" if (not self.loader) and self.type == "xen": self.loader = "/usr/lib/xen/boot/hvmloader"
def __init__(self): self.anne = Guest("Anne", 0) self.ola = Guest("Ola", 1) self.jan = Guest("Jan", 2) self.sondre = Guest("Sondre", 3) # TODO self.guests = [self.anne, self.ola, self.jan, self.sondre] self.assigned_count = 0
def update_list(): list_from_the_list = str(list_box.get(tk.ANCHOR)) list_from_the_list = list_from_the_list.split(',') id = list_from_the_list[0][1:] guest = Guest(entry_name_update.get(), entry_surname_update.get(), entry_phone_update.get()) print(entry_name_update.get(), entry_surname_update.get(), entry_phone_update.get()) interfaceDB.updateGuest(id, guest)
def updateGuest(): interfaceDB.selectGuests() id = input("Which person want to update? Chose id: ") name = input("Write a name: ") surname = input("Write a surname: ") phone = input("Write a phone number: ") guest = Guest(name, surname, phone) interfaceDB.updateGuest(id, guest)
def retreive_guest(self, ID): # If a guest parked before and came back to release their car, we need to retrieve their information from the guest file f = open('437Guest.txt', 'r') line = f.readline() while line != '': test = line.split() if ID == test[4]: car1 = Car(test[2], test[3], test[0], test[1]) p1 = Guest(test[0], test[1], car1, self, self.CarRotationManager,ID,test[5]) # ---initialize guest--- return p1 line = f.readline() return None
def _set_defaults(self, devlist_func): disktype = VirtualDevice.VIRTUAL_DEV_DISK nettype = VirtualDevice.VIRTUAL_DEV_NET disk_bus = self._lookup_device_param(disktype, "bus") net_model = self._lookup_device_param(nettype, "model") # Only overwrite params if they weren't already specified for net in devlist_func(nettype): if net_model and not net.model: net.model = net_model for disk in devlist_func(disktype): if (disk_bus and not disk.bus and disk.device == VirtualDisk.DEVICE_DISK): disk.bus = disk_bus if self.clock.offset == None: self.clock.offset = self._lookup_osdict_key("clock") # Run this last, so we get first crack at disk attributes Guest._set_defaults(self, devlist_func)
def submit_window(): if((guest_name.get() == "") or (guest_number.get() == "") or (total_guest.get() == "") or (room_type.get() == "") or (not bool(selected_dish)) or (additional_bed.get() == "")): #show message messagebox.showwarning("Incomplete Data Input","Please enter all required fields") pass else: #insert new data list_data.append(Guest(guest_name.get(), guest_number.get(), total_guest.get(), room_type.get(), room_number.get(), ({i: selected_dish[i].get() for i in selected_dish}), additional_bed.get(), "Rp " + room_price.get(), filename, image)) #reset form resetForm() #show message messagebox.showinfo("Data Added", "The data has been added")
def _set_defaults(self, devlist_func): disktype = VirtualDevice.VIRTUAL_DEV_DISK nettype = VirtualDevice.VIRTUAL_DEV_NET disk_bus = self._lookup_device_param(disktype, "bus") net_model = self._lookup_device_param(nettype, "model") # Only overwrite params if they weren't already specified for net in devlist_func(nettype): if net_model and not net.model: net.model = net_model for disk in devlist_func(disktype): if (disk_bus and not disk.bus and disk.device == VirtualDisk.DEVICE_DISK): disk.bus = disk_bus if self.clock.offset == None: self.clock.offset = self._lookup_osdict_key("clock") # Run this last, so we get first crack at disk attributes Guest._set_defaults(self, devlist_func)
def continue_as_guest(self): #Function that takes info to create a guest; then adds the info into the guest file.It returns a new Guest object. Name = input("Please enter your name:\n") FamilyName = input("Please enter your family name:\n") model = input("Please enter your car model:\n") model = self.remove_spaces(model) platenumber = input("Please enter your car's plate number:\n") car1 = Car(model, platenumber, Name, FamilyName) p1 = Guest(Name, FamilyName, car1, self, self.CarRotationManager) # ---initialize guest--- print("Welcome" + " " + Name + "!") print("Your ID number is: " + str(p1.uniqueID)) print("Remember your ID number, you must enter it back to pick up your car.") return p1
def loadGuestsDict(): guests = json.loads(open('./Guests.json').read()) currentGuests = {} for guest in guests: currentRes = Reservation(guest['reservation']['roomNumber'], \ guest['reservation']['startTimestamp'], \ guest['reservation']['endTimestamp']) newGuest = Guest(guest['id'], \ guest['firstName'], \ guest['lastName'], \ currentRes) currentGuests.update({newGuest.id: newGuest}) return currentGuests
def __init__(self, type=None, arch=None, connection=None, hypervisorURI=None, emulator=None, installer=None): if not installer: installer = DistroInstaller.DistroInstaller(type = type, os_type = "hvm", conn=connection) Guest.__init__(self, type, connection, hypervisorURI, installer) self.disknode = "hd" self._diskbus = "ide" self.features = { "acpi": None, "pae": _util.is_pae_capable(self.conn), "apic": None } self.emulator = emulator if arch: self.arch = arch self.loader = None guest = self._caps.guestForOSType(type=self.installer.os_type, arch=self.arch) if (not self.emulator) and guest: for dom in guest.domains: if dom.hypervisor_type == self.installer.type: self.emulator = dom.emulator self.loader = dom.loader # Fall back to default hardcoding if self.emulator is None: if self.type == "xen": if self._caps.host.arch in ("x86_64"): self.emulator = "/usr/lib64/xen/bin/qemu-dm" else: self.emulator = "/usr/lib/xen/bin/qemu-dm" if (not self.loader) and self.type == "xen": self.loader = "/usr/lib/xen/boot/hvmloader"
def upd_time(self, dt): self.time_to_finish -= dt if self.time_to_finish <= 1e-5: self.time_to_finish += self.work_time_distribution.generate() if random() < 0.3: # еда с собой if len(self.queues['outside']) <= self.max_outside_len: self.queues['outside'].append(Guest('outside')) else: return 'lost out' else: if len(self.queues['inside']) <= self.max_inside_len and len( self.saloon) < self.saloon_capacity: new_guest = Guest('inside') self.queues['inside'].append(new_guest) self.saloon.append(new_guest) else: if len(self.saloon) >= self.saloon_capacity: return 'lost saloon' return 'lost in' return 'gen' return None
def __init__(self): self.data = {} rawData = json.load(open(r'data.json', 'r', encoding="utf-8")) for day in rawData: tempDay = Day(day['month'], day['day'], day['weekday']) for event in day['event']: tempEvent = Event(event['time'], event['place'], event['celebration'], event['description']) for guest in event['aGuestList']: tempGuest = Guest(guest['title'], guest['surname'], guest['name'], guest['patronymic'], guest['sequenceNumber']) tempEvent.addAGuestList(tempGuest) tempDay.addEvent(tempEvent) self.data[str(day['day']) + ' ' + day['month']] = tempDay
def readGuestsFromFile(filename, list): """ Read the guests from the specified file to the given list. :param filename: Name of the file with the guests data. :param list: List to append new guests to. :return: Guests list. """ file = open(filename, "r") for line in file: string = line.rstrip().split("|") id = int(string[0]) name = string[1] surname = string[2] friends = [int(x) for x in string[3].split(",")] list.append(Guest(id, name, surname, friends)) return list
def parseGuest(self, guest): hostname = self.parseTextElement(guest, "hostname") memorySize = self.parseTextElement(guest, "memory-size") vcpuCount = self.parseTextElement(guest, "vcpu-count") ksFile = self.parseTextElement(guest, "ks-file") networkSettingsFile = self.parseTextElement(guest, "network-settings-file") storageFile = self.parseStorageFile(guest) imageFile = self.parseImageFile(guest) ipv4 = self.parseIP(guest, "ipv4", IP.IPv4) ipv6 = self.parseIP(guest, "ipv6", IP.IPv6) return Guest(hostname, memorySize, vcpuCount, imageFile, ksFile, networkSettingsFile, storageFile, ipv4, ipv6)
def update_dictionary(host, vmid, mem_size): host_vm_dict = getHostVMDict() value = host_vm_dict[host][vmid] old_memory = value.current_memory required_memory = float(mem_size) - float(old_memory) guest = Guest(value.vmip, value.vmid, value.current_cpu, value.max_cpu, float(mem_size), value.max_memory, value.io, value.start_time) #Update memory for guest in guest dictionary addOrUpdateDictionaryOfVM(host, vmid, guest) #Update memory for guest in host dictionary update_resources_after_mem_scaling(host, vmid, guest, required_memory)
def seed(): dbStag.session.add_all([ Guest('73F', 'Armando', '*****@*****.**', '01/03/1990', '10/02/2017'), Guest('33W', 'João', '*****@*****.**', '21/01/1984', '10/02/2017'), Guest('12D', 'José', '*****@*****.**', None, '10/02/2017'), Guest('43F', 'Maico', '*****@*****.**', '22/11/1990', '10/02/2017'), Guest('20S', 'Will', '*****@*****.**', '11/05/1950', '10/02/2017'), Guest('84X', 'Carla', '*****@*****.**', '22/11/1991', '10/02/2017') ]) dbStag.session.commit()
class InvitationNode: def __init__(self): self.anne = Guest("Anne", 0) self.ola = Guest("Ola", 1) self.jan = Guest("Jan", 2) self.sondre = Guest("Sondre", 3) # TODO self.guests = [self.anne, self.ola, self.jan, self.sondre] self.assigned_count = 0 def neighbours(self): result = list() invitation_node = self.copy_and_add_assignment(True) if not(invitation_node is None) and invitation_node.consistent(): result.append(invitation_node) invitation_node = self.copy_and_add_assignment(False) if not(invitation_node is None) and invitation_node.consistent(): result.append(invitation_node) return result # Makes a new node with assignment for one more guest def copy_and_add_assignment(self, is_invited): if self.assigned_count == len(self.guests): return None invitation_node = InvitationNode() for i in range(self.assigned_count): invitation_node.guests[i].set_invited(self.guests[i].is_invited()) invitation_node.guests[self.assigned_count].set_invited(is_invited) invitation_node.assigned_count = self.assigned_count + 1 return invitation_node # Constraints for the invitation problem def consistent(self): constraint1 = self.passes_test(not(self.anne.is_invited()) or not(self.ola.is_invited()), self.ola.rank) constraint2 = self.passes_test(not(self.anne.is_invited() or self.jan.is_invited()), self.jan.rank) # TODO, add constraints here return constraint1 and constraint2 # Checks if an assignment passes a logical test # It passes if it is true or if the highest ranked guest has not been assigned yet def passes_test(self, bol, max_rank): if max_rank < self.assigned_count: return bol return True def all_assigned(self): return self.assigned_count == len(self.guests) def __str__(self): string = "{" n_guests = len(self.guests) for i in range(len(self.guests)-1): guest = self.guests[i] if guest.is_invited(): string += guest.name + ", " string += self.guests[(n_guests-1)].name string += "}" return string def __hash__(self): result = 0 for i in range(self.assigned_count): if self.guests[i].is_invited(): result += i return result
def guestButtonClicked(self): self.loginWindow.withdraw() guest = Guest()
#host_vm_dict[key]={"vm1":Guest("192.168.1.14","vm1", float(1), float(3),float(42424),float(424242),float(1))} if (guest == None): del host_vm_dict[hostName][vmid] pickleNodeVMDictionary(host_vm_dict) else: host_vm_dict[hostName][vmid] = guest pickleNodeVMDictionary(host_vm_dict) print host_vm_dict def pickleNodeVMDictionary(dictionary): lock = LockFile("/var/lib/virtdc/framework/host_vm_dict.pkl") with lock: #print "I locked", lock.path with open('/var/lib/virtdc/framework/host_vm_dict.pkl', 'w') as host_vm_pickle_out: pickle.dump(dictionary, host_vm_pickle_out) #host_vm_pickle_out.close() #====================================================================== # Function calls 42424345353 #====================================================================== if __name__ == "__main__": # stuff only to run when not called via 'import' here addOrUpdateDictionaryOfVM( 'node1', 'Task1', Guest("192.168.1.14", "Task1", float(1), float(3), float(42424345353), float(424242), float(1), time.time())) #addOrUpdateDictionaryOfVM('', '','')
def vm_submitjob(vmid, cpu, memory, max_memory, io): try: #Activity Log vmsubmission_log = open( '/var/lib/virtdc/logs/activity_logs/vmsubmission.log', 'a+') obj = NodeFinder() #memory=float(_base_memory_size) + float(memory) #print "Memory "+str(memory) #Identify is there a space for the VM host = obj.is_space_available_for_vm(cpu, memory, io) print 'VMID "', vmid print 'CPU "', cpu print 'memory"', memory print 'max_memory"', max_memory print 'io"', io if host is None: print "Cant create new domain. Space not available." #print subprocess.call("date") #print 'VMID "', vmid #print 'CPU "', cpu #print 'memory"', memory #print 'max_memory"', max_memory #print 'io"', io return False prefix_host = host print host #Code to check whether the VM can be placed if (host == _master): prefix_host = '' _imageCopyCmd = "cp " _cloneCmd = "virsh create " else: _cloneCmd = "virsh --connect qemu+ssh://" + host + "/system create " prefix_host = host + ":" _imageCopyCmd = "scp " #print "The node is %s",host #To get the guest os configuration xml for the first time #cmd = "virsh dumpxml Test_clone > /root/Desktop/PYTHON/guestconfig.xml" #p = subprocess.Popen(cmd, shell=True, stderr=subprocess.PIPE) #command to get the xml into python string for further updates. guestconfig.xml needs to be copied(physically present) int the same folder of this script nodeInfo = "cat " + guest_config_path xmlstring = subprocess.check_output(nodeInfo, shell=True, stderr=subprocess.PIPE) #command to copy the iso image to the destination. Every VM will have an individual iso image. (I think this copy can be cleared later on). Make the nodes passwordless image_path = guest_image + vmid + ".img" image_dest = prefix_host + guest_image + vmid + ".img" cp_cmd = _imageCopyCmd + guest_image + "base_image.img " + image_dest copy_image = subprocess.check_output(cp_cmd, shell=True, stderr=subprocess.PIPE) vmsubmission_log.write( str(datetime.datetime.now()) + '::Copy Image ::' + host + ' :: ' + vmid + ' :: Successfully copied the image\n') #uuid = subprocess.check_output("uuidgen", shell=True, stderr=subprocess.PIPE) #config update based on the new VM requiement #image_path max_memory current_memory current_cpu max_cpu xmlstring = xmlstring.replace("vm_name", vmid) #xmlstring=xmlstring.replace("vm_uuid", uuid); xmlstring = xmlstring.replace("max_memory", str(int(max_memory))) xmlstring = xmlstring.replace("current_memory", str(int(memory))) xmlstring = xmlstring.replace("current_cpu", str(int(cpu))) xmlstring = xmlstring.replace("max_cpu", "8") xmlstring = xmlstring.replace("image_path", image_path) #command to write the xml string to file guest_info_file = guest_config_file_storage_path + vmid + ".xml" config_temp_file = open(guest_info_file, "w") config_temp_file.write(xmlstring) config_temp_file.close() #command to clone the image clone = _cloneCmd + guest_info_file clone_out = subprocess.check_output(clone, shell=True, stderr=subprocess.PIPE) vmsubmission_log.write( str(datetime.datetime.now()) + '::Create VM ::' + host + ' :: ' + vmid + ' :: Successfully created the VM\n') #VM Successfully created. Update the node dictionary pickle host = obj.place_job(host, cpu, max_memory, io) if host is None: print 'Issue in updating node dictionary' vmsubmission_log.write( str(datetime.datetime.now()) + '::Update Node Dictionary ::' + host + ' :: ' + vmid + ' :: Issue in updating node dictionary\n') return False # Wait for VM to boot up time.sleep(60) # Get the IP address of Virtual Machine and update in VM_Info_Updater guest_ip = getGuestIP(host.strip(), vmid.strip(), "root", "Teamb@123") # If get ip failed, terminate this VM if guest_ip == "": print 'Issue in retrieving public IP of domain : Terminating the domain!' vmsubmission_log.write( str(datetime.datetime.now()) + '::Issue in retrieving public IP of domain : Terminating the domain - ' + vmid + '\n') vm_terminate_guest(host.strip(), vmid.strip()) return False # Making the max cpu as 8 for all VM's addOrUpdateDictionaryOfVM( host, vmid, Guest(guest_ip, vmid, float(cpu), float(8), float(memory), float(max_memory), float(1), str(datetime.datetime.now()))) vmsubmission_log.write( str(datetime.datetime.now()) + '::Update IP::' + host + ' :: ' + vmid + ' :: Successfully updated the IP\n') # copy host_config.txt file to guest # this will start monitor_agent on guest do_prereq_start_workload(host, vmid) #Run Job in Guest runJobOnVM(host, vmid) vmsubmission_log.write( str(datetime.datetime.now()) + '::Run Job::' + host + ' :: ' + vmid + ' :: Successfully ran the job\n') return True except Exception, e: print 'Error occured during domain creation/run job' + str(vmid) #exc_type, exc_obj, exc_tb = sys.exc_info() #fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] #print exc_type, fname, exc_tb.tb_lineno vmsubmission_log.write( str(datetime.datetime.now()) + ' :: Create Guest :: ' + vmid + ' :: Cannot create the guest\n') #print "error>",e.output,'<' vmsubmission_log.write(str(e) + '\n') mail_subject = 'Guest creation error - ' + str(vmid) mail_content = 'Error occured during guest creation ' + vmid + ' . The error as follows, \n\n' + str( e) + '\n' send_support_mail(mail_subject, mail_content.strip()) return False
def add_to_list(): guest = Guest(entry_name.get(), entry_surname.get(), entry_phone.get()) print(entry_name.get(), entry_surname.get(), entry_phone.get()) interfaceDB.addGuest(guest)