Beispiel #1
0
        def run(self, context, args, kwargs, opargs, filtering=None):
            if len(args) != 0:
                raise CommandException('Wrong arguments count')

            self.parent.load()

            values = Object()
            entity = self.parent.entity

            for mapping in self.parent.property_mappings:
                if not mapping.get:
                    continue

                if mapping.ns:
                    continue

                if mapping.condition is not None:
                    if not mapping.condition(entity):
                        continue

                if mapping.set and mapping.is_usersetable(entity) and self.parent.allow_edit:
                    editable = True
                else:
                    editable = False

                value = Object.Item(
                    mapping.descr,
                    mapping.name,
                    mapping.do_get(entity),
                    mapping.type,
                    editable,
                )
                values.append(value)

            return values
Beispiel #2
0
 def run(self, context, args, kwargs, opargs):
     status_dict = context.call_sync('management.status')
     status_dict['up-since'] = format_value(status_dict['started-at'], vt=ValueType.TIME)
     return Object(
         Object.Item("Number of middleware connections", 'middleware-connections', status_dict['connected-clients']),
         Object.Item("Uptime", 'up-since', status_dict['up-since']),
         Object.Item("Started at", 'started-at', status_dict['started-at'])
     )
Beispiel #3
0
 def run(self, context, args, kwargs, opargs):
     return Object(
         Object.Item(
             'FreeNAS version', 'freenas_version', context.call_sync('system.info.version')
         ),
         Object.Item(
             'System version',
             'system_version',
             ' '.join(context.call_sync('system.info.uname_full'))
         )
     )
Beispiel #4
0
 def run(self, context, args, kwargs, opargs):
     result = context.call_task_sync('backup.query',
                                     self.parent.entity['id'])
     manifest = result['result']
     return Sequence(
         Object(
             Object.Item('Hostname', 'hostname', manifest['hostname']),
             Object.Item('Dataset', 'dataset', manifest['dataset']),
         ),
         Table(manifest['snapshots'], [
             Table.Column('Snapshot name', 'name', ValueType.STRING),
             Table.Column('Incremental', 'incremental', ValueType.BOOLEAN),
             Table.Column('Created at', 'created_at', ValueType.TIME)
         ]))
Beispiel #5
0
    def run(self, context, args, kwargs, opargs):
        guest_info = context.call_sync('vm.get_guest_info', self.parent.entity['id'])
        addresses = []

        for name, config in guest_info['interfaces'].items():
            if name.startswith('lo'):
                continue

            addresses += [i['address'] for i in config['aliases'] if i['af'] != 'LINK']

        return Object(
            Object.Item('Load average', 'load_avg', guest_info['load_avg'], ValueType.ARRAY),
            Object.Item('Network configuration', 'interfaces', addresses, ValueType.SET)
        )
Beispiel #6
0
    def run(self, context, args, kwargs, opargs):
        result = context.call_task_sync('backup.query',
                                        self.parent.entity['id'])
        if result['state'] != 'FINISHED':
            raise CommandException('Failed to query backup: {0}'.format(
                q.get(result, 'error.message')))

        manifest = result['result']
        return Sequence(
            Object(
                Object.Item('Hostname', 'hostname', manifest['hostname']),
                Object.Item('Dataset', 'dataset', manifest['dataset']),
            ),
            Table(manifest['snapshots'], [
                Table.Column('Snapshot name', 'name', ValueType.STRING),
                Table.Column('Incremental', 'incremental', ValueType.BOOLEAN),
                Table.Column('Created at', 'created_at', ValueType.TIME)
            ]))
Beispiel #7
0
        def run(self, context, args, kwargs, opargs, filtering=None):
            if len(args) != 0:
                raise CommandException('Wrong arguments count')

            self.parent.load()

            values = Object()
            entity = self.parent.entity

            for mapping in self.parent.property_mappings:
                if not mapping.get:
                    continue

                if mapping.ns:
                    continue

                if mapping.condition is not None:
                    if not mapping.condition(entity):
                        continue

                if mapping.set and mapping.is_usersetable(
                        entity) and self.parent.allow_edit:
                    editable = True
                else:
                    editable = False

                value = Object.Item(
                    mapping.descr,
                    mapping.name,
                    mapping.do_get(entity),
                    mapping.type,
                    editable,
                )
                values.append(value)

            if self.parent.leaf_entity:
                leaf_res = ListCommand(self.parent).run(
                    context, args, kwargs, opargs, filtering)
                return Sequence(
                    values,
                    "-- {0} --".format(self.parent.leaf_ns.description),
                    leaf_res)
            return values
Beispiel #8
0
    def run(self, context, args, kwargs, opargs):
        namespaces = self.parent.namespaces()
        output_dict = {}
        output = Sequence()
        hw_info_dict = context.call_sync('system.info.hardware')
        parent_commands = self.parent.commands()

        def get_show(obj):
            if isinstance(obj, ConfigNamespace):
                obj.load()
            commands = obj.commands()
            if 'show' in commands:
                instance = commands['show']
                return instance.run(context, '', '', '')
            else:
                raise CommandException(
                    _("Namespace {0} does not have 'show' command".format(
                        obj.name)))

        def append_out(key):
            if key == 'ipmi' or len(output_dict[key]) > 0:
                output.append("\nData about {0}:".format(key))
                output.append(output_dict[key])

        for namespace in namespaces:
            output_dict[namespace.name] = get_show(namespace)
            append_out(namespace.name)

        output_dict['memory'] = Object(
            Object.Item("Memory size",
                        'memory_size',
                        hw_info_dict['memory_size'],
                        vt=ValueType.SIZE))
        output_dict['cpu'] = parent_commands['cpu'].run(context, '', '', '')

        append_out('memory')
        append_out('cpu')

        return output
