Esempio n. 1
0
    def display(self):
        items = [
            pvc.widget.menu.MenuItem(
                tag='DNS',
                description='Find VMs by DNS name',
                on_select=self.find_by_dns
            ),
            pvc.widget.menu.MenuItem(
                tag='IP',
                description='Find VMs by IP address',
                on_select=self.find_by_ip
            ),
            pvc.widget.menu.MenuItem(
                tag='UUID',
                description='Find VMs by UUID',
                on_select=self.find_by_uuid
            ),
            pvc.widget.menu.MenuItem(
                tag='Datastore Path',
                description='Find VM by its location on a datastore',
                on_select=self.find_by_datastore_path
            ),
        ]

        menu = pvc.widget.menu.Menu(
            items=items,
            dialog=self.dialog,
            title='Inventory Search',
            text='Select criteria for searching of hosts'
        )

        menu.display()
Esempio n. 2
0
    def display(self):
        items = [
            pvc.widget.menu.MenuItem(
                tag='Connect',
                description='Connect host to cluster',
                on_select=self.connect_host
            ),
            pvc.widget.menu.MenuItem(
                tag='Disconnect',
                description='Disconnect host(s) from cluster',
                on_select=self.disconnect_host
            ),
            pvc.widget.menu.MenuItem(
                tag='Reconnect',
                description='Reconnect host(s) to cluster',
                on_select=self.reconnect_host
            ),
            pvc.widget.menu.MenuItem(
                tag='View',
                description='View hosts in cluster',
                on_select=pvc.widget.common.host_menu,
                on_select_args=(self.agent, self.dialog, self.obj)
            ),
        ]

        menu = pvc.widget.menu.Menu(
            items=items,
            dialog=self.dialog,
            title=self.title,
            text='Select action to be performed'
        )

        menu.display()
Esempio n. 3
0
def alarm_menu(agent, dialog, obj):
    """
    Args:
        agent         (VConnector): A VConnector instance
        dialog     (dialog.Dailog): A Dialog instance
        obj    (vim.ManagedEntity): A Managed Entity

    """
    title = '{} ({})'.format(obj.name, obj.__class__.__name__)

    dialog.infobox(title=title, text='Retrieving information ...')

    if not obj.triggeredAlarmState:
        dialog.msgbox(title=title, text='No triggered alarms')
        return

    items = [
        pvc.widget.menu.MenuItem(tag=alarm.key,
                                 description=alarm.alarm.info.name,
                                 on_select=pvc.widget.alarm.AlarmWidget,
                                 on_select_args=(agent, dialog, alarm))
        for alarm in obj.triggeredAlarmState
    ]

    menu = pvc.widget.menu.Menu(items=items,
                                dialog=dialog,
                                title=title,
                                text='Select an alarm for more details')

    menu.display()
Esempio n. 4
0
    def display(self):
        items = [
            pvc.widget.menu.MenuItem(
                tag='Create',
                description='Create new datastore',
                on_select=self.create_datastore
            ),
            pvc.widget.menu.MenuItem(
                tag='Unmount',
                description='Unmount datastores',
                on_select=HostSystemUnmountStorage,
                on_select_args=(self.agent, self.dialog, self.obj)
            ),
            pvc.widget.menu.MenuItem(
                tag='View',
                description='View datastores',
                on_select=pvc.widget.common.datastore_menu,
                on_select_args=(self.agent, self.dialog, self.obj)
            ),
        ]

        menu = pvc.widget.menu.Menu(
            items=items,
            dialog=self.dialog,
            title=self.title,
            text='Select an action to be performed'
        )

        menu.display()
Esempio n. 5
0
    def network_menu(self):
        self.dialog.infobox(
            text='Retrieving information ...'
        )

        view = self.agent.get_container_view(
            obj_type=[pyVmomi.vim.Network]
        )

        properties = self.agent.collect_properties(
            view_ref=view,
            obj_type=pyVmomi.vim.Network,
            path_set=['name', 'summary.accessible'],
            include_mors=True
        )
        view.DestroyView()

        items = [
            pvc.widget.menu.MenuItem(
                tag=network['name'],
                description='Accessible' if network['summary.accessible'] else 'Not Accessible',
                on_select=pvc.widget.network.NetworkWidget,
                on_select_args=(self.agent, self.dialog, network['obj'])
            ) for network in properties
        ]

        menu = pvc.widget.menu.Menu(
            items=items,
            dialog=self.dialog,
            title='Networks',
            text='Select a network from the menu that you wish to manage'
        )

        menu.display()
Esempio n. 6
0
    def host_menu(self):
        self.dialog.infobox(title=self.title, text="Retrieving information ...")

        view = self.agent.get_container_view(obj_type=[pyVmomi.vim.HostSystem], container=self.obj)
        properties = self.agent.collect_properties(
            view_ref=view,
            obj_type=pyVmomi.vim.HostSystem,
            path_set=["name", "runtime.connectionState"],
            include_mors=True,
        )
        view.DestroyView()

        if not properties:
            self.dialog.msgbox(title=self.title, text="No hosts found in datacenter")
            return

        items = [
            pvc.widget.menu.MenuItem(
                tag=host["name"],
                description=host["runtime.connectionState"],
                on_select=pvc.widget.hostsystem.HostSystemWidget,
                on_select_args=(self.agent, self.dialog, host["obj"]),
            )
            for host in properties
        ]

        menu = pvc.widget.menu.Menu(
            items=items, dialog=self.dialog, title=self.title, text="Select a host from the menu"
        )

        menu.display()
Esempio n. 7
0
    def display(self):
        items = [
            pvc.widget.menu.MenuItem(tag='Datacenters',
                                     description='Manage Datacenters',
                                     on_select=InventoryDatacenterWidget,
                                     on_select_args=(self.agent, self.dialog)),
            pvc.widget.menu.MenuItem(tag='Clusters',
                                     description='Manage Clusters',
                                     on_select=pvc.widget.common.cluster_menu,
                                     on_select_args=(self.agent, self.dialog)),
            pvc.widget.menu.MenuItem(tag='Hosts',
                                     description='Manage hosts',
                                     on_select=self.host_menu),
            pvc.widget.menu.MenuItem(tag='VMs & Templates',
                                     description='Manage VMs & Templates',
                                     on_select=self.virtual_machine_menu),
            pvc.widget.menu.MenuItem(tag='Datastores',
                                     description='Manage Datastores',
                                     on_select=self.datastore_menu),
            pvc.widget.menu.MenuItem(tag='Networking',
                                     description='Manage Networking',
                                     on_select=self.network_menu),
            pvc.widget.menu.MenuItem(tag='Search',
                                     description='Search Inventory',
                                     on_select=InventorySearchWidget,
                                     on_select_args=(self.agent, self.dialog)),
        ]

        menu = pvc.widget.menu.Menu(items=items,
                                    dialog=self.dialog,
                                    title='Inventory Menu',
                                    text='Select an item from the inventory')

        menu.display()
Esempio n. 8
0
    def display(self):
        items = [
            pvc.widget.menu.MenuItem(
                tag='BusLogic Parallel',
                description='Add SCSI BusLogic Parallel Controller',
                on_select=AddSCSIControllerWidget,
                on_select_args=(self.agent, self.dialog, self.obj,
                                pyVmomi.vim.VirtualBusLogicController)),
            pvc.widget.menu.MenuItem(
                tag='LSI Logic Parallel',
                description='Add SCSI LSI Logic Parallel Controller',
                on_select=AddSCSIControllerWidget,
                on_select_args=(self.agent, self.dialog, self.obj,
                                pyVmomi.vim.VirtualLsiLogicController)),
            pvc.widget.menu.MenuItem(
                tag='LSI Logic SAS',
                description='Add SCSI LSI Logic SAS Controller',
                on_select=AddSCSIControllerWidget,
                on_select_args=(self.agent, self.dialog, self.obj,
                                pyVmomi.vim.VirtualLsiLogicSASController)),
            pvc.widget.menu.MenuItem(
                tag='VMware Paravirtual',
                description='Add SCSI VMware Paravirtual Controller',
                on_select=AddSCSIControllerWidget,
                on_select_args=(self.agent, self.dialog, self.obj,
                                pyVmomi.vim.ParaVirtualSCSIController)),
        ]

        menu = pvc.widget.menu.Menu(items=items,
                                    dialog=self.dialog,
                                    title=self.title,
                                    text='Select a virtual controller to add')

        menu.display()
