idx
int64
0
63k
question
stringlengths
61
4.03k
target
stringlengths
6
1.23k
32,600
def _hash_file ( self , path ) : m = hashlib . md5 ( ) with open ( path , "rb" ) as f : while True : buf = f . read ( 128 ) if not buf : break m . update ( buf ) return m . hexdigest ( )
Compute and md5 hash for file
32,601
def mac ( self ) : res = 'Port Mac VLAN\n' result = ( yield from self . _node . _hypervisor . send ( 'ethsw show_mac_addr_table {}' . format ( self . _node . name ) ) ) for line in result : mac , vlan , nio = line . replace ( ' ' , ' ' ) . split ( ' ' ) mac = mac . replace ( '.' , '' ) mac = "{}:{...
Show MAC address table
32,602
def set_name ( self , new_name ) : yield from self . _hypervisor . send ( 'ethsw rename "{name}" "{new_name}"' . format ( name = self . _name , new_name = new_name ) ) log . info ( 'Ethernet switch "{name}" [{id}]: renamed to "{new_name}"' . format ( name = self . _name , id = self . _id , new_name = new_name ) ) self ...
Renames this Ethernet switch .
32,603
def close ( self ) : yield from self . _telnet . close ( ) self . _telnet_server . close ( ) for nio in self . _nios . values ( ) : if nio : yield from nio . close ( ) self . manager . port_manager . release_tcp_port ( self . _console , self . _project ) if self . _hypervisor : try : yield from self . _hypervisor . sen...
Deletes this Ethernet switch .
32,604
def add_nio ( self , nio , port_number ) : if port_number in self . _nios : raise DynamipsError ( "Port {} isn't free" . format ( port_number ) ) yield from self . _hypervisor . send ( 'ethsw add_nio "{name}" {nio}' . format ( name = self . _name , nio = nio ) ) log . info ( 'Ethernet switch "{name}" [{id}]: NIO {nio} ...
Adds a NIO as new port on Ethernet switch .
32,605
def remove_nio ( self , port_number ) : if port_number not in self . _nios : raise DynamipsError ( "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 ) if self . _hyper...
Removes the specified NIO as member of this Ethernet switch .
32,606
def set_port_settings ( self , port_number , settings ) : if settings [ "type" ] == "access" : yield from self . set_access_port ( port_number , settings [ "vlan" ] ) elif settings [ "type" ] == "dot1q" : yield from self . set_dot1q_port ( port_number , settings [ "vlan" ] ) elif settings [ "type" ] == "qinq" : yield f...
Applies port settings to a specific port .
32,607
def set_access_port ( self , port_number , vlan_id ) : if port_number not in self . _nios : raise DynamipsError ( "Port {} is not allocated" . format ( port_number ) ) nio = self . _nios [ port_number ] yield from self . _hypervisor . send ( 'ethsw set_access_port "{name}" {nio} {vlan_id}' . format ( name = self . _nam...
Sets the specified port as an ACCESS port .
32,608
def get_mac_addr_table ( self ) : mac_addr_table = yield from self . _hypervisor . send ( 'ethsw show_mac_addr_table "{}"' . format ( self . _name ) ) return mac_addr_table
Returns the MAC address table for this Ethernet switch .
32,609
def instance ( host = None , port = None ) : if not hasattr ( WebServer , "_instance" ) or WebServer . _instance is None : assert host is not None assert port is not None WebServer . _instance = WebServer ( host , port ) return WebServer . _instance
Singleton to return only one instance of Server .
32,610
def shutdown_server ( self ) : if not self . _closing : self . _closing = True else : log . warning ( "Close is already in progress" ) return if self . _server : self . _server . close ( ) yield from self . _server . wait_closed ( ) if self . _app : yield from self . _app . shutdown ( ) if self . _handler : try : yield...
Cleanly shutdown the server .
32,611
def _exit_handling ( self ) : def close_asyncio_loop ( ) : loop = None try : loop = asyncio . get_event_loop ( ) except AttributeError : pass if loop is not None : loop . close ( ) atexit . register ( close_asyncio_loop )
Makes sure the asyncio loop is closed .
32,612
def _on_startup ( self , * args ) : yield from Controller . instance ( ) . start ( ) asyncio . async ( Qemu . instance ( ) . list_images ( ) )
Called when the HTTP server start
32,613
def create ( self ) : super ( ) . create ( ) log . info ( 'Ethernet hub "{name}" [{id}] has been created' . format ( name = self . _name , id = self . _id ) )
Creates this hub .
32,614
def list_vms ( self , allow_clone = False ) : vbox_vms = [ ] result = yield from self . execute ( "list" , [ "vms" ] ) for line in result : if len ( line ) == 0 or line [ 0 ] != '"' or line [ - 1 : ] != "}" : continue vmname , _ = line . rsplit ( ' ' , 1 ) vmname = vmname . strip ( '"' ) if vmname == "<inaccessible>" :...
Gets VirtualBox VM list .
32,615
def set_npe ( self , npe ) : if ( yield from self . is_running ( ) ) : raise DynamipsError ( "Cannot change NPE on running router" ) yield from self . _hypervisor . send ( 'c7200 set_npe "{name}" {npe}' . format ( name = self . _name , npe = npe ) ) log . info ( 'Router "{name}" [{id}]: NPE updated from {old_npe} to {n...
Sets the NPE model .
32,616
def set_midplane ( self , midplane ) : yield from self . _hypervisor . send ( 'c7200 set_midplane "{name}" {midplane}' . format ( name = self . _name , midplane = midplane ) ) log . info ( 'Router "{name}" [{id}]: midplane updated from {old_midplane} to {new_midplane}' . format ( name = self . _name , id = self . _id ,...
Sets the midplane model .
32,617
def set_sensors ( self , sensors ) : sensor_id = 0 for sensor in sensors : yield from self . _hypervisor . send ( 'c7200 set_temp_sensor "{name}" {sensor_id} {temp}' . format ( name = self . _name , sensor_id = sensor_id , temp = sensor ) ) log . info ( 'Router "{name}" [{id}]: sensor {sensor_id} temperature updated fr...
Sets the 4 sensors with temperature in degree Celcius .
32,618
def set_power_supplies ( self , power_supplies ) : power_supply_id = 0 for power_supply in power_supplies : yield from self . _hypervisor . send ( 'c7200 set_power_supply "{name}" {power_supply_id} {powered_on}' . format ( name = self . _name , power_supply_id = power_supply_id , powered_on = power_supply ) ) log . inf...
Sets the 2 power supplies with 0 = off 1 = on .
32,619
def start ( self ) : yield from Router . start ( self ) if self . _sensors != [ 22 , 22 , 22 , 22 ] : yield from self . set_sensors ( self . _sensors ) if self . _power_supplies != [ 1 , 1 ] : yield from self . set_power_supplies ( self . _power_supplies )
Starts this router . At least the IOS image must be set before starting it .
32,620
def export_project ( project , temporary_dir , include_images = False , keep_compute_id = False , allow_all_nodes = False , ignore_prefixes = None ) : if project . is_running ( ) : raise aiohttp . web . HTTPConflict ( text = "Running topology could not be exported" ) project . dump ( ) z = zipstream . ZipFile ( allowZi...
Export the project as zip . It s a ZipStream object . The file will be read chunk by chunk when you iterate on the zip .
32,621
def dispatch ( self , action , event , compute_id ) : if action == "node.updated" : try : project = self . _controller . get_project ( event [ "project_id" ] ) node = project . get_node ( event [ "node_id" ] ) yield from node . parse_node_response ( event ) self . emit ( "node.updated" , node . __json__ ( ) ) except ( ...
Notification received from compute node . Send it directly to clients or process it
32,622
def emit ( self , action , event ) : if os . environ . get ( "PYTEST_BUILD_DOCUMENTATION" ) == "1" : os . makedirs ( "docs/api/notifications" , exist_ok = True ) try : import json data = json . dumps ( event , indent = 4 , sort_keys = True ) if "MagicMock" not in data : with open ( os . path . join ( "docs/api/notifica...
Send a notification to clients scoped by projects
32,623
def _send_event_to_project ( self , project_id , action , event ) : try : project_listeners = self . _listeners [ project_id ] except KeyError : return for listener in project_listeners : listener . put_nowait ( ( action , event , { } ) )
Send an event to all the client listening for notifications for this project
32,624
def _send_event_to_all ( self , action , event ) : for project_listeners in self . _listeners . values ( ) : for listener in project_listeners : listener . put_nowait ( ( action , event , { } ) )
Send an event to all the client listening for notifications on all projects
32,625
def _update_config ( self ) : if self . _local_server : server_config = Config . instance ( ) . get_section_config ( "Server" ) self . _local_server . user = server_config . get ( "user" ) self . _local_server . password = server_config . get ( "password" )
Call this when the server configuration file change
32,626
def save ( self ) : if self . _settings is None : return data = { "computes" : [ ] , "settings" : self . _settings , "gns3vm" : self . gns3vm . __json__ ( ) , "version" : __version__ } for c in self . _computes . values ( ) : if c . id != "local" and c . id != "vm" : data [ "computes" ] . append ( { "host" : c . host ,...
Save the controller configuration on disk
32,627
def _load_controller_settings ( self ) : try : if not os . path . exists ( self . _config_file ) : yield from self . _import_gns3_gui_conf ( ) self . save ( ) with open ( self . _config_file ) as f : data = json . load ( f ) except ( OSError , ValueError ) as e : log . critical ( "Cannot load %s: %s" , self . _config_f...
Reload the controller configuration from disk
32,628
def load_projects ( self ) : server_config = Config . instance ( ) . get_section_config ( "Server" ) projects_path = os . path . expanduser ( server_config . get ( "projects_path" , "~/GNS3/projects" ) ) os . makedirs ( projects_path , exist_ok = True ) try : for project_path in os . listdir ( projects_path ) : project...
Preload the list of projects from disk
32,629
def load_base_files ( self ) : dst_path = self . configs_path ( ) src_path = get_resource ( 'configs' ) try : for file in os . listdir ( src_path ) : if not os . path . exists ( os . path . join ( dst_path , file ) ) : shutil . copy ( os . path . join ( src_path , file ) , os . path . join ( dst_path , file ) ) except ...
At startup we copy base file to the user location to allow them to customize it
32,630
def _import_gns3_gui_conf ( self ) : config_file = os . path . join ( os . path . dirname ( self . _config_file ) , "gns3_gui.conf" ) if os . path . exists ( config_file ) : with open ( config_file ) as f : data = json . load ( f ) server_settings = data . get ( "Servers" , { } ) for remote in server_settings . get ( "...
Import old config from GNS3 GUI
32,631
def add_compute ( self , compute_id = None , name = None , force = False , connect = True , ** kwargs ) : if compute_id not in self . _computes : if ( compute_id == 'local' or compute_id == 'vm' ) and not force : return None if name == 'gns3vm' : return None for compute in self . _computes . values ( ) : if name and co...
Add a server to the dictionary of compute servers controlled by this controller
32,632
def close_compute_projects ( self , compute ) : for project in self . _projects . values ( ) : if compute in project . computes : yield from project . close ( )
Close projects running on a compute
32,633
def delete_compute ( self , compute_id ) : try : compute = self . get_compute ( compute_id ) except aiohttp . web . HTTPNotFound : return yield from self . close_compute_projects ( compute ) yield from compute . close ( ) del self . _computes [ compute_id ] self . save ( ) self . notification . emit ( "compute.deleted"...
Delete a compute node . Project using this compute will be close
32,634
def get_compute ( self , compute_id ) : try : return self . _computes [ compute_id ] except KeyError : if compute_id == "vm" : raise aiohttp . web . HTTPNotFound ( text = "You try to use a node on the GNS3 VM server but the GNS3 VM is not configured" ) raise aiohttp . web . HTTPNotFound ( text = "Compute ID {} doesn't ...
Returns a compute server or raise a 404 error .
32,635
def add_project ( self , project_id = None , name = None , ** kwargs ) : if project_id not in self . _projects : for project in self . _projects . values ( ) : if name and project . name == name : raise aiohttp . web . HTTPConflict ( text = 'Project name "{}" already exists' . format ( name ) ) project = Project ( proj...
Creates a project or returns an existing project
32,636
def load_project ( self , path , load = True ) : topo_data = load_topology ( path ) topo_data . pop ( "topology" ) topo_data . pop ( "version" ) topo_data . pop ( "revision" ) topo_data . pop ( "type" ) if topo_data [ "project_id" ] in self . _projects : project = self . _projects [ topo_data [ "project_id" ] ] else : ...
Load a project from a . gns3
32,637
def _project_auto_open ( self ) : for project in self . _projects . values ( ) : if project . auto_open : yield from project . open ( )
Auto open the project with auto open enable
32,638
def get_free_project_name ( self , base_name ) : names = [ p . name for p in self . _projects . values ( ) ] if base_name not in names : return base_name i = 1 projects_path = self . projects_directory ( ) while True : new_name = "{}-{}" . format ( base_name , i ) if new_name not in names and not os . path . exists ( o...
Generate a free project name base on the base name
32,639
def instance ( ) : if not hasattr ( Controller , '_instance' ) or Controller . _instance is None : Controller . _instance = Controller ( ) return Controller . _instance
Singleton to return only on instance of Controller .
32,640
def autoidlepc ( self , compute_id , platform , image , ram ) : compute = self . get_compute ( compute_id ) for project in list ( self . _projects . values ( ) ) : if project . name == "AUTOIDLEPC" : yield from project . delete ( ) self . remove_project ( project ) project = yield from self . add_project ( name = "AUTO...
Compute and IDLE PC value for an image
32,641
def _control_vm ( self , params ) : args = shlex . split ( params ) result = yield from self . manager . execute ( "controlvm" , [ self . _vmname ] + args ) return result
Change setting in this VM when running .
32,642
def _patch_vm_uuid ( self ) : if os . path . exists ( self . _linked_vbox_file ( ) ) : try : tree = ET . parse ( self . _linked_vbox_file ( ) ) except ET . ParseError : raise VirtualBoxError ( "Cannot modify VirtualBox linked nodes file. " "File {} is corrupted." . format ( self . _linked_vbox_file ( ) ) ) machine = tr...
Fix the VM uuid in the case of linked clone
32,643
def start ( self ) : if self . status == "started" : return vm_state = yield from self . _get_vm_state ( ) if vm_state == "paused" : yield from self . resume ( ) return if vm_state != "poweroff" : raise VirtualBoxError ( "VirtualBox VM not powered off" ) yield from self . _set_network_options ( ) yield from self . _set...
Starts this VirtualBox VM .
32,644
def stop ( self ) : self . _hw_virtualization = False yield from self . _stop_ubridge ( ) yield from self . _stop_remote_console ( ) vm_state = yield from self . _get_vm_state ( ) if vm_state == "running" or vm_state == "paused" or vm_state == "stuck" : if self . acpi_shutdown : result = yield from self . _control_vm (...
Stops this VirtualBox VM .
32,645
def suspend ( self ) : vm_state = yield from self . _get_vm_state ( ) if vm_state == "running" : yield from self . _control_vm ( "pause" ) self . status = "suspended" log . info ( "VirtualBox VM '{name}' [{id}] suspended" . format ( name = self . name , id = self . id ) ) else : log . warn ( "VirtualBox VM '{name}' [{i...
Suspends this VirtualBox VM .
32,646
def resume ( self ) : yield from self . _control_vm ( "resume" ) self . status = "started" log . info ( "VirtualBox VM '{name}' [{id}] resumed" . format ( name = self . name , id = self . id ) )
Resumes this VirtualBox VM .
32,647
def reload ( self ) : result = yield from self . _control_vm ( "reset" ) log . info ( "VirtualBox VM '{name}' [{id}] reloaded" . format ( name = self . name , id = self . id ) ) log . debug ( "Reload result: {}" . format ( result ) )
Reloads this VirtualBox VM .
32,648
def _reattach_linked_hdds ( self ) : hdd_info_file = os . path . join ( self . working_dir , self . _vmname , "hdd_info.json" ) try : with open ( hdd_info_file , "r" , encoding = "utf-8" ) as f : hdd_table = json . load ( f ) except ( ValueError , OSError ) as e : return for hdd_info in hdd_table : hdd_file = os . path...
Reattach linked cloned hard disks .
32,649
def save_linked_hdds_info ( self ) : hdd_table = [ ] if self . linked_clone : if os . path . exists ( self . working_dir ) : hdd_files = yield from self . _get_all_hdd_files ( ) vm_info = yield from self . _get_vm_info ( ) for entry , value in vm_info . items ( ) : match = re . search ( "^([\s\w]+)\-(\d)\-(\d)$" , entr...
Save linked cloned hard disks information .
32,650
def close ( self ) : if self . _closed : return if not ( yield from super ( ) . close ( ) ) : return False log . debug ( "VirtualBox VM '{name}' [{id}] is closing" . format ( name = self . name , id = self . id ) ) if self . _console : self . _manager . port_manager . release_tcp_port ( self . _console , self . _projec...
Closes this VirtualBox VM .
32,651
def set_ram ( self , ram ) : if ram == 0 : return yield from self . _modify_vm ( '--memory {}' . format ( ram ) ) log . info ( "VirtualBox VM '{name}' [{id}] has set amount of RAM to {ram}" . format ( name = self . name , id = self . id , ram = ram ) ) self . _ram = ram
Set the amount of RAM allocated to this VirtualBox VM .
32,652
def set_vmname ( self , vmname ) : if vmname == self . _vmname : return if self . linked_clone : if self . status == "started" : raise VirtualBoxError ( "You can't change the name of running VM {}" . format ( self . _name ) ) vms = yield from self . manager . list_vms ( allow_clone = True ) if vmname in [ vm [ "vmname"...
Renames the VirtualBox VM .
32,653
def set_adapters ( self , adapters ) : vm_info = yield from self . _get_vm_info ( ) chipset = "piix3" self . _maximum_adapters = 8 if "chipset" in vm_info : chipset = vm_info [ "chipset" ] max_adapter_string = "Maximum {} Network Adapter count" . format ( chipset . upper ( ) ) if max_adapter_string in self . _system_pr...
Sets the number of Ethernet adapters for this VirtualBox VM instance .
32,654
def _get_vm_info ( self ) : vm_info = { } results = yield from self . manager . execute ( "showvminfo" , [ self . _vmname , "--machinereadable" ] ) for info in results : try : name , value = info . split ( '=' , 1 ) except ValueError : continue vm_info [ name . strip ( '"' ) ] = value . strip ( '"' ) return vm_info
Returns this VM info .
32,655
def _storage_attach ( self , params ) : args = shlex . split ( params ) yield from self . manager . execute ( "storageattach" , [ self . _vmname ] + args )
Change storage medium in this VM .
32,656
def _get_nic_attachements ( self , maximum_adapters ) : nics = [ ] vm_info = yield from self . _get_vm_info ( ) for adapter_number in range ( 0 , maximum_adapters ) : entry = "nic{}" . format ( adapter_number + 1 ) if entry in vm_info : value = vm_info [ entry ] nics . append ( value . lower ( ) ) else : nics . append ...
Returns NIC attachements .
32,657
def _create_linked_clone ( self ) : gns3_snapshot_exists = False vm_info = yield from self . _get_vm_info ( ) for entry , value in vm_info . items ( ) : if entry . startswith ( "SnapshotName" ) and value == "GNS3 Linked Base for clones" : gns3_snapshot_exists = True if not gns3_snapshot_exists : result = yield from sel...
Creates a new linked clone .
32,658
def _check_ubridge_version ( self , env = None ) : try : output = yield from subprocess_check_output ( self . _path , "-v" , cwd = self . _working_dir , env = env ) match = re . search ( "ubridge version ([0-9a-z\.]+)" , output ) if match : self . _version = match . group ( 1 ) if sys . platform . startswith ( "win" ) ...
Checks if the ubridge executable version
32,659
def start ( self ) : env = os . environ . copy ( ) if sys . platform . startswith ( "win" ) : system_root = os . path . join ( os . path . expandvars ( "%SystemRoot%" ) , "System32" , "Npcap" ) if os . path . isdir ( system_root ) : env [ "PATH" ] = system_root + ';' + env [ "PATH" ] yield from self . _check_ubridge_ve...
Starts the uBridge hypervisor process .
32,660
def find_vmrun ( self ) : vmrun_path = self . config . get_section_config ( "VMware" ) . get ( "vmrun_path" ) if not vmrun_path : if sys . platform . startswith ( "win" ) : vmrun_path = shutil . which ( "vmrun" ) if vmrun_path is None : vmrun_path = self . _find_vmrun_registry ( r"SOFTWARE\Wow6432Node\VMware, Inc.\VMwa...
Searches for vmrun .
32,661
def _check_vmware_player_requirements ( self , player_version ) : player_version = int ( player_version ) if player_version < 6 : raise VMwareError ( "Using VMware Player requires version 6 or above" ) elif player_version == 6 : yield from self . check_vmrun_version ( minimum_required_version = "1.13.0" ) elif player_v...
Check minimum requirements to use VMware Player .
32,662
def _check_vmware_workstation_requirements ( self , ws_version ) : ws_version = int ( ws_version ) if ws_version < 10 : raise VMwareError ( "Using VMware Workstation requires version 10 or above" ) elif ws_version == 10 : yield from self . check_vmrun_version ( minimum_required_version = "1.13.0" ) elif ws_version == 1...
Check minimum requirements to use VMware Workstation .
32,663
def check_vmware_version ( self ) : if sys . platform . startswith ( "win" ) : ws_version = self . _find_vmware_version_registry ( r"SOFTWARE\Wow6432Node\VMware, Inc.\VMware Workstation" ) if ws_version is None : player_version = self . _find_vmware_version_registry ( r"SOFTWARE\Wow6432Node\VMware, Inc.\VMware Player" ...
Check VMware version
32,664
def check_vmrun_version ( self , minimum_required_version = "1.13.0" ) : vmrun_path = self . vmrun_path if not vmrun_path : vmrun_path = self . find_vmrun ( ) try : output = yield from subprocess_check_output ( vmrun_path ) match = re . search ( "vmrun version ([0-9\.]+)" , output ) version = None if match : version = ...
Checks the vmrun version .
32,665
def remove_from_vmware_inventory ( self , vmx_path ) : with ( yield from self . _vmware_inventory_lock ) : inventory_path = self . get_vmware_inventory_path ( ) if os . path . exists ( inventory_path ) : try : inventory_pairs = self . parse_vmware_file ( inventory_path ) except OSError as e : log . warning ( 'Could not...
Removes a linked clone from the VMware inventory file .
32,666
def write_vmx_file ( path , pairs ) : encoding = "utf-8" if ".encoding" in pairs : file_encoding = pairs [ ".encoding" ] try : codecs . lookup ( file_encoding ) encoding = file_encoding except LookupError : log . warning ( "Invalid file encoding detected in '{}': {}" . format ( path , file_encoding ) ) with open ( path...
Write a VMware VMX file .
32,667
def _get_vms_from_inventory ( self , inventory_path ) : vm_entries = { } vmware_vms = [ ] log . info ( 'Searching for VMware VMs in inventory file "{}"' . format ( inventory_path ) ) try : pairs = self . parse_vmware_file ( inventory_path ) for key , value in pairs . items ( ) : if key . startswith ( "vmlist" ) : try :...
Searches for VMs by parsing a VMware inventory file .
32,668
def _get_vms_from_directory ( self , directory ) : vmware_vms = [ ] log . info ( 'Searching for VMware VMs in directory "{}"' . format ( directory ) ) for path , _ , filenames in os . walk ( directory ) : for filename in filenames : if os . path . splitext ( filename ) [ 1 ] == ".vmx" : vmx_path = os . path . join ( pa...
Searches for VMs in a given directory .
32,669
def get_vmware_inventory_path ( ) : if sys . platform . startswith ( "win" ) : return os . path . expandvars ( r"%APPDATA%\Vmware\Inventory.vmls" ) elif sys . platform . startswith ( "darwin" ) : return os . path . expanduser ( "~/Library/Application Support/VMware Fusion/vmInventory" ) else : return os . path . expand...
Returns VMware inventory file path .
32,670
def get_vmware_preferences_path ( ) : if sys . platform . startswith ( "win" ) : return os . path . expandvars ( r"%APPDATA%\VMware\preferences.ini" ) elif sys . platform . startswith ( "darwin" ) : return os . path . expanduser ( "~/Library/Preferences/VMware Fusion/preferences" ) else : return os . path . expanduser ...
Returns VMware preferences file path .
32,671
def get_vmware_default_vm_paths ( ) : if sys . platform . startswith ( "win" ) : import ctypes import ctypes . wintypes path = ctypes . create_unicode_buffer ( ctypes . wintypes . MAX_PATH ) ctypes . windll . shell32 . SHGetFolderPathW ( None , 5 , None , 0 , path ) documents_folder = path . value return [ '{}\My Virtu...
Returns VMware default VM directory paths .
32,672
def list_vms ( self ) : yield from self . check_vmware_version ( ) vmware_vms = [ ] inventory_path = self . get_vmware_inventory_path ( ) if os . path . exists ( inventory_path ) and self . host_type != "player" : vmware_vms = self . _get_vms_from_inventory ( inventory_path ) if not vmware_vms : vmware_preferences_path...
Gets VMware VM list .
32,673
def remove_nio ( self , port_number ) : if port_number not in self . _nios : raise DynamipsError ( "Port {} is not allocated" . format ( port_number ) ) for source , destination in self . _active_mappings . copy ( ) . items ( ) : if len ( source ) == 3 and len ( destination ) == 3 : source_port , source_vpi , source_vc...
Removes the specified NIO as member of this ATM switch .
32,674
def map_vp ( self , port1 , vpi1 , port2 , vpi2 ) : if port1 not in self . _nios : return if port2 not in self . _nios : return nio1 = self . _nios [ port1 ] nio2 = self . _nios [ port2 ] yield from self . _hypervisor . send ( 'atmsw create_vpc "{name}" {input_nio} {input_vpi} {output_nio} {output_vpi}' . format ( name...
Creates a new Virtual Path connection .
32,675
def file ( self , path , status = 200 , set_content_length = True ) : ct , encoding = mimetypes . guess_type ( path ) if not ct : ct = 'application/octet-stream' if encoding : self . headers [ aiohttp . hdrs . CONTENT_ENCODING ] = encoding self . content_type = ct if set_content_length : st = os . stat ( path ) self . ...
Return a file as a response
32,676
def restore ( self ) : yield from self . _project . delete_on_computes ( ) yield from self . _project . close ( ignore_notification = True ) self . _project . controller . notification . emit ( "snapshot.restored" , self . __json__ ( ) ) try : if os . path . exists ( os . path . join ( self . _project . path , "project...
Restore the snapshot
32,677
def get_resource ( resource_name ) : resource_path = None if hasattr ( sys , "frozen" ) : resource_path = os . path . normpath ( os . path . join ( os . path . dirname ( sys . executable ) , resource_name ) ) elif not hasattr ( sys , "frozen" ) and pkg_resources . resource_exists ( "gns3server" , resource_name ) : reso...
Return a resource in current directory or in frozen package
32,678
def _nvram_changed ( self , path ) : log . debug ( "NVRAM changed: {}" . format ( path ) ) self . save_configs ( ) self . updated ( )
Called when the NVRAM file has changed
32,679
def close ( self ) : if not ( yield from super ( ) . close ( ) ) : return False adapters = self . _ethernet_adapters + self . _serial_adapters for adapter in adapters : if adapter is not None : for nio in adapter . ports . values ( ) : if nio and isinstance ( nio , NIOUDP ) : self . manager . port_manager . release_udp...
Closes this IOU VM .
32,680
def path ( self , path ) : self . _path = self . manager . get_abs_image_path ( path ) log . info ( 'IOU "{name}" [{id}]: IOU image updated to "{path}"' . format ( name = self . _name , id = self . _id , path = self . _path ) )
Path of the IOU executable .
32,681
def use_default_iou_values ( self , state ) : self . _use_default_iou_values = state if state : log . info ( 'IOU "{name}" [{id}]: uses the default IOU image values' . format ( name = self . _name , id = self . _id ) ) else : log . info ( 'IOU "{name}" [{id}]: does not use the default IOU image values' . format ( name ...
Sets if this device uses the default IOU image values .
32,682
def update_default_iou_values ( self ) : try : output = yield from gns3server . utils . asyncio . subprocess_check_output ( self . _path , "-h" , cwd = self . working_dir , stderr = True ) match = re . search ( "-n <n>\s+Size of nvram in Kb \(default ([0-9]+)KB\)" , output ) if match : self . nvram = int ( match . grou...
Finds the default RAM and NVRAM values for the IOU image .
32,683
def _check_requirements ( self ) : if not self . _path : raise IOUError ( "IOU image is not configured" ) if not os . path . isfile ( self . _path ) or not os . path . exists ( self . _path ) : if os . path . islink ( self . _path ) : raise IOUError ( "IOU image '{}' linked to '{}' is not accessible" . format ( self . ...
Checks the IOU image .
32,684
def iourc_path ( self ) : iourc_path = self . _config ( ) . get ( "iourc_path" ) if not iourc_path : path = os . path . join ( self . temporary_directory , "iourc" ) if os . path . exists ( path ) : return path path = os . path . join ( os . path . expanduser ( "~/" ) , ".iourc" ) if os . path . exists ( path ) : retur...
Returns the IOURC file path .
32,685
def name ( self , new_name ) : if self . startup_config_file : content = self . startup_config_content content = re . sub ( r"^hostname .+$" , "hostname " + new_name , content , flags = re . MULTILINE ) self . startup_config_content = content super ( IOUVM , IOUVM ) . name . __set__ ( self , new_name )
Sets the name of this IOU VM .
32,686
def _library_check ( self ) : try : output = yield from gns3server . utils . asyncio . subprocess_check_output ( "ldd" , self . _path ) except ( FileNotFoundError , subprocess . SubprocessError ) as e : log . warn ( "Could not determine the shared library dependencies for {}: {}" . format ( self . _path , e ) ) return ...
Checks for missing shared library dependencies in the IOU image .
32,687
def _nvram_file ( self ) : return os . path . join ( self . working_dir , "nvram_{:05d}" . format ( self . application_id ) )
Path to the nvram file
32,688
def _push_configs_to_nvram ( self ) : startup_config_content = self . startup_config_content if startup_config_content : nvram_file = self . _nvram_file ( ) try : if not os . path . exists ( nvram_file ) : open ( nvram_file , "a" ) . close ( ) nvram_content = None else : with open ( nvram_file , "rb" ) as file : nvram_...
Push the startup - config and private - config content to the NVRAM .
32,689
def start ( self ) : self . _check_requirements ( ) if not self . is_running ( ) : yield from self . _library_check ( ) try : self . _rename_nvram_file ( ) except OSError as e : raise IOUError ( "Could not rename nvram files: {}" . format ( e ) ) iourc_path = self . iourc_path if not iourc_path : raise IOUError ( "Coul...
Starts the IOU process .
32,690
def _networking ( self ) : bridge_name = "IOL-BRIDGE-{}" . format ( self . application_id + 512 ) try : yield from self . _ubridge_send ( "iol_bridge delete {name}" . format ( name = bridge_name ) ) except UbridgeError : pass yield from self . _ubridge_send ( "iol_bridge create {name} {bridge_id}" . format ( name = bri...
Configures the IOL bridge in uBridge .
32,691
def _rename_nvram_file ( self ) : destination = self . _nvram_file ( ) for file_path in glob . glob ( os . path . join ( glob . escape ( self . working_dir ) , "nvram_*" ) ) : shutil . move ( file_path , destination ) destination = os . path . join ( self . working_dir , "vlan.dat-{:05d}" . format ( self . application_...
Before starting the VM rename the nvram and vlan . dat files with the correct IOU application identifier .
32,692
def stop ( self ) : yield from self . _stop_ubridge ( ) if self . _nvram_watcher : self . _nvram_watcher . close ( ) self . _nvram_watcher = None if self . _telnet_server : self . _telnet_server . close ( ) self . _telnet_server = None if self . is_running ( ) : self . _terminate_process_iou ( ) if self . _iou_process ...
Stops the IOU process .
32,693
def _terminate_process_iou ( self ) : if self . _iou_process : log . info ( 'Stopping IOU process for IOU VM "{}" PID={}' . format ( self . name , self . _iou_process . pid ) ) try : self . _iou_process . terminate ( ) except ProcessLookupError : pass self . _started = False self . status = "stopped"
Terminate the IOU process if running
32,694
def _create_netmap_config ( self ) : netmap_path = os . path . join ( self . working_dir , "NETMAP" ) try : with open ( netmap_path , "w" , encoding = "utf-8" ) as f : for bay in range ( 0 , 16 ) : for unit in range ( 0 , 4 ) : f . write ( "{ubridge_id}:{bay}/{unit}{iou_id:>5d}:{bay}/{unit}\n" . format ( ubridge_id = s...
Creates the NETMAP file .
32,695
def read_iou_stdout ( self ) : output = "" if self . _iou_stdout_file : try : with open ( self . _iou_stdout_file , "rb" ) as file : output = file . read ( ) . decode ( "utf-8" , errors = "replace" ) except OSError as e : log . warn ( "could not read {}: {}" . format ( self . _iou_stdout_file , e ) ) return output
Reads the standard output of the IOU process . Only use when the process has been stopped or has crashed .
32,696
def ethernet_adapters ( self , ethernet_adapters ) : self . _ethernet_adapters . clear ( ) for _ in range ( 0 , ethernet_adapters ) : self . _ethernet_adapters . append ( EthernetAdapter ( interfaces = 4 ) ) log . info ( 'IOU "{name}" [{id}]: number of Ethernet adapters changed to {adapters}' . format ( name = self . _...
Sets the number of Ethernet adapters for this IOU VM .
32,697
def serial_adapters ( self , serial_adapters ) : self . _serial_adapters . clear ( ) for _ in range ( 0 , serial_adapters ) : self . _serial_adapters . append ( SerialAdapter ( interfaces = 4 ) ) log . info ( 'IOU "{name}" [{id}]: number of Serial adapters changed to {adapters}' . format ( name = self . _name , id = se...
Sets the number of Serial adapters for this IOU VM .
32,698
def adapter_add_nio_binding ( self , adapter_number , port_number , nio ) : try : adapter = self . _adapters [ adapter_number ] except IndexError : raise IOUError ( 'Adapter {adapter_number} does not exist for IOU "{name}"' . format ( name = self . _name , adapter_number = adapter_number ) ) if not adapter . port_exist...
Adds a adapter NIO binding .
32,699
def _ubridge_apply_filters ( self , adapter_number , port_number , filters ) : bridge_name = "IOL-BRIDGE-{}" . format ( self . application_id + 512 ) location = '{bridge_name} {bay} {unit}' . format ( bridge_name = bridge_name , bay = adapter_number , unit = port_number ) yield from self . _ubridge_send ( 'iol_bridge r...
Apply filter like rate limiting