def select_vmx_version(self, obj): """ Select a VMX version for the Virtual Machine Args: obj (vim.ComputeResource): Entity to query for supported versions """ self.dialog.infobox( text='Retrieving information ...' ) versions = obj.environmentBrowser.QueryConfigOptionDescriptor() items = [ pvc.widget.radiolist.RadioListItem( tag=v.key, description=v.description ) for v in versions if v.createSupported ] radiolist = pvc.widget.radiolist.RadioList( items=items, dialog=self.dialog, title='Create New Virtual Machine', text='Select Virtual Machine hardware version' ) code, tag = radiolist.display() if code in (self.dialog.CANCEL, self.dialog.ESC) or not tag: return return tag
def choose_host(agent, dialog, folder=None): """ Prompts the user to choose a host Args: agent (VConnector): A VConnector instance dialog (dialog.Dailog): A Dialog instance folder (vim.Folder): A vim.Folder entity Returns: A vim.HostSystem managed entity if the user chose a host. Returns None if no host has been selected or there are no hosts existing """ dialog.infobox( text='Retrieving information ...' ) if not folder: folder = agent.si.content.rootFolder view = agent.get_container_view( obj_type=[pyVmomi.vim.HostSystem], container=folder ) properties = agent.collect_properties( view_ref=view, obj_type=pyVmomi.vim.HostSystem, path_set=['name', 'runtime.connectionState'], include_mors=True ) view.DestroyView() if not properties: return items = [ pvc.widget.radiolist.RadioListItem( tag=host['name'], description=host['runtime.connectionState'], ) for host in properties ] radiolist = pvc.widget.radiolist.RadioList( items=items, dialog=dialog, title='Choose Host', text='Choose a host from the list below' ) code, tag = radiolist.display() if code in (dialog.CANCEL, dialog.ESC) or not tag: return return [h['obj'] for h in properties if h['name'] == tag].pop()
def choose_network(agent, dialog, obj): """ Prompts the user to choose a network Args: agent (VConnector): A VConnector instance dialog (dialog.Dailog): A Dialog instance obj (vim.ManagedEntity): A Managed Entity Returns: A vim.Network managed entity if a network has been chosen Return None if no network has been selected or there are no networks existing """ title = '{} ({})'.format(obj.name, obj.__class__.__name__) dialog.infobox( title=title, text='Retrieving information ...' ) if not hasattr(obj, 'network'): return view = agent.get_list_view(obj.network) properties = agent.collect_properties( view_ref=view, obj_type=pyVmomi.vim.Network, path_set=['name', 'summary.accessible'], include_mors=True ) view.DestroyView() if not properties: return items = [ pvc.widget.radiolist.RadioListItem( tag=network['name'], description='Accessible' if network['summary.accessible'] else 'Not Accessible', ) for network in properties ] radiolist = pvc.widget.radiolist.RadioList( items=items, dialog=dialog, title='Choose Network', text='Choose a network from the list below' ) code, tag = radiolist.display() if code in (dialog.CANCEL, dialog.ESC) or not tag: return return [network['obj'] for network in properties if network['name'] == tag].pop()
def choose_network(agent, dialog, obj): """ Prompts the user to choose a network Args: agent (VConnector): A VConnector instance dialog (dialog.Dailog): A Dialog instance obj (vim.ManagedEntity): A Managed Entity Returns: A vim.Network managed entity if a network has been chosen Return None if no network has been selected or there are no networks existing """ title = '{} ({})'.format(obj.name, obj.__class__.__name__) dialog.infobox(title=title, text='Retrieving information ...') if not hasattr(obj, 'network'): return view = agent.get_list_view(obj.network) properties = agent.collect_properties( view_ref=view, obj_type=pyVmomi.vim.Network, path_set=['name', 'summary.accessible'], include_mors=True) view.DestroyView() if not properties: return items = [ pvc.widget.radiolist.RadioListItem( tag=network['name'], description='Accessible' if network['summary.accessible'] else 'Not Accessible', ) for network in properties ] radiolist = pvc.widget.radiolist.RadioList( items=items, dialog=dialog, title='Choose Network', text='Choose a network from the list below') code, tag = radiolist.display() if code in (dialog.CANCEL, dialog.ESC) or not tag: return return [ network['obj'] for network in properties if network['name'] == tag ].pop()
def choose_datacenter(agent, dialog, all_datacenters_option=False): """ Prompts the user to choose a datacenter Convinience function that can be used to choose a datacenter, which result can be used for example to restrict search of inventory to a specific datacenter only, or be used for other purposes, e.g. choosing a datacenter where to deploy a Virtual Machine. Args: agent (VConnector): A VConnector instance dialog (dialog.Dialog): A Dialog instance all_datacenters_option (bool): If True then an option to choose all datacenter is provided as well Returns: A vim.Datacenter managed entity if a datacenter has been selected. Returns None if there are no datacenters found or if selected the 'All Datacenters' option. """ dialog.infobox(text='Retrieving information ...') view = agent.get_datacenter_view() properties = agent.collect_properties(view_ref=view, obj_type=pyVmomi.vim.Datacenter, path_set=['name'], include_mors=True) view.DestroyView() if not properties: return items = [] if all_datacenters_option: items.append(pvc.widget.radiolist.RadioListItem(tag='All Datacenters')) datacenters = [ pvc.widget.radiolist.RadioListItem(tag=datacenter['name']) for datacenter in properties ] items.extend(datacenters) radiolist = pvc.widget.radiolist.RadioList( items=items, dialog=dialog, title='Choose Datacenter', text='Choose a Datacenter from the list below') code, tag = radiolist.display() if not tag: return elif all_datacenters_option and tag == 'All Datacenters': return return [d['obj'] for d in properties if d['name'] == tag].pop()
def choose_host(agent, dialog, folder=None): """ Prompts the user to choose a host Args: agent (VConnector): A VConnector instance dialog (dialog.Dailog): A Dialog instance folder (vim.Folder): A vim.Folder entity Returns: A vim.HostSystem managed entity if the user chose a host. Returns None if no host has been selected or there are no hosts existing """ dialog.infobox(text='Retrieving information ...') if not folder: folder = agent.si.content.rootFolder view = agent.get_container_view(obj_type=[pyVmomi.vim.HostSystem], container=folder) properties = agent.collect_properties( view_ref=view, obj_type=pyVmomi.vim.HostSystem, path_set=['name', 'runtime.connectionState'], include_mors=True) view.DestroyView() if not properties: return items = [ pvc.widget.radiolist.RadioListItem( tag=host['name'], description=host['runtime.connectionState'], ) for host in properties ] radiolist = pvc.widget.radiolist.RadioList( items=items, dialog=dialog, title='Choose Host', text='Choose a host from the list below') code, tag = radiolist.display() if code in (dialog.CANCEL, dialog.ESC) or not tag: return return [h['obj'] for h in properties if h['name'] == tag].pop()
def select_ethernet_adapter(self): """ Prompts the user to select an ethernet adapter Returns: A vim.VirtualEthernetAdapter type on success, None otherwise """ self.dialog.infobox( title=self.title, text='Retrieving information ...' ) # Get the OS descriptor which contains the list of # supported ethernet adapters on the virtual machine for descriptor in self.obj.environmentBrowser.QueryConfigOption().guestOSDescriptor: if hasattr(descriptor, 'supportedEthernetCard'): break else: self.dialog.msgbox( title=self.title, text='No supported ethernet adapters found' ) return # The descriptor.supportedEthernetCard property # contains a list of vim.VirtualEthernetAdapter types. # In the radiolist we build below we use the # vim.VirtualEthernetAdapter.__name__ property to # present the user with a list of adapters to choose from items = [ pvc.widget.radiolist.RadioListItem( tag=card.__name__.split('.')[-1].replace('Virtual', '').upper() ) for card in descriptor.supportedEthernetCard ] radiolist = pvc.widget.radiolist.RadioList( items=items, dialog=self.dialog, title=self.title, text='Select virtual ethernet adapter' ) code, tag = radiolist.display() if code in (self.dialog.CANCEL, self.dialog.ESC) or not tag: return card_name = '{}{}'.format('vim.vm.device.Virtual', tag.title()) return [c for c in descriptor.supportedEthernetCard if c.__name__ == card_name].pop()
def choose_folder(agent, dialog): """ Prompts the user to choose a folder Args: agent (VConnector): A VConnector instance dialog (dialog.Dialog): A Dialog instance Returns: A vim.Folder managed entity """ dialog.infobox( text='Retrieving information ...' ) view = agent.get_container_view(obj_type=[pyVmomi.vim.Folder]) properties = agent.collect_properties( view_ref=view, obj_type=pyVmomi.vim.Folder, path_set=['name'], include_mors=True ) view.DestroyView() # Remove all occurrencies of 'vm', 'host', 'datastore' and # 'network' from the collected folders as these ones are # reserved and we cannot create a datacenter there folders = [f for f in properties if f['name'] not in ('vm', 'host', 'datastore', 'network')] if not folders: return agent.si.content.rootFolder items = [ pvc.widget.radiolist.RadioListItem(tag=folder['name']) for folder in folders ] radiolist = pvc.widget.radiolist.RadioList( items=items, dialog=dialog, title='Choose Folder', text='Choose a folder or CANCEL to select the root folder', ) code, tag = radiolist.display() if not tag: return agent.si.content.rootFolder return [f['obj'] for f in properties if f['name'] == tag].pop()
def choose_folder(agent, dialog): """ Prompts the user to choose a folder Args: agent (VConnector): A VConnector instance dialog (dialog.Dialog): A Dialog instance Returns: A vim.Folder managed entity """ dialog.infobox(text='Retrieving information ...') view = agent.get_container_view(obj_type=[pyVmomi.vim.Folder]) properties = agent.collect_properties(view_ref=view, obj_type=pyVmomi.vim.Folder, path_set=['name'], include_mors=True) view.DestroyView() # Remove all occurrencies of 'vm', 'host', 'datastore' and # 'network' from the collected folders as these ones are # reserved and we cannot create a datacenter there folders = [ f for f in properties if f['name'] not in ('vm', 'host', 'datastore', 'network') ] if not folders: return agent.si.content.rootFolder items = [ pvc.widget.radiolist.RadioListItem(tag=folder['name']) for folder in folders ] radiolist = pvc.widget.radiolist.RadioList( items=items, dialog=dialog, title='Choose Folder', text='Choose a folder or CANCEL to select the root folder', ) code, tag = radiolist.display() if not tag: return agent.si.content.rootFolder return [f['obj'] for f in properties if f['name'] == tag].pop()
def select_backing(self): """ Prompts the user to select device backing Returns: A vim.VirtualDeviceDeviceBackingInfo instance on success, None otherwise """ items = [ pvc.widget.radiolist.RadioListItem(tag='Pass through'), pvc.widget.radiolist.RadioListItem(tag='ATAPI emulation'), ] radiolist = pvc.widget.radiolist.RadioList( items=items, dialog=self.dialog, title=self.title, text='Select device backing' ) code, tag = radiolist.display() if code in (self.dialog.CANCEL, self.dialog.ESC) or not tag: self.dialog.msgbox( title=self.title, text='Invalid device backing selected' ) return if tag == 'Pass through': backing_info = pyVmomi.vim.VirtualCdromRemotePassthroughBackingInfo( deviceName='', useAutoDetect=False, exclusive=False ) elif tag == 'ATAPI emulation': backing_info = pyVmomi.vim.VirtualCdromRemoteAtapiBackingInfo( deviceName='', useAutoDetect=False ) return backing_info
def choose_controller(self, controller): """ Prompts the user to select a virtual controller Args: controller (vim.VirtualController): Controller type to choose from Returns: A vim.VirtualController if a virtual controller has been selected, None otherwise """ controllers = [d for d in self.hardware.device if isinstance(d, controller)] if not controllers: self.dialog.msgbox( title=self.title, text='No suitable controllers found' ) return items = [ pvc.widget.radiolist.RadioListItem( tag=d.deviceInfo.label ) for d in controllers ] radiolist = pvc.widget.radiolist.RadioList( items=items, dialog=self.dialog, title=self.title, text='Select virtual controller' ) code, tag = radiolist.display() if code in (self.dialog.CANCEL, self.dialog.ESC) or not tag: return return [d for d in controllers if d.deviceInfo.label == tag].pop()
def select_historical_interval(self): """ Prompts the user to select an existing historical interval """ self.dialog.infobox(title=self.title, text='Retrieving information ...') intervals = [i.name for i in self.pm.historicalInterval] items = [ pvc.widget.radiolist.RadioListItem(tag=interval) for interval in intervals ] radiolist = pvc.widget.radiolist.RadioList( items=items, dialog=self.dialog, title=self.title, text='Select a historical performance interval', ) return radiolist.display()
def select_historical_interval(self): """ Prompts the user to select an existing historical interval """ self.dialog.infobox( title=self.title, text='Retrieving information ...' ) intervals = [i.name for i in self.pm.historicalInterval] items = [ pvc.widget.radiolist.RadioListItem(tag=interval) for interval in intervals ] radiolist = pvc.widget.radiolist.RadioList( items=items, dialog=self.dialog, title=self.title, text='Select a historical performance interval', ) return radiolist.display()
def choose_datacenter(agent, dialog, all_datacenters_option=False): """ Prompts the user to choose a datacenter Convinience function that can be used to choose a datacenter, which result can be used for example to restrict search of inventory to a specific datacenter only, or be used for other purposes, e.g. choosing a datacenter where to deploy a Virtual Machine. Args: agent (VConnector): A VConnector instance dialog (dialog.Dialog): A Dialog instance all_datacenters_option (bool): If True then an option to choose all datacenter is provided as well Returns: A vim.Datacenter managed entity if a datacenter has been selected. Returns None if there are no datacenters found or if selected the 'All Datacenters' option. """ dialog.infobox( text='Retrieving information ...' ) view = agent.get_datacenter_view() properties = agent.collect_properties( view_ref=view, obj_type=pyVmomi.vim.Datacenter, path_set=['name'], include_mors=True ) view.DestroyView() if not properties: return items = [] if all_datacenters_option: items.append( pvc.widget.radiolist.RadioListItem(tag='All Datacenters') ) datacenters = [ pvc.widget.radiolist.RadioListItem(tag=datacenter['name']) for datacenter in properties ] items.extend(datacenters) radiolist = pvc.widget.radiolist.RadioList( items=items, dialog=dialog, title='Choose Datacenter', text='Choose a Datacenter from the list below' ) code, tag = radiolist.display() if not tag: return elif all_datacenters_option and tag == 'All Datacenters': return return [d['obj'] for d in properties if d['name'] == tag].pop()