Esempio n. 9
0
    def display(self):
        items = [
            pvc.widget.menu.MenuItem(
                tag='Mark Template',
                description='Mark Virtual Machine as template',
                on_select=self.mark_as_template
            ),
            pvc.widget.menu.MenuItem(
                tag='Mark VM',
                description='Mark template as Virtual Machine',
                on_select=self.mark_as_virtual_machine
            ),
            pvc.widget.menu.MenuItem(
                tag='Export OVA',
                description='Export as single file (OVA)',
                on_select=VirtualMachineExportWidget,
                on_select_args=(self.agent, self.dialog, self.obj, True)
            ),
            pvc.widget.menu.MenuItem(
                tag='Export OVF',
                description='Export as directory of files (OVF)',
                on_select=VirtualMachineExportWidget,
                on_select_args=(self.agent, self.dialog, self.obj, False)
            ),
        ]

        menu = pvc.widget.menu.Menu(
            dialog=self.dialog,
            items=items,
            title=self.title,
            text='Select an action to be performed'
        )

        menu.display()
Esempio n. 10
0
    def display(self):
        items = [
            pvc.widget.menu.MenuItem(
                tag='Info',
                description='Counter information',
                on_select=self.info
            ),
            pvc.widget.menu.MenuItem(
                tag='Graph',
                description='Display graph',
                on_select=PerformanceCounterGraphWidget,
                on_select_args=(self.agent, self.dialog, self.obj, self.counter, self.realtime)
            ),
        ]

        title = 'Performance counter {0}.{1}.{2}'.format(
            self.counter.groupInfo.key,
            self.counter.nameInfo.key,
            self.counter.unitInfo.key
        )

        menu = pvc.widget.menu.Menu(
            items=items,
            dialog=self.dialog,
            title=self.title,
            text=title
        )

        menu.display()
Esempio n. 11
0
    def find_by_uuid(self):
        """
        Find virtual machines by their UUID

        """
        result = pvc.widget.common.inventory_search_by_uuid(agent=self.agent,
                                                            dialog=self.dialog,
                                                            vm_search=True)

        if not result:
            self.dialog.msgbox(title='Inventory Search',
                               text='No results found')
            return

        items = [
            pvc.widget.menu.MenuItem(
                tag=vm.name,
                description=vm.runtime.powerState,
                on_select=pvc.widget.virtualmachine.VirtualMachineWidget,
                on_select_args=(self.agent, self.dialog, vm)) for vm in result
        ]

        menu = pvc.widget.menu.Menu(
            items=items,
            dialog=self.dialog,
            title='Inventory Search Results',
            text='Found {} virtual machines matching the search criteria'.
            format(len(result)))

        menu.display()
Esempio n. 12
0
    def find_by_uuid(self):
        """
        Find hosts by their UUID

        """
        result = pvc.widget.common.inventory_search_by_uuid(agent=self.agent,
                                                            dialog=self.dialog,
                                                            vm_search=False)

        if not result:
            self.dialog.msgbox(title='Inventory Search',
                               text='No results found')
            return

        items = [
            pvc.widget.menu.MenuItem(
                tag=host.name,
                description=host.runtime.connectionState,
                on_select=pvc.widget.hostsystem.HostSystemWidget,
                on_select_args=(self.agent, self.dialog, host))
            for host in result
        ]

        menu = pvc.widget.menu.Menu(
            items=items,
            dialog=self.dialog,
            title='Inventory Search Results',
            text='Found {} hosts matching the search criteria'.format(
                len(result)))

        menu.display()
Esempio n. 13
0
    def display(self):
        items = [
            pvc.widget.menu.MenuItem(
                tag='Rename',
                description='Rename Virtual Machine',
                on_select=pvc.widget.common.rename,
                on_select_args=(self.obj, self.dialog)
            ),
            pvc.widget.menu.MenuItem(
                tag='Unregister',
                description='Remove from inventory',
                on_select=self.unregister
            ),
            pvc.widget.menu.MenuItem(
                tag='Delete',
                description='Delete from disk',
                on_select=pvc.widget.common.remove,
                on_select_args=(self.obj, self.dialog)
            ),
        ]

        menu = pvc.widget.menu.Menu(
            dialog=self.dialog,
            items=items,
            title=self.title,
            text='Select an action to be performed'
        )

        menu.display()
Esempio n. 14
0
    def display(self):
        items = [
            pvc.widget.menu.MenuItem(
                tag='Details',
                description='View Alarm Details',
                on_select=self.details
            ),
            pvc.widget.menu.MenuItem(
                tag='Acknowledge',
                description='Acknowledge Alarm',
                on_select=self.acknowledge
            ),
            pvc.widget.menu.MenuItem(
                tag='Reset',
                description='Reset Alarm'
            ),
        ]

        menu = pvc.widget.menu.Menu(
            items=items,
            dialog=self.dialog,
            title=self.title,
            text='Select an action to be performed'
        )

        menu.display()
Esempio n. 15
0
    def display(self):
        self.dialog.infobox(
            title=self.title,
            text='Retrieving information ...'
        )

        # Get the unique metrics so we don't get duplicate
        # entries in the resulting menu. Duplicate entries
        # may be seen by counters with more than one
        # object instance, e.g. vmnic0, vmnic1, etc.
        unique_metrics = set([m.counterId for m in self.metric_id])

        perf_counter = self.pm.perfCounter
        counters = [c for c in perf_counter for m in unique_metrics if c.key == m and c.groupInfo.label == self.label]

        items = [
            pvc.widget.menu.MenuItem(
                tag='{0}.{1}.{2}'.format(c.groupInfo.key, c.nameInfo.key, c.unitInfo.key),
                description=c.nameInfo.label,
                on_select=PerformanceCounterWidget,
                on_select_args=(self.agent, self.dialog, self.obj, c, self.realtime)
            ) for c in counters
        ]

        menu = pvc.widget.menu.Menu(
            items=items,
            dialog=self.dialog,
            title=self.title,
            text="Performance counters in group '{}'".format(self.label)
        )

        menu.display()
Esempio n. 16
0
    def display(self):
        self.warn_if_not_vcenter()
        self.show_motd()

        items = [
            pvc.widget.menu.MenuItem(
                tag='Inventory',
                description='Inventory Menu',
                on_select=pvc.widget.inventory.InventoryWidget,
                on_select_args=(self.agent, self.dialog)
            ),
            pvc.widget.menu.MenuItem(
                tag='Administration',
                description='Administration Menu',
                on_select=pvc.widget.administration.AdministrationWidget,
                on_select_args=(self.agent, self.dialog)
            ),
        ]

        menu = pvc.widget.menu.Menu(
            items=items,
            dialog=self.dialog,
            title='Home',
            text='Select an item from the menu',
            cancel_label='Logout'
        )

        menu.display()
