idx int64 0 63k | question stringlengths 61 4.03k | target stringlengths 6 1.23k |
|---|---|---|
32,400 | def get_project ( self , project_id ) : try : UUID ( project_id , version = 4 ) except ValueError : raise aiohttp . web . HTTPBadRequest ( text = "Project ID {} is not a valid UUID" . format ( project_id ) ) if project_id not in self . _projects : raise aiohttp . web . HTTPNotFound ( text = "Project ID {} doesn't exist... | Returns a Project instance . |
32,401 | def _check_available_disk_space ( self , project ) : try : used_disk_space = psutil . disk_usage ( project . path ) . percent except FileNotFoundError : log . warning ( 'Could not find "{}" when checking for used disk space' . format ( project . path ) ) return if used_disk_space >= 90 : message = 'Only {}% or less of ... | Sends a warning notification if disk space is getting low . |
32,402 | def create_project ( self , name = None , project_id = None , path = None ) : if project_id is not None and project_id in self . _projects : return self . _projects [ project_id ] project = Project ( name = name , project_id = project_id , path = path ) self . _check_available_disk_space ( project ) self . _projects [ ... | Create a project and keep a references to it in project manager . |
32,403 | def remove_project ( self , project_id ) : if project_id not in self . _projects : raise aiohttp . web . HTTPNotFound ( text = "Project ID {} doesn't exist" . format ( project_id ) ) del self . _projects [ project_id ] | Removes a Project instance from the list of projects in use . |
32,404 | def check_hardware_virtualization ( self , source_node ) : for project in self . _projects . values ( ) : for node in project . nodes : if node == source_node : continue if node . hw_virtualization and node . __class__ . __name__ != source_node . __class__ . __name__ : return False return True | Checks if hardware virtualization can be used . |
32,405 | def ports_mapping ( self , ports ) : if ports != self . _ports_mapping : if len ( self . _nios ) > 0 : raise NodeError ( "Can't modify a cloud already connected." ) port_number = 0 for port in ports : port [ "port_number" ] = port_number port_number += 1 self . _ports_mapping = ports | Set the ports on this cloud . |
32,406 | def close ( self ) : if not ( yield from super ( ) . close ( ) ) : return False for nio in self . _nios . values ( ) : if nio and isinstance ( nio , NIOUDP ) : self . manager . port_manager . release_udp_port ( nio . lport , self . _project ) yield from self . _stop_ubridge ( ) log . info ( 'Cloud "{name}" [{id}] has b... | Closes this cloud . |
32,407 | def _add_linux_ethernet ( self , port_info , bridge_name ) : interface = port_info [ "interface" ] if gns3server . utils . interfaces . is_interface_bridge ( interface ) : network_interfaces = [ interface [ "name" ] for interface in self . _interfaces ( ) ] i = 0 while True : tap = "gns3tap{}-{}" . format ( i , port_in... | Use raw sockets on Linux . |
32,408 | def add_nio ( self , nio , port_number ) : if port_number in self . _nios : raise NodeError ( "Port {} isn't free" . format ( port_number ) ) log . info ( 'Cloud "{name}" [{id}]: NIO {nio} bound to port {port}' . format ( name = self . _name , id = self . _id , nio = nio , port = port_number ) ) try : yield from self .... | Adds a NIO as new port on this cloud . |
32,409 | def update_nio ( self , port_number , nio ) : bridge_name = "{}-{}" . format ( self . _id , port_number ) if self . _ubridge_hypervisor and self . _ubridge_hypervisor . is_running ( ) : yield from self . _ubridge_apply_filters ( bridge_name , nio . filters ) | Update an nio on this node |
32,410 | def remove_nio ( self , port_number ) : if port_number not in self . _nios : raise NodeError ( "Port {} is not allocated" . format ( port_number ) ) nio = self . _nios [ port_number ] if isinstance ( nio , NIOUDP ) : self . manager . port_manager . release_udp_port ( nio . lport , self . _project ) log . info ( 'Cloud ... | Removes the specified NIO as member of cloud . |
32,411 | def pid_lock ( path ) : if os . path . exists ( path ) : pid = None try : with open ( path ) as f : try : pid = int ( f . read ( ) ) os . kill ( pid , 0 ) except ( OSError , SystemError , ValueError ) : pid = None except OSError as e : log . critical ( "Can't open pid file %s: %s" , pid , str ( e ) ) sys . exit ( 1 ) i... | Write the file in a file on the system . Check if the process is not already running . |
32,412 | def kill_ghosts ( ) : detect_process = [ "vpcs" , "ubridge" , "dynamips" ] for proc in psutil . process_iter ( ) : try : name = proc . name ( ) . lower ( ) . split ( "." ) [ 0 ] if name in detect_process : proc . kill ( ) log . warning ( "Killed ghost process %s" , name ) except ( psutil . NoSuchProcess , psutil . Acce... | Kill process from previous GNS3 session |
32,413 | def qemu_path ( self , qemu_path ) : if qemu_path and os . pathsep not in qemu_path : if sys . platform . startswith ( "win" ) and ".exe" not in qemu_path . lower ( ) : qemu_path += "w.exe" new_qemu_path = shutil . which ( qemu_path , path = os . pathsep . join ( self . _manager . paths_list ( ) ) ) if new_qemu_path is... | Sets the QEMU binary path this QEMU VM . |
32,414 | def _disk_setter ( self , variable , value ) : value = self . manager . get_abs_image_path ( value ) if not self . linked_clone : for node in self . manager . nodes : if node != self and getattr ( node , variable ) == value : raise QemuError ( "Sorry a node without the linked base setting enabled can only be used once ... | Use by disk image setter for checking and apply modifications |
32,415 | def hdc_disk_interface ( self , hdc_disk_interface ) : self . _hdc_disk_interface = hdc_disk_interface log . info ( 'QEMU VM "{name}" [{id}] has set the QEMU hdc disk interface to {interface}' . format ( name = self . _name , id = self . _id , interface = self . _hdc_disk_interface ) ) | Sets the hdc disk interface for this QEMU VM . |
32,416 | def hdd_disk_interface ( self , hdd_disk_interface ) : self . _hdd_disk_interface = hdd_disk_interface log . info ( 'QEMU VM "{name}" [{id}] has set the QEMU hdd disk interface to {interface}' . format ( name = self . _name , id = self . _id , interface = self . _hdd_disk_interface ) ) | Sets the hdd disk interface for this QEMU VM . |
32,417 | def cdrom_image ( self , cdrom_image ) : self . _cdrom_image = self . manager . get_abs_image_path ( cdrom_image ) log . info ( 'QEMU VM "{name}" [{id}] has set the QEMU cdrom image path to {cdrom_image}' . format ( name = self . _name , id = self . _id , cdrom_image = self . _cdrom_image ) ) | Sets the cdrom image for this QEMU VM . |
32,418 | def bios_image ( self , bios_image ) : self . _bios_image = self . manager . get_abs_image_path ( bios_image ) log . info ( 'QEMU VM "{name}" [{id}] has set the QEMU bios image path to {bios_image}' . format ( name = self . _name , id = self . _id , bios_image = self . _bios_image ) ) | Sets the bios image for this QEMU VM . |
32,419 | def boot_priority ( self , boot_priority ) : self . _boot_priority = boot_priority log . info ( 'QEMU VM "{name}" [{id}] has set the boot priority to {boot_priority}' . format ( name = self . _name , id = self . _id , boot_priority = self . _boot_priority ) ) | Sets the boot priority for this QEMU VM . |
32,420 | def adapters ( self , adapters ) : self . _ethernet_adapters . clear ( ) for adapter_number in range ( 0 , adapters ) : self . _ethernet_adapters . append ( EthernetAdapter ( ) ) log . info ( 'QEMU VM "{name}" [{id}]: number of Ethernet adapters changed to {adapters}' . format ( name = self . _name , id = self . _id , ... | Sets the number of Ethernet adapters for this QEMU VM . |
32,421 | def mac_address ( self , mac_address ) : if not mac_address : self . _mac_address = "52:%s:%s:%s:%s:00" % ( self . project . id [ - 4 : - 2 ] , self . project . id [ - 2 : ] , self . id [ - 4 : - 2 ] , self . id [ - 2 : ] ) else : self . _mac_address = mac_address log . info ( 'QEMU VM "{name}" [{id}]: MAC address chan... | Sets the MAC address for this QEMU VM . |
32,422 | def legacy_networking ( self , legacy_networking ) : if legacy_networking : log . info ( 'QEMU VM "{name}" [{id}] has enabled legacy networking' . format ( name = self . _name , id = self . _id ) ) else : log . info ( 'QEMU VM "{name}" [{id}] has disabled legacy networking' . format ( name = self . _name , id = self . ... | Sets either QEMU legacy networking commands are used . |
32,423 | def acpi_shutdown ( self , acpi_shutdown ) : if acpi_shutdown : log . info ( 'QEMU VM "{name}" [{id}] has enabled ACPI shutdown' . format ( name = self . _name , id = self . _id ) ) else : log . info ( 'QEMU VM "{name}" [{id}] has disabled ACPI shutdown' . format ( name = self . _name , id = self . _id ) ) self . _acpi... | Sets either this QEMU VM can be ACPI shutdown . |
32,424 | def cpu_throttling ( self , cpu_throttling ) : log . info ( 'QEMU VM "{name}" [{id}] has set the percentage of CPU allowed to {cpu}' . format ( name = self . _name , id = self . _id , cpu = cpu_throttling ) ) self . _cpu_throttling = cpu_throttling self . _stop_cpulimit ( ) if cpu_throttling : self . _set_cpu_throttlin... | Sets the percentage of CPU allowed . |
32,425 | def process_priority ( self , process_priority ) : log . info ( 'QEMU VM "{name}" [{id}] has set the process priority to {priority}' . format ( name = self . _name , id = self . _id , priority = process_priority ) ) self . _process_priority = process_priority | Sets the process priority . |
32,426 | def cpus ( self , cpus ) : log . info ( 'QEMU VM "{name}" [{id}] has set the number of vCPUs to {cpus}' . format ( name = self . _name , id = self . _id , cpus = cpus ) ) self . _cpus = cpus | Sets the number of vCPUs this QEMU VM . |
32,427 | def options ( self , options ) : log . info ( 'QEMU VM "{name}" [{id}] has set the QEMU options to {options}' . format ( name = self . _name , id = self . _id , options = options ) ) if not sys . platform . startswith ( "linux" ) : if "-no-kvm" in options : options = options . replace ( "-no-kvm" , "" ) if "-enable-kvm... | Sets the options for this QEMU VM . |
32,428 | def initrd ( self , initrd ) : initrd = self . manager . get_abs_image_path ( initrd ) log . info ( 'QEMU VM "{name}" [{id}] has set the QEMU initrd path to {initrd}' . format ( name = self . _name , id = self . _id , initrd = initrd ) ) if "asa" in initrd : self . project . emit ( "log.warning" , { "message" : "Warnin... | Sets the initrd path for this QEMU VM . |
32,429 | def kernel_image ( self , kernel_image ) : kernel_image = self . manager . get_abs_image_path ( kernel_image ) log . info ( 'QEMU VM "{name}" [{id}] has set the QEMU kernel image path to {kernel_image}' . format ( name = self . _name , id = self . _id , kernel_image = kernel_image ) ) self . _kernel_image = kernel_imag... | Sets the kernel image path for this QEMU VM . |
32,430 | def kernel_command_line ( self , kernel_command_line ) : log . info ( 'QEMU VM "{name}" [{id}] has set the QEMU kernel command line to {kernel_command_line}' . format ( name = self . _name , id = self . _id , kernel_command_line = kernel_command_line ) ) self . _kernel_command_line = kernel_command_line | Sets the kernel command line for this QEMU VM . |
32,431 | def _set_process_priority ( self ) : if self . _process_priority == "normal" : return if sys . platform . startswith ( "win" ) : try : import win32api import win32con import win32process except ImportError : log . error ( "pywin32 must be installed to change the priority class for QEMU VM {}" . format ( self . _name ) ... | Changes the process priority |
32,432 | def _stop_cpulimit ( self ) : if self . _cpulimit_process and self . _cpulimit_process . returncode is None : self . _cpulimit_process . kill ( ) try : self . _process . wait ( 3 ) except subprocess . TimeoutExpired : log . error ( "Could not kill cpulimit process {}" . format ( self . _cpulimit_process . pid ) ) | Stops the cpulimit process . |
32,433 | def _set_cpu_throttling ( self ) : if not self . is_running ( ) : return try : if sys . platform . startswith ( "win" ) and hasattr ( sys , "frozen" ) : cpulimit_exec = os . path . join ( os . path . dirname ( os . path . abspath ( sys . executable ) ) , "cpulimit" , "cpulimit.exe" ) else : cpulimit_exec = "cpulimit" s... | Limits the CPU usage for current QEMU process . |
32,434 | def stop ( self ) : yield from self . _stop_ubridge ( ) with ( yield from self . _execute_lock ) : self . _hw_virtualization = False if self . is_running ( ) : log . info ( 'Stopping QEMU VM "{}" PID={}' . format ( self . _name , self . _process . pid ) ) try : if self . acpi_shutdown : yield from self . _control_vm ( ... | Stops this QEMU VM . |
32,435 | def _control_vm ( self , command , expected = None ) : result = None if self . is_running ( ) and self . _monitor : log . debug ( "Execute QEMU monitor command: {}" . format ( command ) ) try : log . info ( "Connecting to Qemu monitor on {}:{}" . format ( self . _monitor_host , self . _monitor ) ) reader , writer = yie... | Executes a command with QEMU monitor when this VM is running . |
32,436 | def close ( self ) : if not ( yield from super ( ) . close ( ) ) : return False self . acpi_shutdown = False yield from self . stop ( ) for adapter in self . _ethernet_adapters : if adapter is not None : for nio in adapter . ports . values ( ) : if nio and isinstance ( nio , NIOUDP ) : self . manager . port_manager . r... | Closes this QEMU VM . |
32,437 | def _get_vm_status ( self ) : result = yield from self . _control_vm ( "info status" , [ b"debug" , b"inmigrate" , b"internal-error" , b"io-error" , b"paused" , b"postmigrate" , b"prelaunch" , b"finish-migrate" , b"restore-vm" , b"running" , b"save-vm" , b"shutdown" , b"suspended" , b"watchdog" , b"guest-panicked" ] ) ... | Returns this VM suspend status . |
32,438 | def suspend ( self ) : if self . is_running ( ) : vm_status = yield from self . _get_vm_status ( ) if vm_status is None : raise QemuError ( "Suspending a QEMU VM is not supported" ) elif vm_status == "running" or vm_status == "prelaunch" : yield from self . _control_vm ( "stop" ) self . status = "suspended" log . debug... | Suspends this QEMU VM . |
32,439 | def resume ( self ) : vm_status = yield from self . _get_vm_status ( ) if vm_status is None : raise QemuError ( "Resuming a QEMU VM is not supported" ) elif vm_status == "paused" : yield from self . _control_vm ( "cont" ) log . debug ( "QEMU VM has been resumed" ) else : log . info ( "QEMU VM is not paused to be resume... | Resumes this QEMU VM . |
32,440 | def read_stdout ( self ) : output = "" if self . _stdout_file : try : with open ( self . _stdout_file , "rb" ) as file : output = file . read ( ) . decode ( "utf-8" , errors = "replace" ) except OSError as e : log . warning ( "Could not read {}: {}" . format ( self . _stdout_file , e ) ) return output | Reads the standard output of the QEMU process . Only use when the process has been stopped or has crashed . |
32,441 | def read_qemu_img_stdout ( self ) : output = "" if self . _qemu_img_stdout_file : try : with open ( self . _qemu_img_stdout_file , "rb" ) as file : output = file . read ( ) . decode ( "utf-8" , errors = "replace" ) except OSError as e : log . warning ( "Could not read {}: {}" . format ( self . _qemu_img_stdout_file , e... | Reads the standard output of the QEMU - IMG process . |
32,442 | def is_running ( self ) : if self . _process : if self . _process . returncode is None : return True else : self . _process = None return False | Checks if the QEMU process is running |
32,443 | def _get_qemu_img ( self ) : qemu_img_path = "" qemu_path_dir = os . path . dirname ( self . qemu_path ) try : for f in os . listdir ( qemu_path_dir ) : if f . startswith ( "qemu-img" ) : qemu_img_path = os . path . join ( qemu_path_dir , f ) except OSError as e : raise QemuError ( "Error while looking for qemu-img in ... | Search the qemu - img binary in the same binary of the qemu binary for avoiding version incompatibily . |
32,444 | def _graphic ( self ) : if sys . platform . startswith ( "win" ) : return [ ] if len ( os . environ . get ( "DISPLAY" , "" ) ) > 0 : return [ ] if "-nographic" not in self . _options : return [ "-nographic" ] return [ ] | Adds the correct graphic options depending of the OS |
32,445 | def _run_with_kvm ( self , qemu_path , options ) : if sys . platform . startswith ( "linux" ) and self . manager . config . get_section_config ( "Qemu" ) . getboolean ( "enable_kvm" , True ) and "-no-kvm" not in options : if os . path . basename ( qemu_path ) not in [ "qemu-system-x86_64" , "qemu-system-i386" , "qemu-k... | Check if we could run qemu with KVM |
32,446 | def update_settings ( self , settings ) : new_settings = copy . copy ( self . _settings ) new_settings . update ( settings ) if self . settings != new_settings : yield from self . _stop ( ) self . _settings = settings self . _controller . save ( ) if self . enable : yield from self . start ( ) else : if self . enable a... | Update settings and will restart the VM if require |
32,447 | def _get_engine ( self , engine ) : if engine in self . _engines : return self . _engines [ engine ] if engine == "vmware" : self . _engines [ "vmware" ] = VMwareGNS3VM ( self . _controller ) return self . _engines [ "vmware" ] elif engine == "virtualbox" : self . _engines [ "virtualbox" ] = VirtualBoxGNS3VM ( self . _... | Load an engine |
32,448 | def list ( self , engine ) : engine = self . _get_engine ( engine ) vms = [ ] try : for vm in ( yield from engine . list ( ) ) : vms . append ( { "vmname" : vm [ "vmname" ] } ) except GNS3VMError as e : if self . enable : raise e return vms | List VMS for an engine |
32,449 | def auto_start_vm ( self ) : if self . enable : try : yield from self . start ( ) except GNS3VMError as e : try : yield from self . _controller . add_compute ( compute_id = "vm" , name = "GNS3 VM ({})" . format ( self . current_engine ( ) . vmname ) , host = None , force = True ) except aiohttp . web . HTTPConflict : p... | Auto start the GNS3 VM if require |
32,450 | def start ( self ) : engine = self . current_engine ( ) if not engine . running : if self . _settings [ "vmname" ] is None : return log . info ( "Start the GNS3 VM" ) engine . vmname = self . _settings [ "vmname" ] engine . ram = self . _settings [ "ram" ] engine . vcpus = self . _settings [ "vcpus" ] engine . headless... | Start the GNS3 VM |
32,451 | def _check_network ( self , compute ) : try : vm_interfaces = yield from compute . interfaces ( ) vm_interface_netmask = None for interface in vm_interfaces : if interface [ "ip_address" ] == self . ip_address : vm_interface_netmask = interface [ "netmask" ] break if vm_interface_netmask : vm_network = ipaddress . ip_i... | Check that the VM is in the same subnet as the local server |
32,452 | def _suspend ( self ) : engine = self . current_engine ( ) if "vm" in self . _controller . computes : yield from self . _controller . delete_compute ( "vm" ) if engine . running : log . info ( "Suspend the GNS3 VM" ) yield from engine . suspend ( ) | Suspend the GNS3 VM |
32,453 | def _stop ( self ) : engine = self . current_engine ( ) if "vm" in self . _controller . computes : yield from self . _controller . delete_compute ( "vm" ) if engine . running : log . info ( "Stop the GNS3 VM" ) yield from engine . stop ( ) | Stop the GNS3 VM |
32,454 | def _convert_before_2_0_0_b3 ( self , dynamips_id ) : dynamips_dir = self . project . module_working_directory ( self . manager . module_name . lower ( ) ) for path in glob . glob ( os . path . join ( glob . escape ( dynamips_dir ) , "configs" , "i{}_*" . format ( dynamips_id ) ) ) : dst = os . path . join ( self . _wo... | Before 2 . 0 . 0 beta3 the node didn t have a folder by node when we start we move the file we can t do it in the topology conversion due to case of remote servers |
32,455 | def get_status ( self ) : status = yield from self . _hypervisor . send ( 'vm get_status "{name}"' . format ( name = self . _name ) ) if len ( status ) == 0 : raise DynamipsError ( "Can't get vm {name} status" . format ( name = self . _name ) ) return self . _status [ int ( status [ 0 ] ) ] | Returns the status of this router |
32,456 | def start ( self ) : status = yield from self . get_status ( ) if status == "suspended" : yield from self . resume ( ) elif status == "inactive" : if not os . path . isfile ( self . _image ) or not os . path . exists ( self . _image ) : if os . path . islink ( self . _image ) : raise DynamipsError ( 'IOS image "{}" lin... | Starts this router . At least the IOS image must be set before it can start . |
32,457 | def stop ( self ) : status = yield from self . get_status ( ) if status != "inactive" : try : yield from self . _hypervisor . send ( 'vm stop "{name}"' . format ( name = self . _name ) ) except DynamipsError as e : log . warn ( "Could not stop {}: {}" . format ( self . _name , e ) ) self . status = "stopped" log . info... | Stops this router . |
32,458 | def suspend ( self ) : status = yield from self . get_status ( ) if status == "running" : yield from self . _hypervisor . send ( 'vm suspend "{name}"' . format ( name = self . _name ) ) self . status = "suspended" log . info ( 'Router "{name}" [{id}] has been suspended' . format ( name = self . _name , id = self . _id ... | Suspends this router . |
32,459 | def set_image ( self , image ) : image = self . manager . get_abs_image_path ( image ) yield from self . _hypervisor . send ( 'vm set_ios "{name}" "{image}"' . format ( name = self . _name , image = image ) ) log . info ( 'Router "{name}" [{id}]: has a new IOS image set: "{image}"' . format ( name = self . _name , id =... | Sets the IOS image for this router . There is no default . |
32,460 | def set_ram ( self , ram ) : if self . _ram == ram : return yield from self . _hypervisor . send ( 'vm set_ram "{name}" {ram}' . format ( name = self . _name , ram = ram ) ) log . info ( 'Router "{name}" [{id}]: RAM updated from {old_ram}MB to {new_ram}MB' . format ( name = self . _name , id = self . _id , old_ram = se... | Sets amount of RAM allocated to this router |
32,461 | def set_nvram ( self , nvram ) : if self . _nvram == nvram : return yield from self . _hypervisor . send ( 'vm set_nvram "{name}" {nvram}' . format ( name = self . _name , nvram = nvram ) ) log . info ( 'Router "{name}" [{id}]: NVRAM updated from {old_nvram}KB to {new_nvram}KB' . format ( name = self . _name , id = sel... | Sets amount of NVRAM allocated to this router |
32,462 | def set_clock_divisor ( self , clock_divisor ) : yield from self . _hypervisor . send ( 'vm set_clock_divisor "{name}" {clock}' . format ( name = self . _name , clock = clock_divisor ) ) log . info ( 'Router "{name}" [{id}]: clock divisor updated from {old_clock} to {new_clock}' . format ( name = self . _name , id = se... | Sets the clock divisor value . The higher is the value the faster is the clock in the virtual machine . The default is 4 but it is often required to adjust it . |
32,463 | def get_idle_pc_prop ( self ) : is_running = yield from self . is_running ( ) was_auto_started = False if not is_running : yield from self . start ( ) was_auto_started = True yield from asyncio . sleep ( 20 ) log . info ( 'Router "{name}" [{id}] has started calculating Idle-PC values' . format ( name = self . _name , i... | Gets the idle PC proposals . Takes 1000 measurements and records up to 10 idle PC proposals . There is a 10ms wait between each measurement . |
32,464 | def set_idlemax ( self , idlemax ) : is_running = yield from self . is_running ( ) if is_running : yield from self . _hypervisor . send ( 'vm set_idle_max "{name}" 0 {idlemax}' . format ( name = self . _name , idlemax = idlemax ) ) log . info ( 'Router "{name}" [{id}]: idlemax updated from {old_idlemax} to {new_idlemax... | Sets CPU idle max value |
32,465 | def set_idlesleep ( self , idlesleep ) : is_running = yield from self . is_running ( ) if is_running : yield from self . _hypervisor . send ( 'vm set_idle_sleep_time "{name}" 0 {idlesleep}' . format ( name = self . _name , idlesleep = idlesleep ) ) log . info ( 'Router "{name}" [{id}]: idlesleep updated from {old_idles... | Sets CPU idle sleep time value . |
32,466 | def set_ghost_file ( self , ghost_file ) : yield from self . _hypervisor . send ( 'vm set_ghost_file "{name}" {ghost_file}' . format ( name = self . _name , ghost_file = shlex . quote ( ghost_file ) ) ) log . info ( 'Router "{name}" [{id}]: ghost file set to {ghost_file}' . format ( name = self . _name , id = self . _i... | Sets ghost RAM file |
32,467 | def formatted_ghost_file ( self ) : ghost_file = "{}-{}.ghost" . format ( os . path . basename ( self . _image ) , self . _ram ) ghost_file = ghost_file . replace ( '\\' , '-' ) . replace ( '/' , '-' ) . replace ( ':' , '-' ) return ghost_file | Returns a properly formatted ghost file name . |
32,468 | def set_ghost_status ( self , ghost_status ) : yield from self . _hypervisor . send ( 'vm set_ghost_status "{name}" {ghost_status}' . format ( name = self . _name , ghost_status = ghost_status ) ) log . info ( 'Router "{name}" [{id}]: ghost status set to {ghost_status}' . format ( name = self . _name , id = self . _id ... | Sets ghost RAM status |
32,469 | def set_console ( self , console ) : self . console = console yield from self . _hypervisor . send ( 'vm set_con_tcp_port "{name}" {console}' . format ( name = self . _name , console = self . console ) ) | Sets the TCP console port . |
32,470 | def set_aux ( self , aux ) : self . aux = aux yield from self . _hypervisor . send ( 'vm set_aux_tcp_port "{name}" {aux}' . format ( name = self . _name , aux = aux ) ) | Sets the TCP auxiliary port . |
32,471 | def get_cpu_usage ( self , cpu_id = 0 ) : cpu_usage = yield from self . _hypervisor . send ( 'vm cpu_usage "{name}" {cpu_id}' . format ( name = self . _name , cpu_id = cpu_id ) ) return int ( cpu_usage [ 0 ] ) | Shows cpu usage in seconds cpu_id is ignored . |
32,472 | def set_mac_addr ( self , mac_addr ) : yield from self . _hypervisor . send ( '{platform} set_mac_addr "{name}" {mac_addr}' . format ( platform = self . _platform , name = self . _name , mac_addr = mac_addr ) ) log . info ( 'Router "{name}" [{id}]: MAC address updated from {old_mac} to {new_mac}' . format ( name = self... | Sets the MAC address . |
32,473 | def set_system_id ( self , system_id ) : yield from self . _hypervisor . send ( '{platform} set_system_id "{name}" {system_id}' . format ( platform = self . _platform , name = self . _name , system_id = system_id ) ) log . info ( 'Router "{name}" [{id}]: system ID updated from {old_id} to {new_id}' . format ( name = se... | Sets the system ID . |
32,474 | def get_slot_bindings ( self ) : slot_bindings = yield from self . _hypervisor . send ( 'vm slot_bindings "{}"' . format ( self . _name ) ) return slot_bindings | Returns slot bindings . |
32,475 | def uninstall_wic ( self , wic_slot_number ) : slot_number = 0 adapter = self . _slots [ slot_number ] if wic_slot_number > len ( adapter . wics ) - 1 : raise DynamipsError ( "WIC slot {wic_slot_number} doesn't exist" . format ( wic_slot_number = wic_slot_number ) ) if adapter . wic_slot_available ( wic_slot_number ) :... | Uninstalls a WIC adapter from this router . |
32,476 | def get_slot_nio_bindings ( self , slot_number ) : nio_bindings = yield from self . _hypervisor . send ( 'vm slot_nio_bindings "{name}" {slot_number}' . format ( name = self . _name , slot_number = slot_number ) ) return nio_bindings | Returns slot NIO bindings . |
32,477 | def slot_add_nio_binding ( self , slot_number , port_number , nio ) : try : adapter = self . _slots [ slot_number ] except IndexError : raise DynamipsError ( 'Slot {slot_number} does not exist on router "{name}"' . format ( name = self . _name , slot_number = slot_number ) ) if adapter is None : raise DynamipsError ( "... | Adds a slot NIO binding . |
32,478 | def slot_remove_nio_binding ( self , slot_number , port_number ) : try : adapter = self . _slots [ slot_number ] except IndexError : raise DynamipsError ( 'Slot {slot_number} does not exist on router "{name}"' . format ( name = self . _name , slot_number = slot_number ) ) if adapter is None : raise DynamipsError ( "Ada... | Removes a slot NIO binding . |
32,479 | def slot_enable_nio ( self , slot_number , port_number ) : is_running = yield from self . is_running ( ) if is_running : yield from self . _hypervisor . send ( 'vm slot_enable_nio "{name}" {slot_number} {port_number}' . format ( name = self . _name , slot_number = slot_number , port_number = port_number ) ) log . info ... | Enables a slot NIO binding . |
32,480 | def set_name ( self , new_name ) : if os . path . isfile ( self . startup_config_path ) : try : with open ( self . startup_config_path , "r+" , encoding = "utf-8" , errors = "replace" ) as f : old_config = f . read ( ) new_config = re . sub ( r"^hostname .+$" , "hostname " + new_name , old_config , flags = re . MULTILI... | Renames this router . |
32,481 | def parse_version ( version ) : release_type_found = False version_infos = re . split ( '(\.|[a-z]+)' , version ) version = [ ] for info in version_infos : if info == '.' or len ( info ) == 0 : continue try : info = int ( info ) version . append ( "%06d" % ( info , ) ) except ValueError : if len ( version ) == 1 : vers... | Return a comparable tuple from a version string . We try to force tuple to semver with version like 1 . 2 . 0 |
32,482 | def _look_for_interface ( self , network_backend ) : result = yield from self . _execute ( "showvminfo" , [ self . _vmname , "--machinereadable" ] ) interface = - 1 for info in result . splitlines ( ) : if '=' in info : name , value = info . split ( '=' , 1 ) if name . startswith ( "nic" ) and value . strip ( '"' ) == ... | Look for an interface with a specific network backend . |
32,483 | def _look_for_vboxnet ( self , interface_number ) : result = yield from self . _execute ( "showvminfo" , [ self . _vmname , "--machinereadable" ] ) for info in result . splitlines ( ) : if '=' in info : name , value = info . split ( '=' , 1 ) if name == "hostonlyadapter{}" . format ( interface_number ) : return value .... | Look for the VirtualBox network name associated with a host only interface . |
32,484 | def _check_dhcp_server ( self , vboxnet ) : properties = yield from self . _execute ( "list" , [ "dhcpservers" ] ) flag_dhcp_server_found = False for prop in properties . splitlines ( ) : try : name , value = prop . split ( ':' , 1 ) except ValueError : continue if name . strip ( ) == "NetworkName" and value . strip ( ... | Check if the DHCP server associated with a vboxnet is enabled . |
32,485 | def _check_vbox_port_forwarding ( self ) : result = yield from self . _execute ( "showvminfo" , [ self . _vmname , "--machinereadable" ] ) for info in result . splitlines ( ) : if '=' in info : name , value = info . split ( '=' , 1 ) if name . startswith ( "Forwarding" ) and value . strip ( '"' ) . startswith ( "GNS3VM... | Checks if the NAT port forwarding rule exists . |
32,486 | def start ( self ) : nat_interface_number = yield from self . _look_for_interface ( "nat" ) if nat_interface_number < 0 : raise GNS3VMError ( "The GNS3 VM: {} must have a NAT interface configured in order to start" . format ( self . vmname ) ) hostonly_interface_number = yield from self . _look_for_interface ( "hostonl... | Start the GNS3 VM . |
32,487 | def _get_ip ( self , hostonly_interface_number , api_port ) : remaining_try = 300 while remaining_try > 0 : json_data = None session = aiohttp . ClientSession ( ) try : resp = None resp = yield from session . get ( 'http://127.0.0.1:{}/v2/compute/network/interfaces' . format ( api_port ) ) except ( OSError , aiohttp . ... | Get the IP from VirtualBox . |
32,488 | def stop ( self ) : vm_state = yield from self . _get_state ( ) if vm_state == "poweroff" : self . running = False return yield from self . _execute ( "controlvm" , [ self . _vmname , "acpipowerbutton" ] , timeout = 3 ) trial = 120 while True : try : vm_state = yield from self . _get_state ( ) except GNS3VMError : vm_s... | Stops the GNS3 VM . |
32,489 | def set_vcpus ( self , vcpus ) : yield from self . _execute ( "modifyvm" , [ self . _vmname , "--cpus" , str ( vcpus ) ] , timeout = 3 ) log . info ( "GNS3 VM vCPU count set to {}" . format ( vcpus ) ) | Set the number of vCPU cores for the GNS3 VM . |
32,490 | def set_ram ( self , ram ) : yield from self . _execute ( "modifyvm" , [ self . _vmname , "--memory" , str ( ram ) ] , timeout = 3 ) log . info ( "GNS3 VM RAM amount set to {}" . format ( ram ) ) | Set the RAM amount for the GNS3 VM . |
32,491 | def console_host ( self , new_host ) : server_config = Config . instance ( ) . get_section_config ( "Server" ) remote_console_connections = server_config . getboolean ( "allow_remote_console" ) if remote_console_connections : log . warning ( "Remote console connections are allowed" ) self . _console_host = "0.0.0.0" el... | If allow remote connection we need to bind console host to 0 . 0 . 0 . 0 |
32,492 | def find_unused_port ( start_port , end_port , host = "127.0.0.1" , socket_type = "TCP" , ignore_ports = None ) : if end_port < start_port : raise HTTPConflict ( text = "Invalid port range {}-{}" . format ( start_port , end_port ) ) last_exception = None for port in range ( start_port , end_port + 1 ) : if ignore_ports... | Finds an unused port in a range . |
32,493 | def _check_port ( host , port , socket_type ) : if socket_type == "UDP" : socket_type = socket . SOCK_DGRAM else : socket_type = socket . SOCK_STREAM for res in socket . getaddrinfo ( host , port , socket . AF_UNSPEC , socket_type , 0 , socket . AI_PASSIVE ) : af , socktype , proto , _ , sa = res with socket . socket (... | Check if an a port is available and raise an OSError if port is not available |
32,494 | def get_free_tcp_port ( self , project , port_range_start = None , port_range_end = None ) : if port_range_start is None and port_range_end is None : port_range_start = self . _console_port_range [ 0 ] port_range_end = self . _console_port_range [ 1 ] port = self . find_unused_port ( port_range_start , port_range_end ,... | Get an available TCP port and reserve it |
32,495 | def reserve_tcp_port ( self , port , project , port_range_start = None , port_range_end = None ) : if port_range_start is None and port_range_end is None : port_range_start = self . _console_port_range [ 0 ] port_range_end = self . _console_port_range [ 1 ] if port in self . _used_tcp_ports : old_port = port port = sel... | Reserve a specific TCP port number . If not available replace it by another . |
32,496 | def release_tcp_port ( self , port , project ) : if port in self . _used_tcp_ports : self . _used_tcp_ports . remove ( port ) project . remove_tcp_port ( port ) log . debug ( "TCP port {} has been released" . format ( port ) ) | Release a specific TCP port number |
32,497 | def get_free_udp_port ( self , project ) : port = self . find_unused_port ( self . _udp_port_range [ 0 ] , self . _udp_port_range [ 1 ] , host = self . _udp_host , socket_type = "UDP" , ignore_ports = self . _used_udp_ports ) self . _used_udp_ports . add ( port ) project . record_udp_port ( port ) log . debug ( "UDP po... | Get an available UDP port and reserve it |
32,498 | def reserve_udp_port ( self , port , project ) : if port in self . _used_udp_ports : raise HTTPConflict ( text = "UDP port {} already in use on host {}" . format ( port , self . _console_host ) ) if port < self . _udp_port_range [ 0 ] or port > self . _udp_port_range [ 1 ] : raise HTTPConflict ( text = "UDP port {} is ... | Reserve a specific UDP port number |
32,499 | def release_udp_port ( self , port , project ) : if port in self . _used_udp_ports : self . _used_udp_ports . remove ( port ) project . remove_udp_port ( port ) log . debug ( "UDP port {} has been released" . format ( port ) ) | Release a specific UDP port number |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.