Пример #1
0
    def disconnect_host(self):
        """
        Disconnect host(s) from the cluster

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

        items = [
            pvc.widget.checklist.CheckListItem(tag=h.name, description=h.runtime.connectionState)
            for h in self.obj.host if h.runtime.connectionState == pyVmomi.vim.HostSystemConnectionState.connected
        ]

        if not items:
            self.dialog.msgbox(
                title=self.title,
                text='There are no hosts connected to cluster'
            )
            return

        checklist = pvc.widget.checklist.CheckList(
            items=items,
            dialog=self.dialog,
            title=self.title,
            text='Select host(s) to be disconnected from the cluster'
        )

        checklist.display()
        selected = checklist.selected()

        if not selected:
            return

        text = (
            'The following host(s) will be disconnected from cluster.'
            '\n\n{}\n\n'
            'Disconnect host(s) from cluster?\n'
        )
        code = self.dialog.yesno(
            title=self.title,
            text=text.format('\n'.join(selected))
        )

        if code in (self.dialog.ESC, self.dialog.CANCEL):
            return

        host_objects = [h for h in self.obj.host if h.name in selected]
        for host_obj in host_objects:
            task = host_obj.Disconnect()
            gauge = pvc.widget.gauge.TaskGauge(
                title=self.title,
                text='Disconnecting {} from cluster ...'.format(host_obj.name),
                dialog=self.dialog,
                task=task
            )
            gauge.display()
Пример #2
0
    def display(self):
        self.dialog.infobox(
            title=self.title,
            text='Retrieving information ...'
        )

        if not self.obj.datastore:
            self.dialog.msgbox(
                title=self.title,
                text='There are no datastores mounted on this host'
            )
            return

        items = [
            pvc.widget.checklist.CheckListItem(
                tag=d.name,
                description='Accessible' if d.summary.accessible else 'Not Accessible',
            ) for d in self.obj.datastore
        ]

        checklist = pvc.widget.checklist.CheckList(
            items=items,
            dialog=self.dialog,
            title=self.title,
            text='Select datastore(s) to be unmounted'
        )

        checklist.display()
        selected = checklist.selected()

        if not selected:
            return

        text = (
            'The following datastore(s) will be unmounted.'
            '\n\n{}\n\n'
            'Unmount datastore(s) from host?\n'
        )

        code = self.dialog.yesno(
            title=self.title,
            text=text.format('\n'.join(selected))
        )

        if code in (self.dialog.ESC, self.dialog.CANCEL):
            return

        datastore_objects = [d for d in self.obj.datastore if d.name in selected]
        for datastore_obj in datastore_objects:
            self.dialog.infobox(
                title=self.title,
                text='Unmount datastore {} ...'.format(datastore_obj.name)
            )
            self.obj.configManager.datastoreSystem.RemoveDatastore(
                datastore=datastore_obj
            )
Пример #3
0
    def display(self):
        self.dialog.infobox(title=self.title,
                            text='Retrieving information ...')

        if not self.obj.datastore:
            self.dialog.msgbox(
                title=self.title,
                text='There are no datastores mounted on this host')
            return

        items = [
            pvc.widget.checklist.CheckListItem(
                tag=d.name,
                description='Accessible'
                if d.summary.accessible else 'Not Accessible',
            ) for d in self.obj.datastore
        ]

        checklist = pvc.widget.checklist.CheckList(
            items=items,
            dialog=self.dialog,
            title=self.title,
            text='Select datastore(s) to be unmounted')

        checklist.display()
        selected = checklist.selected()

        if not selected:
            return

        text = ('The following datastore(s) will be unmounted.'
                '\n\n{}\n\n'
                'Unmount datastore(s) from host?\n')

        code = self.dialog.yesno(title=self.title,
                                 text=text.format('\n'.join(selected)))

        if code in (self.dialog.ESC, self.dialog.CANCEL):
            return

        datastore_objects = [
            d for d in self.obj.datastore if d.name in selected
        ]
        for datastore_obj in datastore_objects:
            self.dialog.infobox(title=self.title,
                                text='Unmount datastore {} ...'.format(
                                    datastore_obj.name))
            self.obj.configManager.datastoreSystem.RemoveDatastore(
                datastore=datastore_obj)
Пример #4
0
    def reconnect_host(self):
        """
        Reconnect disconnected hosts to cluster

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

        items = [
            pvc.widget.checklist.CheckListItem(tag=h.name, description=h.runtime.connectionState)
            for h in self.obj.host if h.runtime.connectionState == pyVmomi.vim.HostSystemConnectionState.disconnected
        ]

        if not items:
            self.dialog.msgbox(
                title=self.title,
                text='There are no disconnected hosts in the cluster'
            )
            return

        checklist = pvc.widget.checklist.CheckList(
            items=items,
            dialog=self.dialog,
            title=self.title,
            text='Select host(s) to be reconnected to the cluster'
        )

        checklist.display()
        selected_hosts = checklist.selected()

        if not selected_hosts:
            return

        host_objects = [h for sh in selected_hosts for h in self.obj.host if sh == h.name]
        for host_obj in host_objects:
            task = host_obj.Reconnect()
            gauge = pvc.widget.gauge.TaskGauge(
                title=self.title,
                text='Reconnecting {} to cluster ...'.format(host_obj.name),
                dialog=self.dialog,
                task=task
            )
            gauge.display()
Пример #5
0
    def select_counter_instances(self):
        """
        Prompts the user to select counter instances

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

        if self.realtime:
            provider_summary = self.pm.QueryPerfProviderSummary(
                entity=self.obj
            )
            interval_id = provider_summary.refreshRate
        else:
            interval_id = None

        metric_id = self.pm.QueryAvailablePerfMetric(
            entity=self.obj,
            intervalId=interval_id
        )
        metrics = [m for m in metric_id if m.counterId == self.counter.key]
        instances = [m.instance if m.instance else self.obj.name for m in metrics]
        items = [
            pvc.widget.checklist.CheckListItem(tag=instance)
            for instance in instances
        ]
        checklist_text = 'Select instances for counter {0}.{1}.{2}'.format(
            self.counter.groupInfo.key,
            self.counter.nameInfo.key,
            self.counter.unitInfo.key
        )

        checklist = pvc.widget.checklist.CheckList(
            items=items,
            dialog=self.dialog,
            title=self.title,
            text=checklist_text,
        )
        checklist.display()

        return checklist.selected()
Пример #6
0
    def select_counter_instances(self):
        """
        Prompts the user to select counter instances

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

        if self.realtime:
            provider_summary = self.pm.QueryPerfProviderSummary(
                entity=self.obj)
            interval_id = provider_summary.refreshRate
        else:
            interval_id = None

        metric_id = self.pm.QueryAvailablePerfMetric(entity=self.obj,
                                                     intervalId=interval_id)
        metrics = [m for m in metric_id if m.counterId == self.counter.key]
        instances = [
            m.instance if m.instance else self.obj.name for m in metrics
        ]
        items = [
            pvc.widget.checklist.CheckListItem(tag=instance)
            for instance in instances
        ]
        checklist_text = 'Select instances for counter {0}.{1}.{2}'.format(
            self.counter.groupInfo.key, self.counter.nameInfo.key,
            self.counter.unitInfo.key)

        checklist = pvc.widget.checklist.CheckList(
            items=items,
            dialog=self.dialog,
            title=self.title,
            text=checklist_text,
        )
        checklist.display()

        return checklist.selected()