Esempio n. 17
0
    def display(self):
        self.dialog.infobox(title=self.title,
                            text='Retrieving information ...')

        # Get the unique metrics so we don't get duplicate
        # entries in the resulting menu. Duplicate entries
        # may be seen by counters with more than one
        # object instance, e.g. vmnic0, vmnic1, etc.
        unique_metrics = set([m.counterId for m in self.metric_id])

        perf_counter = self.pm.perfCounter
        counters = [
            c for c in perf_counter for m in unique_metrics
            if c.key == m and c.groupInfo.label == self.label
        ]

        items = [
            pvc.widget.menu.MenuItem(
                tag='{0}.{1}.{2}'.format(c.groupInfo.key, c.nameInfo.key,
                                         c.unitInfo.key),
                description=c.nameInfo.label,
                on_select=PerformanceCounterWidget,
                on_select_args=(self.agent, self.dialog, self.obj, c,
                                self.realtime)) for c in counters
        ]

        menu = pvc.widget.menu.Menu(
            items=items,
            dialog=self.dialog,
            title=self.title,
            text="Performance counters in group '{}'".format(self.label))

        menu.display()
Esempio n. 18
0
    def display(self):
        items = [
            pvc.widget.menu.MenuItem(
                tag='Details',
                description='View Session Details',
                on_select=self.details
            ),
            pvc.widget.menu.MenuItem(
                tag='Terminate',
                description='Terminate Session',
                on_select=self.terminate
            ),
        ]

        current_session = self.agent.si.content.sessionManager.currentSession
        if current_session.key == self.obj.key:
            title = 'Session {}@{} (This Session)'
        else:
            title = 'Session {}@{}'

        menu = pvc.widget.menu.Menu(
            items=items,
            dialog=self.dialog,
            title=title.format(self.obj.userName, self.obj.ipAddress),
            text='Select an action to be performed'
        )

        menu.display()
Esempio n. 19
0
    def host_menu(self):
        self.dialog.infobox(title=self.title,
                            text='Retrieving information ...')

        view = self.agent.get_container_view(obj_type=[pyVmomi.vim.HostSystem],
                                             container=self.obj)
        properties = self.agent.collect_properties(
            view_ref=view,
            obj_type=pyVmomi.vim.HostSystem,
            path_set=['name', 'runtime.connectionState'],
            include_mors=True)
        view.DestroyView()

        if not properties:
            self.dialog.msgbox(title=self.title,
                               text='No hosts found in datacenter')
            return

        items = [
            pvc.widget.menu.MenuItem(
                tag=host['name'],
                description=host['runtime.connectionState'],
                on_select=pvc.widget.hostsystem.HostSystemWidget,
                on_select_args=(self.agent, self.dialog, host['obj']))
            for host in properties
        ]

        menu = pvc.widget.menu.Menu(items=items,
                                    dialog=self.dialog,
                                    title=self.title,
                                    text='Select a host from the menu')

        menu.display()
Esempio n. 20
0
    def virtual_machine_menu(self):
        self.dialog.infobox(title=self.title, text="Retrieving information ...")

        view = self.agent.get_container_view(obj_type=[pyVmomi.vim.VirtualMachine], container=self.obj)
        properties = self.agent.collect_properties(
            view_ref=view,
            obj_type=pyVmomi.vim.VirtualMachine,
            path_set=["name", "runtime.powerState"],
            include_mors=True,
        )
        view.DestroyView()

        if not properties:
            self.dialog.msgbox(title=self.title, text="No virtual machines found in datacenter")
            return

        items = [
            pvc.widget.menu.MenuItem(
                tag=vm["name"],
                description=vm["runtime.powerState"],
                on_select=pvc.widget.virtualmachine.VirtualMachineWidget,
                on_select_args=(self.agent, self.dialog, vm["obj"]),
            )
            for vm in properties
        ]

        menu = pvc.widget.menu.Menu(
            items=items, dialog=self.dialog, title=self.title, text="Select a virtual machine from the menu"
        )

        menu.display()
Esempio n. 21
0
    def display(self):
        items = [
            pvc.widget.menu.MenuItem(tag='Details',
                                     description='View Session Details',
                                     on_select=self.details),
            pvc.widget.menu.MenuItem(tag='Terminate',
                                     description='Terminate Session',
                                     on_select=self.terminate),
            pvc.widget.menu.MenuItem(tag='Debug',
                                     description='Start a Python REPL console',
                                     on_select=pvc.widget.debug.DebugWidget,
                                     on_select_args=(locals(), globals())),
        ]

        current_session = self.agent.si.content.sessionManager.currentSession
        if current_session.key == self.obj.key:
            title = 'Session {}@{} (This Session)'
        else:
            title = 'Session {}@{}'

        menu = pvc.widget.menu.Menu(items=items,
                                    dialog=self.dialog,
                                    title=title.format(self.obj.userName,
                                                       self.obj.ipAddress),
                                    text='Select an action to be performed')

        menu.display()
Esempio n. 22
0
    def display(self):
        items = [
            pvc.widget.menu.MenuItem(
                tag='Create',
                description='Create new cluster in datacenter',
                on_select=self.create_cluster
            ),
            pvc.widget.menu.MenuItem(
                tag='Remove',
                description='Remove cluster from datacenter'
            ),
            pvc.widget.menu.MenuItem(
                tag='View',
                description='View clusters in datacenter',
                on_select=pvc.widget.common.cluster_menu,
                on_select_args=(self.agent, self.dialog, self.obj)
            ),
        ]

        menu = pvc.widget.menu.Menu(
            items=items,
            dialog=self.dialog,
            title=self.title,
            text='Select an action to be performed'
        )

        menu.display()
Esempio n. 23
0
    def display(self):
        items = [
            pvc.widget.menu.MenuItem(
                tag='Add',
                description='Add virtual hardware',
                on_select=VirtualMachineAddHardwareWidget,
                on_select_args=(self.agent, self.dialog, self.obj)
            ),
            pvc.widget.menu.MenuItem(
                tag='Remove',
                description='Remove virtual hardware'
            ),
            pvc.widget.menu.MenuItem(
                tag='Change',
                description='Change virtual hardware'
            ),
            pvc.widget.menu.MenuItem(
                tag='View',
                description='View virtual hardware',
            ),
        ]

        menu = pvc.widget.menu.Menu(
            items=items,
            dialog=self.dialog,
            title=self.title,
            text='Select an action to be performed'
        )

        menu.display()
Esempio n. 24
0
def host_service_menu(agent, dialog, obj):
    """
    A widget to display a menu of services in a HostSystem

    Args:
        agent      (VConnector): A VConnector instance
        dialog  (dialog.Dailog): A Dialog instance
        obj    (vim.HostSystem): A HostSystem entity

    """
    title = '{} ({})'.format(obj.name, obj.__class__.__name__)

    dialog.infobox(
        title=title,
        text='Retrieving information ...'
    )

    items = [
        pvc.widget.menu.MenuItem(
            tag=service.key,
            description=service.label,
            on_select=pvc.widget.hostsystem.HostSystemServiceWidget,
            on_select_args=(agent, dialog, obj, service)
        ) for service in obj.config.service.service
    ]

    menu = pvc.widget.menu.Menu(
        items=items,
        dialog=dialog,
        title=title,
        text='Choose a service to manage'
    )

    menu.display()
Esempio n. 25
0
    def virtual_machine_menu(self):
        self.dialog.infobox(title=self.title,
                            text='Retrieving information ...')

        view = self.agent.get_container_view(
            obj_type=[pyVmomi.vim.VirtualMachine], container=self.obj)
        properties = self.agent.collect_properties(
            view_ref=view,
            obj_type=pyVmomi.vim.VirtualMachine,
            path_set=['name', 'runtime.powerState'],
            include_mors=True)
        view.DestroyView()

        if not properties:
            self.dialog.msgbox(title=self.title,
                               text='No virtual machines found in datacenter')
            return

        items = [
            pvc.widget.menu.MenuItem(
                tag=vm['name'],
                description=vm['runtime.powerState'],
                on_select=pvc.widget.virtualmachine.VirtualMachineWidget,
                on_select_args=(self.agent, self.dialog, vm['obj']))
            for vm in properties
        ]

        menu = pvc.widget.menu.Menu(
            items=items,
            dialog=self.dialog,
            title=self.title,
            text='Select a virtual machine from the menu')

        menu.display()