Beispiel #9
0
    def run(self, context, args, kwargs, opargs):
        cpu_data = context.call_sync('vm.get_hw_vm_capabilities')
        cpu_data.update(context.call_sync('system.info.hardware'))

        return Object(
            Object.Item("CPU Clockrate", 'cpu_clockrate',
                        cpu_data['cpu_clockrate']),
            Object.Item("CPU Model", 'cpu_model', cpu_data['cpu_model']),
            Object.Item("CPU Cores", 'cpu_cores', cpu_data['cpu_cores']),
            Object.Item("VM Guest", 'vm_guest', cpu_data['vm_guest']),
            Object.Item("VTX capabilitie", 'vtx_enabled',
                        cpu_data['vtx_enabled']),
            Object.Item("SVM Featuress", 'svm_features',
                        cpu_data['svm_features']),
            Object.Item("Unrestricted Guest", 'unrestricted_guest',
                        cpu_data['unrestricted_guest']))
Beispiel #10
0
    def run(self, context, args, kwargs, opargs):
        root_namespaces = context.root_ns.namespaces()
        output_dict = {}
        output = Sequence()

        def get_show(obj):
            if isinstance(obj, ConfigNamespace):
                obj.load()
            commands = obj.commands()
            if 'show' in commands:
                instance = commands['show']
                return instance.run(context, '', '', '')
            else:
                raise CommandException(_("Namespace {0} does not have 'show' command".format(obj.name)))

        def append_out(key):
            if len(output_dict[key]) > 0:
                output.append("\nData about {0}:".format(key))
                output.append(output_dict[key])

        for namespace in root_namespaces:
            if namespace.name in ('system', 'service', 'vm', 'disk', 'share', 'volume'):
                output_dict[namespace.name] = get_show(namespace)

            elif namespace.name == 'account':
                for account_nested_namespace in namespace.namespaces():
                    if account_nested_namespace.name == 'directoryservice':
                        for nested_namespace in account_nested_namespace.namespaces():
                            if nested_namespace.name == 'directories':
                                output_dict[nested_namespace.name] = get_show(nested_namespace)
                            if nested_namespace.name == 'kerberos':
                                for kerberos_namespace in nested_namespace.namespaces():
                                    if kerberos_namespace.name == 'keytab' or \
                                                    kerberos_namespace.name == 'realm':
                                        output_dict[kerberos_namespace.name] = get_show(kerberos_namespace)

            elif namespace.name == 'network':
                for nested_namespace in namespace.namespaces():
                    if nested_namespace.name == 'config' or \
                                    nested_namespace.name == 'host' or \
                                    nested_namespace.name == 'interface' or \
                                    nested_namespace.name == 'route':
                        output_dict[nested_namespace.name] = get_show(nested_namespace)
            elif namespace.name == 'boot':
                for nested_namespace in namespace.namespaces():
                    if nested_namespace.name == 'environment':
                        output_dict[nested_namespace.name] = get_show(nested_namespace)

        hw_info_dict = context.call_sync('system.info.hardware')
        output_dict['hardware'] = Object(
            Object.Item("CPU Clockrate", 'cpu_clockrate', hw_info_dict['cpu_clockrate']),
            Object.Item("CPU Model", 'cpu_model', hw_info_dict['cpu_model']),
            Object.Item("CPU Cores", 'cpu_cores', hw_info_dict['cpu_cores']),
            Object.Item("Memory size", 'memory_size', hw_info_dict['memory_size'], vt=ValueType.SIZE),
            Object.Item("VM Guest", 'vm_guest', hw_info_dict['vm_guest'])
        )

        ver_info = context.call_sync('system.info.version')

        output.append("System version: {0}".format(ver_info))
        output.append("\n\nStatus of machine:")
        append_out('system')
        append_out('hardware')
        output.append("\n\nStatus of boot environment:")
        append_out('environment')
        output.append("\n\nStatus of networking:")
        append_out('config')
        append_out('host')
        append_out('interface')
        append_out('route')
        output.append("\n\nStatus of storage:")
        append_out('volume')
        append_out('disk')
        append_out('share')
        if len(output_dict['vm']) > 0:
            output.append("\n\nStatus of VMs:")
            append_out('vm')
        output.append("\n\nStatus of services:")
        append_out('service')
        if len(output_dict['directories']) > 0:
            output.append("\n\nStatus of Active Directory:")
            append_out('directories')
        if len(output_dict['keytab']) > 0 or len(output_dict['realm']) > 0:
            output.append("\n\nStatus of Kerberos:")
            append_out('keytab')
            append_out('realm')

        return output
Beispiel #11
0
 def run(self, context, args, kwargs, opargs):
     t = self.parent.entity
     return Object(
         Object.Item('ID', 'id', t['id']),
         Object.Item('Name', 'name', t['name']),
         Object.Item('State', 'state', t['state']),
         Object.Item('Started at', 'started_at', t['started_at']),
         Object.Item('Started by', 'started_by', t['user']),
         Object.Item('Resources assigned', 'resources', t['resources']),
         Object.Item('Warnings', 'warnings', t['warnings']),
         Object.Item('Error', 'error', t['error']),
         Object.Item('Arguments', 'arguments', t['args']),
         Object.Item('Result', 'result', t['result']),
         Object.Item('Output', 'output', t['output']),
         Object.Item('Resource usage', 'rusage', t['rusage']))