Esempio n. 26
0
    def find_by_uuid(self):
        """
        Find virtual machines by their UUID

        """
        result = pvc.widget.common.inventory_search_by_uuid(
            agent=self.agent,
            dialog=self.dialog,
            vm_search=True
        )

        if not result:
            self.dialog.msgbox(
                title='Inventory Search',
                text='No results found'
            )
            return

        items = [
            pvc.widget.menu.MenuItem(
                tag=vm.name,
                description=vm.runtime.powerState,
                on_select=pvc.widget.virtualmachine.VirtualMachineWidget,
                on_select_args=(self.agent, self.dialog, vm)
            ) for vm in result
        ]

        menu = pvc.widget.menu.Menu(
            items=items,
            dialog=self.dialog,
            title='Inventory Search Results',
            text='Found {} virtual machines matching the search criteria'.format(len(result))
        )

        menu.display()
Esempio n. 27
0
def host_service_menu(agent, dialog, obj):
    """
    A widget to display a menu of services in a HostSystem

    Args:
        agent      (VConnector): A VConnector instance
        dialog  (dialog.Dailog): A Dialog instance
        obj    (vim.HostSystem): A HostSystem entity

    """
    title = '{} ({})'.format(obj.name, obj.__class__.__name__)

    dialog.infobox(title=title, text='Retrieving information ...')

    items = [
        pvc.widget.menu.MenuItem(
            tag=service.key,
            description=service.label,
            on_select=pvc.widget.hostsystem.HostSystemServiceWidget,
            on_select_args=(agent, dialog, obj, service))
        for service in obj.config.service.service
    ]

    menu = pvc.widget.menu.Menu(items=items,
                                dialog=dialog,
                                title=title,
                                text='Choose a service to manage')

    menu.display()
Esempio n. 28
0
    def virtual_machine_menu(self):
        self.dialog.infobox(
            text='Retrieving information ...'
        )

        view = self.agent.get_vm_view()
        properties = self.agent.collect_properties(
            view_ref=view,
            obj_type=pyVmomi.vim.VirtualMachine,
            path_set=['name', 'runtime.powerState'],
            include_mors=True
        )
        view.DestroyView()

        items = [
            pvc.widget.menu.MenuItem(
                tag=vm['name'],
                description=vm['runtime.powerState'],
                on_select=pvc.widget.virtualmachine.VirtualMachineWidget,
                on_select_args=(self.agent, self.dialog, vm['obj'])
            ) for vm in properties
        ]

        menu = pvc.widget.menu.Menu(
            items=items,
            dialog=self.dialog,
            title='Virtual Machines',
            text='Select a Virtual Machine from the menu'
        )

        menu.display()
Esempio n. 29
0
    def datastore_menu(self):
        self.dialog.infobox(text='Retrieving information ...')

        view = self.agent.get_datastore_view()
        properties = self.agent.collect_properties(
            view_ref=view,
            obj_type=pyVmomi.vim.Datastore,
            path_set=['name', 'summary.accessible'],
            include_mors=True)
        view.DestroyView()

        items = [
            pvc.widget.menu.MenuItem(
                tag=ds['name'],
                description='Accessible'
                if ds['summary.accessible'] else 'Not Accessible',
                on_select=pvc.widget.datastore.DatastoreWidget,
                on_select_args=(self.agent, self.dialog, ds['obj']))
            for ds in properties
        ]

        menu = pvc.widget.menu.Menu(items=items,
                                    dialog=self.dialog,
                                    title='Datastores',
                                    text='Select a Datastore from the menu')

        menu.display()
Esempio n. 30
0
    def host_menu(self):
        self.dialog.infobox(
            text='Retrieving information ...'
        )

        view = self.agent.get_host_view()
        properties = self.agent.collect_properties(
            view_ref=view,
            obj_type=pyVmomi.vim.HostSystem,
            path_set=['name', 'runtime.connectionState'],
            include_mors=True
        )
        view.DestroyView()

        items = [
            pvc.widget.menu.MenuItem(
                tag=host['name'],
                description=host['runtime.connectionState'],
                on_select=pvc.widget.hostsystem.HostSystemWidget,
                on_select_args=(self.agent, self.dialog, host['obj'])
            ) for host in properties
        ]

        menu = pvc.widget.menu.Menu(
            items=items,
            dialog=self.dialog,
            title='Hosts',
            text='Select a host from the menu'
        )

        menu.display()
Esempio n. 31
0
    def datastore_menu(self):
        self.dialog.infobox(
            text='Retrieving information ...'
        )

        view = self.agent.get_datastore_view()
        properties = self.agent.collect_properties(
            view_ref=view,
            obj_type=pyVmomi.vim.Datastore,
            path_set=['name', 'summary.accessible'],
            include_mors=True
        )
        view.DestroyView()

        items = [
            pvc.widget.menu.MenuItem(
                tag=ds['name'],
                description='Accessible' if ds['summary.accessible'] else 'Not Accessible',
                on_select=pvc.widget.datastore.DatastoreWidget,
                on_select_args=(self.agent, self.dialog, ds['obj'])
            ) for ds in properties
        ]

        menu = pvc.widget.menu.Menu(
            items=items,
            dialog=self.dialog,
            title='Datastores',
            text='Select a Datastore from the menu'
        )

        menu.display()
Esempio n. 32
0
    def display(self):
        items = [
            pvc.widget.menu.MenuItem(
                tag='Rename',
                description='Rename datastore',
                on_select=pvc.widget.common.rename,
                on_select_args=(self.obj, self.dialog)
            ),
            pvc.widget.menu.MenuItem(
                tag='Refresh',
                description='Refresh storage information',
                on_select=self.refresh
            ),
            pvc.widget.menu.MenuItem(
                tag='Remove',
                description='Remove datastore',
                on_select=pvc.widget.common.remove,
                on_select_args=(self.obj, self.dialog)
            ),
        ]

        menu = pvc.widget.menu.Menu(
            items=items,
            dialog=self.dialog,
            title=self.title,
            text='Select an action to be performed'
        )

        menu.display()
Esempio n. 33
0
    def display(self):
        items = [
            pvc.widget.menu.MenuItem(
                tag='Details',
                description='View Alarm Details',
                on_select=self.details
            ),
            pvc.widget.menu.MenuItem(
                tag='Acknowledge',
                description='Acknowledge Alarm',
                on_select=self.acknowledge
            ),
            pvc.widget.menu.MenuItem(
                tag='Reset',
                description='Reset Alarm'
            ),
            pvc.widget.menu.MenuItem(
                tag='Debug',
                description='Start a Python REPL console',
                on_select=pvc.widget.debug.DebugWidget,
                on_select_args=(locals(), globals())
            ),
        ]

        menu = pvc.widget.menu.Menu(
            items=items,
            dialog=self.dialog,
            title=self.title,
            text='Select an action to be performed'
        )

        menu.display()
Esempio n. 34
0
    def find_by_uuid(self):
        """
        Find hosts by their UUID

        """
        result = pvc.widget.common.inventory_search_by_uuid(
            agent=self.agent,
            dialog=self.dialog,
            vm_search=False
        )

        if not result:
            self.dialog.msgbox(
                title='Inventory Search',
                text='No results found'
            )
            return

        items = [
            pvc.widget.menu.MenuItem(
                tag=host.name,
                description=host.runtime.connectionState,
                on_select=pvc.widget.hostsystem.HostSystemWidget,
                on_select_args=(self.agent, self.dialog, host)
            ) for host in result
        ]

        menu = pvc.widget.menu.Menu(
            items=items,
            dialog=self.dialog,
            title='Inventory Search Results',
            text='Found {} hosts matching the search criteria'.format(len(result))
        )

        menu.display()
Esempio n. 35
0
    def display(self):
        items = [
            pvc.widget.menu.MenuItem(tag='Info',
                                     description='View Service Info',
                                     on_select=self.info),
            pvc.widget.menu.MenuItem(tag='Start',
                                     description='Start Service',
                                     on_select=self.start),
            pvc.widget.menu.MenuItem(tag='Stop',
                                     description='Stop Service',
                                     on_select=self.stop),
            pvc.widget.menu.MenuItem(tag='Restart',
                                     description='Restart Service',
                                     on_select=self.restart),
            pvc.widget.menu.MenuItem(tag='Uninstall',
                                     description='Uninstall Service',
                                     on_select=self.uninstall),
            pvc.widget.menu.MenuItem(tag='Policy',
                                     description='Update Service Policy',
                                     on_select=self.update_policy),
        ]

        menu = pvc.widget.menu.Menu(items=items,
                                    dialog=self.dialog,
                                    title=self.title,
                                    text='Select an action to be performed')

        menu.display()
Esempio n. 36
0
    def network_menu(self):
        self.dialog.infobox(text='Retrieving information ...')

        view = self.agent.get_container_view(obj_type=[pyVmomi.vim.Network])

        properties = self.agent.collect_properties(
            view_ref=view,
            obj_type=pyVmomi.vim.Network,
            path_set=['name', 'summary.accessible'],
            include_mors=True)
        view.DestroyView()

        items = [
            pvc.widget.menu.MenuItem(
                tag=network['name'],
                description='Accessible'
                if network['summary.accessible'] else 'Not Accessible',
                on_select=pvc.widget.network.NetworkWidget,
                on_select_args=(self.agent, self.dialog, network['obj']))
            for network in properties
        ]

        menu = pvc.widget.menu.Menu(
            items=items,
            dialog=self.dialog,
            title='Networks',
            text='Select a network from the menu that you wish to manage')

        menu.display()
Esempio n. 37
0
    def display(self):
        items = [
            pvc.widget.menu.MenuItem(
                tag='General',
                description='General information',
                on_select=self.info
            ),
            pvc.widget.menu.MenuItem(
                tag='Capacity',
                description='Datastore Capacity ',
                on_select=self.capacity
            ),
            pvc.widget.menu.MenuItem(
                tag='Actions',
                description='Available Actions',
                on_select=DatastoreActionWidget,
                on_select_args=(self.agent, self.dialog, self.obj)
            ),
            pvc.widget.menu.MenuItem(
                tag='Hosts',
                description='Hosts using the datastore',
                on_select=pvc.widget.common.hostmount_menu,
                on_select_args=(self.agent, self.dialog, self.obj)
            ),
            pvc.widget.menu.MenuItem(
                tag='Virtual Machines',
                description='Virtual Machines using the datastore',
                on_select=pvc.widget.common.virtual_machine_menu,
                on_select_args=(self.agent, self.dialog, self.obj)
            ),
            pvc.widget.menu.MenuItem(
                tag='Performance',
                description='Performance Metrics',
                on_select=pvc.widget.performance.PerformanceProviderWidget,
                on_select_args=(self.agent, self.dialog, self.obj)
            ),
            pvc.widget.menu.MenuItem(
                tag='Events',
                description='View Events',
                on_select=pvc.widget.event.EventWidget,
                on_select_args=(self.agent, self.dialog, self.obj)
            ),
            pvc.widget.menu.MenuItem(
                tag='Alarms',
                description='View triggered alarms',
                on_select=pvc.widget.common.alarm_menu,
                on_select_args=(self.agent, self.dialog, self.obj)
            ),
        ]

        menu = pvc.widget.menu.Menu(
            items=items,
            dialog=self.dialog,
            title=self.title,
            text='Select an action to be performed'
        )

        menu.display()
Esempio n. 38
0
def virtual_machine_menu(agent, dialog, obj):
    """
    A widget to display the VMs contained within a Managed Entity, e.g.
    HostSystem, ClusterComputeResource, Datastore, etc.

    Args:
        agent         (VConnector): A VConnector instance
        dialog     (dialog.Dailog): A Dialog instance
        obj    (vim.ManagedEntity): A Managed Entity

    """
    title = '{} ({})'.format(obj.name, obj.__class__.__name__)

    dialog.infobox(
        title=title,
        text='Retrieving information ...'
    )

    if not hasattr(obj, 'vm'):
        dialog.msgbox(
            title=title,
            text='Entity does not contain a vm property'
        )
        return

    view = agent.get_list_view(obj.vm)
    properties = agent.collect_properties(
        view_ref=view,
        obj_type=pyVmomi.vim.VirtualMachine,
        path_set=['name', 'runtime.powerState'],
        include_mors=True
    )
    view.DestroyView()

    if not properties:
        dialog.msgbox(
            title=title,
            text='No virtual machines found for this managed entity'
        )
        return

    items = [
        pvc.widget.menu.MenuItem(
            tag=vm['name'],
            description=vm['runtime.powerState'],
            on_select=pvc.widget.virtualmachine.VirtualMachineWidget,
            on_select_args=(agent, dialog, vm['obj'])
        ) for vm in properties
    ]

    menu = pvc.widget.menu.Menu(
        items=items,
        dialog=dialog,
        title=title,
        text=''
    )

    menu.display()
Esempio n. 39
0
def datastore_menu(agent, dialog, obj):
    """
    A widget to get all Datastores used by a managed entity, e.g.
    HostSystem, VirtualMachine, Cluster, etc.

    Args:
        agent         (VConnector): A VConnector instance
        dialog     (dialog.Dailog): A Dialog instance
        obj    (vim.ManagedEntity): A Managed Entity

    """
    title = '{} ({})'.format(obj.name, obj.__class__.__name__)

    dialog.infobox(
        title=title,
        text='Retrieving information ...'
    )

    if not hasattr(obj, 'datastore'):
        dialog.msgbox(
            title=title,
            text='Entity does not contain a datastore property'
        )
        return

    view = agent.get_list_view(obj.datastore)
    properties = agent.collect_properties(
        view_ref=view,
        obj_type=pyVmomi.vim.Datastore,
        path_set=['name', 'summary.accessible'],
        include_mors=True
    )
    view.DestroyView()

    if not properties:
        dialog.msgbox(
            title=title,
            text='No datastores found for this managed entity'
        )
        return

    items = [
        pvc.widget.menu.MenuItem(
            tag=ds['name'],
            description='Accessible' if ds['summary.accessible'] else 'Not Accessible',
            on_select=pvc.widget.datastore.DatastoreWidget,
            on_select_args=(agent, dialog, ds['obj'])
        ) for ds in properties
    ]

    menu = pvc.widget.menu.Menu(
        items=items,
        dialog=dialog,
        title=title,
        text=''
    )

    menu.display()
Esempio n. 40
0
def network_menu(agent, dialog, obj):
    """
    A widget to display the networks by a Managed Entity

    Args:
        agent         (VConnector): A VConnector instance
        dialog     (dialog.Dailog): A Dialog instance
        obj    (vim.ManagedEntity): A Managed Entity

    """
    title = '{} ({})'.format(obj.name, obj.__class__.__name__)

    dialog.infobox(
        title=title,
        text='Retrieving information ...'
    )

    if not hasattr(obj, 'network'):
        dialog.msgbox(
            title=title,
            text='Entity does not contain a network property'
        )
        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:
        dialog.msgbox(
            title=title,
            text='No networks found for this managed entity'
        )
        return

    items = [
        pvc.widget.menu.MenuItem(
            tag=network['name'],
            description='Accessible' if network['summary.accessible'] else 'Not Accessible',
            on_select=pvc.widget.network.NetworkWidget,
            on_select_args=(agent, dialog, network['obj'])
        ) for network in properties
    ]

    menu = pvc.widget.menu.Menu(
        items=items,
        dialog=dialog,
        title=title,
        text=''
    )

    menu.display()
Esempio n. 41
0
def host_menu(agent, dialog, obj):
    """
    A widget to display a menu of HostSystem entities

    Args:
        agent         (VConnector): A VConnector instance
        dialog     (dialog.Dailog): A Dialog instance
        obj    (vim.ManagedEntity): A Managed Entity

    """
    title = '{} ({})'.format(obj.name, obj.__class__.__name__)

    dialog.infobox(
        title=title,
        text='Retrieving information ...'
    )

    if not hasattr(obj, 'host'):
        dialog.msgbox(
            title=title,
            text='Entity does not contain a host property'
        )
        return

    view = agent.get_list_view(obj.host)
    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:
        dialog.msgbox(
            title=title,
            text='No hosts found on this managed entity'
        )
        return

    items = [
        pvc.widget.menu.MenuItem(
            tag=host['name'],
            description=host['runtime.connectionState'],
            on_select=pvc.widget.hostsystem.HostSystemWidget,
            on_select_args=(agent, dialog, host['obj'])
        ) for host in properties
    ]

    menu = pvc.widget.menu.Menu(
        items=items,
        dialog=dialog,
        title=title,
        text=''
    )

    menu.display()
Esempio n. 42
0
    def display(self):
        items = [
            pvc.widget.menu.MenuItem(tag='General',
                                     description='General information',
                                     on_select=self.info),
            pvc.widget.menu.MenuItem(tag='Resources',
                                     description='Resource usage information',
                                     on_select=self.resources),
            pvc.widget.menu.MenuItem(tag='Virtual Machines',
                                     description='Manage Virtual Machines',
                                     on_select=HostSystemVirtualMachineWidget,
                                     on_select_args=(self.agent, self.dialog,
                                                     self.obj)),
            pvc.widget.menu.MenuItem(tag='Networks',
                                     description='Host Networks',
                                     on_select=pvc.widget.common.network_menu,
                                     on_select_args=(self.agent, self.dialog,
                                                     self.obj)),
            pvc.widget.menu.MenuItem(
                tag='Datastores',
                description='Manage datastores on this host',
                on_select=HostSystemDatastoreWidget,
                on_select_args=(self.agent, self.dialog, self.obj)),
            pvc.widget.menu.MenuItem(
                tag='Performance',
                description='Performance Metrics',
                on_select=pvc.widget.performance.PerformanceProviderWidget,
                on_select_args=(self.agent, self.dialog, self.obj)),
            pvc.widget.menu.MenuItem(tag='Events',
                                     description='View Events',
                                     on_select=pvc.widget.event.EventWidget,
                                     on_select_args=(self.agent, self.dialog,
                                                     self.obj)),
            pvc.widget.menu.MenuItem(tag='Alarms',
                                     description='View triggered alarms',
                                     on_select=pvc.widget.common.alarm_menu,
                                     on_select_args=(self.agent, self.dialog,
                                                     self.obj)),
            pvc.widget.menu.MenuItem(
                tag='Services',
                description='Manage Services',
                on_select=pvc.widget.common.host_service_menu,
                on_select_args=(self.agent, self.dialog, self.obj)),
            pvc.widget.menu.MenuItem(tag='Debug',
                                     description='Start a Python REPL console',
                                     on_select=pvc.widget.debug.DebugWidget,
                                     on_select_args=(locals(), globals())),
        ]

        menu = pvc.widget.menu.Menu(items=items,
                                    dialog=self.dialog,
                                    title=self.title,
                                    text='Select an action to be performed')

        menu.display()
Esempio n. 43
0
    def realtime_counter_groups(self):
        """
        Available real-time counter groups

        """
        self.dialog.infobox(
            title=self.title,
            text='Retrieving information ...'
        )

        provider_summary = self.pm.QueryPerfProviderSummary(
            entity=self.obj
        )

        if not provider_summary.currentSupported:
            self.dialog.msgbox(
                title=self.title,
                text='Provider does not support real-time statistics'
            )
            return

        metric_id = self.pm.QueryAvailablePerfMetric(
            entity=self.obj,
            intervalId=provider_summary.refreshRate
        )

        if not metric_id:
            self.dialog.msgbox(
                title=self.title,
                text='Performance data is currently not available for entity'
            )
            return

        perf_counter = self.pm.perfCounter
        counters = [c for c in perf_counter for m in metric_id if c.key == m.counterId]
        groups = set([(c.groupInfo.key, c.groupInfo.label) for c in counters])

        items = [
            pvc.widget.menu.MenuItem(
                tag=key,
                description=label,
                on_select=PerformanceCounterInGroupWidget,
                on_select_args=(self.agent, self.dialog, self.obj, metric_id, label, True)
            ) for key, label in groups
        ]

        menu = pvc.widget.menu.Menu(
            items=items,
            dialog=self.dialog,
            title=self.title,
            text='Select a performance counter group'
        )

        menu.display()
Esempio n. 44
0
    def display(self):
        items = [
            pvc.widget.menu.MenuItem(tag="General", description="General information", on_select=self.info),
            pvc.widget.menu.MenuItem(tag="Capacity", description="Datastore Capacity ", on_select=self.capacity),
            pvc.widget.menu.MenuItem(
                tag="Actions",
                description="Available Actions",
                on_select=DatastoreActionWidget,
                on_select_args=(self.agent, self.dialog, self.obj),
            ),
            pvc.widget.menu.MenuItem(
                tag="Hosts",
                description="Hosts using the datastore",
                on_select=pvc.widget.common.hostmount_menu,
                on_select_args=(self.agent, self.dialog, self.obj),
            ),
            pvc.widget.menu.MenuItem(
                tag="Virtual Machines",
                description="Virtual Machines using the datastore",
                on_select=pvc.widget.common.virtual_machine_menu,
                on_select_args=(self.agent, self.dialog, self.obj),
            ),
            pvc.widget.menu.MenuItem(
                tag="Performance",
                description="Performance Metrics",
                on_select=pvc.widget.performance.PerformanceProviderWidget,
                on_select_args=(self.agent, self.dialog, self.obj),
            ),
            pvc.widget.menu.MenuItem(
                tag="Events",
                description="View Events",
                on_select=pvc.widget.event.EventWidget,
                on_select_args=(self.agent, self.dialog, self.obj),
            ),
            pvc.widget.menu.MenuItem(
                tag="Alarms",
                description="View triggered alarms",
                on_select=pvc.widget.common.alarm_menu,
                on_select_args=(self.agent, self.dialog, self.obj),
            ),
            pvc.widget.menu.MenuItem(
                tag="Debug",
                description="Start a Python REPL console",
                on_select=pvc.widget.debug.DebugWidget,
                on_select_args=(locals(), globals()),
            ),
        ]

        menu = pvc.widget.menu.Menu(
            items=items, dialog=self.dialog, title=self.title, text="Select an action to be performed"
        )

        menu.display()
Esempio n. 45
0
    def display(self):
        items = [
            pvc.widget.menu.MenuItem(tag='View',
                                     description='View hosts in datacenter',
                                     on_select=self.host_menu),
        ]

        menu = pvc.widget.menu.Menu(items=items,
                                    dialog=self.dialog,
                                    title=self.title,
                                    text='Select item from menu')

        menu.display()
Esempio n. 46
0
def hostmount_menu(agent, dialog, obj):
    """
    A widget to display a menu of DatastoreHostMount instances

    To be used with datastores in order to provide a menu of
    hosts mounting a particular datastore

    Args:
        agent     (VConnector): A VConnector instance
        dialog (dialog.Dailog): A Dialog instance
        obj    (vim.Datastore): A Managed Entity

    """
    title = '{} ({})'.format(obj.name, obj.__class__.__name__)

    dialog.infobox(title=title, text='Retrieving information ...')

    if not hasattr(obj, 'host'):
        dialog.msgbox(title=title,
                      text='Entity does not contain a host property')
        return

    hosts = [h.key for h in obj.host]
    view = agent.get_list_view(hosts)
    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:
        dialog.msgbox(title=title, text='No hosts have mounted the datastore')
        return

    items = [
        pvc.widget.menu.MenuItem(
            tag=host['name'],
            description=host['runtime.connectionState'],
            on_select=pvc.widget.hostsystem.HostSystemWidget,
            on_select_args=(agent, dialog, host['obj'])) for host in properties
    ]

    menu = pvc.widget.menu.Menu(
        items=items,
        dialog=dialog,
        title=title,
        text='',
    )

    menu.display()
Esempio n. 47
0
    def display(self):
        items = [
            pvc.widget.menu.MenuItem(tag='General',
                                     description='General information',
                                     on_select=self.info),
            pvc.widget.menu.MenuItem(tag='Capacity',
                                     description='Datastore Capacity ',
                                     on_select=self.capacity),
            pvc.widget.menu.MenuItem(tag='Actions',
                                     description='Available Actions',
                                     on_select=DatastoreActionWidget,
                                     on_select_args=(self.agent, self.dialog,
                                                     self.obj)),
            pvc.widget.menu.MenuItem(
                tag='Hosts',
                description='Hosts using the datastore',
                on_select=pvc.widget.common.hostmount_menu,
                on_select_args=(self.agent, self.dialog, self.obj)),
            pvc.widget.menu.MenuItem(
                tag='Virtual Machines',
                description='Virtual Machines using the datastore',
                on_select=pvc.widget.common.virtual_machine_menu,
                on_select_args=(self.agent, self.dialog, self.obj)),
            pvc.widget.menu.MenuItem(
                tag='Performance',
                description='Performance Metrics',
                on_select=pvc.widget.performance.PerformanceProviderWidget,
                on_select_args=(self.agent, self.dialog, self.obj)),
            pvc.widget.menu.MenuItem(tag='Events',
                                     description='View Events',
                                     on_select=pvc.widget.event.EventWidget,
                                     on_select_args=(self.agent, self.dialog,
                                                     self.obj)),
            pvc.widget.menu.MenuItem(tag='Alarms',
                                     description='View triggered alarms',
                                     on_select=pvc.widget.common.alarm_menu,
                                     on_select_args=(self.agent, self.dialog,
                                                     self.obj)),
            pvc.widget.menu.MenuItem(tag='Debug',
                                     description='Start a Python REPL console',
                                     on_select=pvc.widget.debug.DebugWidget,
                                     on_select_args=(locals(), globals())),
        ]

        menu = pvc.widget.menu.Menu(items=items,
                                    dialog=self.dialog,
                                    title=self.title,
                                    text='Select an action to be performed')

        menu.display()
Esempio n. 48
0
    def display(self):
        items = [
            pvc.widget.menu.MenuItem(tag='View',
                                     description='View networks in datacenter',
                                     on_select=pvc.widget.common.network_menu,
                                     on_select_args=(self.agent, self.dialog,
                                                     self.obj)),
        ]

        menu = pvc.widget.menu.Menu(items=items,
                                    dialog=self.dialog,
                                    title=self.title,
                                    text='Select item from menu')

        menu.display()
Esempio n. 49
0
def datastore_menu(agent, dialog, obj):
    """
    A widget to get all Datastores used by a managed entity, e.g.
    HostSystem, VirtualMachine, Cluster, etc.

    Args:
        agent         (VConnector): A VConnector instance
        dialog     (dialog.Dailog): A Dialog instance
        obj    (vim.ManagedEntity): A Managed Entity

    """
    title = '{} ({})'.format(obj.name, obj.__class__.__name__)

    dialog.infobox(title=title, text='Retrieving information ...')

    if not hasattr(obj, 'datastore'):
        dialog.msgbox(title=title,
                      text='Entity does not contain a datastore property')
        return

    view = agent.get_list_view(obj.datastore)
    properties = agent.collect_properties(
        view_ref=view,
        obj_type=pyVmomi.vim.Datastore,
        path_set=['name', 'summary.accessible'],
        include_mors=True)
    view.DestroyView()

    if not properties:
        dialog.msgbox(title=title,
                      text='No datastores found for this managed entity')
        return

    items = [
        pvc.widget.menu.MenuItem(
            tag=ds['name'],
            description='Accessible'
            if ds['summary.accessible'] else 'Not Accessible',
            on_select=pvc.widget.datastore.DatastoreWidget,
            on_select_args=(agent, dialog, ds['obj'])) for ds in properties
    ]

    menu = pvc.widget.menu.Menu(items=items,
                                dialog=dialog,
                                title=title,
                                text='')

    menu.display()
Esempio n. 50
0
def network_menu(agent, dialog, obj):
    """
    A widget to display the networks by a Managed Entity

    Args:
        agent         (VConnector): A VConnector instance
        dialog     (dialog.Dailog): A Dialog instance
        obj    (vim.ManagedEntity): A Managed Entity

    """
    title = '{} ({})'.format(obj.name, obj.__class__.__name__)

    dialog.infobox(title=title, text='Retrieving information ...')

    if not hasattr(obj, 'network'):
        dialog.msgbox(title=title,
                      text='Entity does not contain a network property')
        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:
        dialog.msgbox(title=title,
                      text='No networks found for this managed entity')
        return

    items = [
        pvc.widget.menu.MenuItem(
            tag=network['name'],
            description='Accessible'
            if network['summary.accessible'] else 'Not Accessible',
            on_select=pvc.widget.network.NetworkWidget,
            on_select_args=(agent, dialog, network['obj']))
        for network in properties
    ]

    menu = pvc.widget.menu.Menu(items=items,
                                dialog=dialog,
                                title=title,
                                text='')

    menu.display()
Esempio n. 51
0
    def realtime_counter_groups(self):
        """
        Available real-time counter groups

        """
        self.dialog.infobox(title=self.title,
                            text='Retrieving information ...')

        provider_summary = self.pm.QueryPerfProviderSummary(entity=self.obj)

        if not provider_summary.currentSupported:
            self.dialog.msgbox(
                title=self.title,
                text='Provider does not support real-time statistics')
            return

        metric_id = self.pm.QueryAvailablePerfMetric(
            entity=self.obj, intervalId=provider_summary.refreshRate)

        if not metric_id:
            self.dialog.msgbox(
                title=self.title,
                text='Performance data is currently not available for entity')
            return

        perf_counter = self.pm.perfCounter
        counters = [
            c for c in perf_counter for m in metric_id if c.key == m.counterId
        ]
        groups = set([(c.groupInfo.key, c.groupInfo.label) for c in counters])

        items = [
            pvc.widget.menu.MenuItem(tag=key,
                                     description=label,
                                     on_select=PerformanceCounterInGroupWidget,
                                     on_select_args=(self.agent, self.dialog,
                                                     self.obj, metric_id,
                                                     label, True))
            for key, label in groups
        ]

        menu = pvc.widget.menu.Menu(items=items,
                                    dialog=self.dialog,
                                    title=self.title,
                                    text='Select a performance counter group')

        menu.display()
Esempio n. 52
0
def virtual_machine_menu(agent, dialog, obj):
    """
    A widget to display the VMs contained within a Managed Entity, e.g.
    HostSystem, ClusterComputeResource, Datastore, etc.

    Args:
        agent         (VConnector): A VConnector instance
        dialog     (dialog.Dailog): A Dialog instance
        obj    (vim.ManagedEntity): A Managed Entity

    """
    title = '{} ({})'.format(obj.name, obj.__class__.__name__)

    dialog.infobox(title=title, text='Retrieving information ...')

    if not hasattr(obj, 'vm'):
        dialog.msgbox(title=title,
                      text='Entity does not contain a vm property')
        return

    view = agent.get_list_view(obj.vm)
    properties = agent.collect_properties(
        view_ref=view,
        obj_type=pyVmomi.vim.VirtualMachine,
        path_set=['name', 'runtime.powerState'],
        include_mors=True)
    view.DestroyView()

    if not properties:
        dialog.msgbox(title=title,
                      text='No virtual machines found for this managed entity')
        return

    items = [
        pvc.widget.menu.MenuItem(
            tag=vm['name'],
            description=vm['runtime.powerState'],
            on_select=pvc.widget.virtualmachine.VirtualMachineWidget,
            on_select_args=(agent, dialog, vm['obj'])) for vm in properties
    ]

    menu = pvc.widget.menu.Menu(items=items,
                                dialog=dialog,
                                title=title,
                                text='')

    menu.display()
Esempio n. 53
0
    def find_by_datastore_path(self):
        """
        Find virtual machine it's localtion on a datastore

        """
        datacenter = pvc.widget.common.choose_datacenter(
            agent=self.agent, dialog=self.dialog, all_datacenters_option=False)

        if not datacenter:
            self.dialog.msgbox(
                title='Error',
                text='No datacenter specified for inventory search')
            return

        code, path = self.dialog.inputbox(
            title='Inventory Search',
            text='Specify datastore path to the .vmx file')

        if not path:
            self.dialog.msgbox(title='Error', text='Invalid input provided')
            return

        self.dialog.infobox(text='Searching Inventory ...')

        vm = self.agent.si.content.searchIndex.FindByDatastorePath(
            datacenter=datacenter, path=path)

        if not vm:
            self.dialog.msgbox(title='Inventory Search',
                               text='No results found')
            return

        items = [
            pvc.widget.menu.MenuItem(
                tag=vm.name,
                description=vm.runtime.powerState,
                on_select=pvc.widget.virtualmachine.VirtualMachineWidget,
                on_select_args=(self.agent, self.dialog, vm))
        ]

        menu = pvc.widget.menu.Menu(items=items,
                                    dialog=self.dialog,
                                    title='Inventory Search Results',
                                    text='')

        menu.display()
Esempio n. 54
0
def host_menu(agent, dialog, obj):
    """
    A widget to display a menu of HostSystem entities

    Args:
        agent         (VConnector): A VConnector instance
        dialog     (dialog.Dailog): A Dialog instance
        obj    (vim.ManagedEntity): A Managed Entity

    """
    title = '{} ({})'.format(obj.name, obj.__class__.__name__)

    dialog.infobox(title=title, text='Retrieving information ...')

    if not hasattr(obj, 'host'):
        dialog.msgbox(title=title,
                      text='Entity does not contain a host property')
        return

    view = agent.get_list_view(obj.host)
    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:
        dialog.msgbox(title=title,
                      text='No hosts found on this managed entity')
        return

    items = [
        pvc.widget.menu.MenuItem(
            tag=host['name'],
            description=host['runtime.connectionState'],
            on_select=pvc.widget.hostsystem.HostSystemWidget,
            on_select_args=(agent, dialog, host['obj'])) for host in properties
    ]

    menu = pvc.widget.menu.Menu(items=items,
                                dialog=dialog,
                                title=title,
                                text='')

    menu.display()
Esempio n. 55
0
    def display(self):
        items = [
            pvc.widget.menu.MenuItem(tag='Create',
                                     description='Create new datacenter',
                                     on_select=self.create_datacenter),
            pvc.widget.menu.MenuItem(
                tag='View',
                description='View datacenters',
                on_select=pvc.widget.common.datacenter_menu,
                on_select_args=(self.agent, self.dialog)),
        ]

        menu = pvc.widget.menu.Menu(items=items,
                                    dialog=self.dialog,
                                    title='Inventory Datacenter Menu',
                                    text='Select an item from the inventory')

        menu.display()
Esempio n. 56
0
    def display(self):
        items = [
            pvc.widget.menu.MenuItem(tag='Rename',
                                     description='Rename datacenter',
                                     on_select=pvc.widget.common.rename,
                                     on_select_args=(self.obj, self.dialog)),
            pvc.widget.menu.MenuItem(tag='Remove',
                                     description='Remove datacenter',
                                     on_select=pvc.widget.common.remove,
                                     on_select_args=(self.obj, self.dialog)),
        ]

        menu = pvc.widget.menu.Menu(items=items,
                                    dialog=self.dialog,
                                    title=self.title,
                                    text='Select an action to be performed')

        menu.display()
Esempio n. 57
0
def cluster_menu(agent, dialog, folder=None):
    """
    A widget to display a menu of vim.ClusterComputeResource entities

    Args:
        agent     (VConnector): A VConnector instance
        dialog (dialog.Dailog): A Dialog instance
        folder    (vim.Folder): A vim.Folder entity

    """
    dialog.infobox(text='Retrieving information ...')

    if not folder:
        folder = agent.si.content.rootFolder

    view = agent.get_container_view(
        obj_type=[pyVmomi.vim.ClusterComputeResource], container=folder)
    properties = agent.collect_properties(
        view_ref=view,
        obj_type=pyVmomi.vim.ClusterComputeResource,
        path_set=['name', 'overallStatus'],
        include_mors=True)
    view.DestroyView()

    if not properties:
        dialog.msgbox(title='No objects found',
                      text='No cluster managed entities found')
        return

    items = [
        pvc.widget.menu.MenuItem(tag=cluster['name'],
                                 description=cluster['overallStatus'],
                                 on_select=pvc.widget.cluster.ClusterWidget,
                                 on_select_args=(agent, dialog,
                                                 cluster['obj']))
        for cluster in properties
    ]

    menu = pvc.widget.menu.Menu(items=items,
                                dialog=dialog,
                                title='Select Cluster',
                                text='')

    menu.display()
Esempio n. 58
0
    def display(self):
        items = [
            pvc.widget.menu.MenuItem(
                tag='Create',
                description='Create new Virtual Machine',
                on_select=pvc.widget.virtualmachine.CreateVirtualMachineWidget,
                on_select_args=(self.agent, self.dialog, self.obj)),
            pvc.widget.menu.MenuItem(
                tag='View',
                description='Virtual Machines in datacenter',
                on_select=self.virtual_machine_menu),
        ]

        menu = pvc.widget.menu.Menu(items=items,
                                    dialog=self.dialog,
                                    title=self.title,
                                    text='Select an action to be performed')

        menu.display()
Esempio n. 59
0
    def display(self):
        items = [
            pvc.widget.menu.MenuItem(tag='Hosts',
                                     description='Search inventory for hosts',
                                     on_select=InventorySearchHostWidget,
                                     on_select_args=(self.agent, self.dialog)),
            pvc.widget.menu.MenuItem(
                tag='Virtual Machines',
                description='Search inventory for VMs',
                on_select=InventorySearchVirtualMachineWidget,
                on_select_args=(self.agent, self.dialog)),
        ]

        menu = pvc.widget.menu.Menu(items=items,
                                    dialog=self.dialog,
                                    title='Inventory Search',
                                    text='')

        menu.display()