Example #1
0
    def show(cls, args, lstmsg):
        tbl = linstor_client.Table(utf8=not args.no_utf8, colors=not args.no_color, pastable=args.pastable)
        tbl.add_column("ResourceName")
        tbl.add_column("SnapshotName")
        tbl.add_column("NodeNames")
        tbl.add_column("Volumes")
        tbl.add_column("State", color=Output.color(Color.DARKGREEN, args.no_color))
        for snapshot_dfn in lstmsg.snapshot_dfns:
            if FLAG_DELETE in snapshot_dfn.snapshot_dfn_flags:
                state_cell = tbl.color_cell("DELETING", Color.RED)
            elif FLAG_FAILED_DEPLOYMENT in snapshot_dfn.snapshot_dfn_flags:
                state_cell = tbl.color_cell("Failed", Color.RED)
            elif FLAG_FAILED_DISCONNECT in snapshot_dfn.snapshot_dfn_flags:
                state_cell = tbl.color_cell("Satellite disconnected", Color.RED)
            elif FLAG_SUCCESSFUL in snapshot_dfn.snapshot_dfn_flags:
                state_cell = tbl.color_cell("Successful", Color.DARKGREEN)
            else:
                state_cell = tbl.color_cell("Incomplete", Color.DARKBLUE)

            tbl.add_row([
                snapshot_dfn.rsc_name,
                snapshot_dfn.snapshot_name,
                ", ".join([snapshot.node_name for snapshot in snapshot_dfn.snapshots]),
                ", ".join([
                    str(snapshot_vlm_dfn.vlm_nr) + ": " + SizeCalc.approximate_size_string(snapshot_vlm_dfn.vlm_size)
                    for snapshot_vlm_dfn in snapshot_dfn.snapshot_vlm_dfns]),
                state_cell
            ])
        tbl.show()
Example #2
0
    def show_volumes(cls, args, lstmsg):
        tbl = linstor_client.Table(utf8=not args.no_utf8,
                                   colors=not args.no_color,
                                   pastable=args.pastable)
        tbl.add_column("Node")
        tbl.add_column("Resource")
        tbl.add_column("StoragePool")
        tbl.add_column("VolumeNr")
        tbl.add_column("MinorNr")
        tbl.add_column("DeviceName")
        tbl.add_column("State",
                       color=Output.color(Color.DARKGREEN, args.no_color),
                       just_txt='>')

        for rsc in lstmsg.resources:
            rsc_state = ResourceCommands.get_resource_state(
                lstmsg.resource_states, rsc.node_name, rsc.name)
            for vlm in rsc.vlms:
                vlm_state = ResourceCommands.get_volume_state(
                    rsc_state.vlm_states, vlm.vlm_nr) if rsc_state else None
                state_txt, color = cls.volume_state_cell(
                    vlm_state, rsc.rsc_flags, vlm.vlm_flags)
                state = tbl.color_cell(state_txt,
                                       color) if color else state_txt
                tbl.add_row([
                    rsc.node_name, rsc.name, vlm.stor_pool_name,
                    str(vlm.vlm_nr),
                    str(vlm.vlm_minor_nr), vlm.device_path, state
                ])

        tbl.show()
Example #3
0
    def show(self, args, lstmsg):
        tbl = linstor_client.Table(utf8=not args.no_utf8, colors=not args.no_color, pastable=args.pastable)
        for hdr in self._stor_pool_headers:
            tbl.add_header(hdr)

        tbl.set_groupby(args.groupby if args.groupby else [self._stor_pool_headers[0].name])

        for storpool in lstmsg.stor_pools:
            driver_device = self._linstor.storage_props_to_driver_pool(storpool.driver[:-len('Driver')], storpool.props)

            supports_snapshots_prop = [x for x in storpool.static_traits if x.key == KEY_STOR_POOL_SUPPORTS_SNAPSHOTS]
            supports_snapshots = supports_snapshots_prop[0].value if supports_snapshots_prop else ''

            provisioning_prop = [x for x in storpool.static_traits if x.key == KEY_STOR_POOL_PROVISIONING]
            provisioning = provisioning_prop[0].value if provisioning_prop else ''

            freespace = ""
            if provisioning == VAL_STOR_POOL_PROVISIONING_THIN:
                freespace = "(thin)"
            elif storpool.driver != 'DisklessDriver' and storpool.HasField("free_space"):
                freespace = SizeCalc.approximate_size_string(storpool.free_space.free_space)

            tbl.add_row([
                storpool.stor_pool_name,
                storpool.node_name,
                storpool.driver,
                driver_device,
                freespace,
                supports_snapshots
            ])
        tbl.show()
Example #4
0
    def _print_props(cls, prop_list_map, args):
        """Print properties in machine or human readable format"""

        if args.machine_readable:
            s = ''
            if prop_list_map:
                d = [[{"key": x, "value": prop_list_map[0][x]} for x in prop_list_map[0]]]
                s = json.dumps(d, indent=2)
            print(s)
            return None

        property_map_count = len(prop_list_map)
        if property_map_count == 0:
            print(Output.color_str("No property map found for this entry.", Color.YELLOW, args.no_color))
            return None

        tbl = linstor_client.Table(utf8=not args.no_utf8, colors=not args.no_color, pastable=args.pastable)
        tbl.add_column("Key")
        tbl.add_column("Value")

        if property_map_count > 0:
            prop_map = prop_list_map[0]
            for p in sorted(prop_map.keys()):
                tbl.add_row([p, prop_map[p]])

        tbl.show()

        if property_map_count > 1:
            print(Output.color_str("Unexpected additional property data, ignoring.", Color.YELLOW, args.no_color))
Example #5
0
    def show(cls, args, lstmsg):
        tbl = linstor_client.Table(utf8=not args.no_utf8, colors=not args.no_color, pastable=args.pastable)

        vlm_dfn_hdrs = list(cls._vlm_dfn_headers)
        if args.external_name:
            vlm_dfn_hdrs.insert(1, linstor_client.TableHeader("External"))
        for hdr in vlm_dfn_hdrs:
            tbl.add_header(hdr)

        tbl.set_groupby(args.groupby if args.groupby else [tbl.header_name(0)])
        for rsc_dfn in lstmsg.resource_definitions:
            for vlmdfn in rsc_dfn.volume_definitions:
                state = tbl.color_cell("ok", Color.DARKGREEN)
                if FLAG_DELETE in vlmdfn.flags:
                    state = tbl.color_cell("DELETING", Color.RED)
                elif FLAG_RESIZE in vlmdfn.flags:
                    state = tbl.color_cell("resizing", Color.DARKPINK)

                drbd_data = vlmdfn.drbd_data
                tbl.add_row([
                    rsc_dfn.name,
                    vlmdfn.number,
                    drbd_data.minor if drbd_data else "",
                    SizeCalc.approximate_size_string(vlmdfn.size),
                    "+" if FLAG_GROSS_SIZE in vlmdfn.flags else "",
                    state
                ])
        tbl.show()
Example #6
0
    def show(cls, args, lstmsg):
        tbl = linstor_client.Table(utf8=not args.no_utf8,
                                   colors=not args.no_color,
                                   pastable=args.pastable)

        rsc_dfn_hdr = list(cls._rsc_dfn_headers)

        if args.external_name:
            rsc_dfn_hdr.insert(1, linstor_client.TableHeader("External"))

        for hdr in rsc_dfn_hdr:
            tbl.add_header(hdr)

        tbl.set_groupby(args.groupby if args.groupby else [tbl.header_name(0)])

        for rsc_dfn in lstmsg.resource_definitions:
            drbd_data = rsc_dfn.drbd_data
            row = [rsc_dfn.name]
            if args.external_name and isinstance(rsc_dfn.external_name, str):
                row.append(rsc_dfn.external_name)
            row.append(drbd_data.port if drbd_data else "")
            row.append(rsc_dfn.resource_group_name)
            row.append(
                tbl.color_cell("DELETING", Color.RED) if FLAG_DELETE in
                rsc_dfn.flags else tbl.color_cell("ok", Color.DARKGREEN))
            tbl.add_row(row)
        tbl.show()
Example #7
0
    def show_enclosures(cls, args, list_msg):
        tbl = linstor_client.Table(utf8=not args.no_utf8,
                                   colors=not args.no_color,
                                   pastable=args.pastable)

        header = list(cls._exos_enclosure_headers)
        for hdr in header:
            tbl.add_header(hdr)

        tbl.set_groupby([tbl.header_name(0)])

        health_colors_dict = {"OK": Color.GREEN}

        for encl in list_msg.exos_enclosures:
            if encl.health in health_colors_dict:
                health_color = health_colors_dict[encl.health]
            else:
                health_color = Color.RED

            row = [
                encl.name, encl.ctrl_a_ip if encl.ctrl_a_ip else "-",
                encl.ctrl_b_ip if encl.ctrl_b_ip else "-",
                tbl.color_cell(encl.health, health_color),
                encl.health_reason if encl.health_reason else ""
            ]
            tbl.add_row(row)
        tbl.show()
Example #8
0
    def show_nodes(cls, args, lstmsg):
        tbl = linstor_client.Table(utf8=not args.no_utf8,
                                   colors=not args.no_color,
                                   pastable=args.pastable)
        for hdr in cls._node_headers:
            tbl.add_header(hdr)

        conn_stat_dict = {
            apiconsts.CONN_STATUS_OFFLINE: ("OFFLINE", Color.RED),
            apiconsts.CONN_STATUS_CONNECTED: ("Connected", Color.YELLOW),
            apiconsts.CONN_STATUS_ONLINE: ("Online", Color.GREEN),
            apiconsts.CONN_STATUS_VERSION_MISMATCH:
            ("OFFLINE(VERSION MISMATCH)", Color.RED),
            apiconsts.CONN_STATUS_FULL_SYNC_FAILED:
            ("OFFLINE(FULL SYNC FAILED)", Color.RED),
            apiconsts.CONN_STATUS_AUTHENTICATION_ERROR:
            ("OFFLINE(AUTHENTICATION ERROR)", Color.RED),
            apiconsts.CONN_STATUS_UNKNOWN: ("Unknown", Color.YELLOW)
        }

        tbl.set_groupby(args.groupby if args.groupby else [tbl.header_name(0)])

        node_list = [x for x in lstmsg.nodes
                     if x.name in args.nodes] if args.nodes else lstmsg.nodes
        for n in node_list:
            ips = [if_.address for if_ in n.net_interfaces]
            conn_stat = conn_stat_dict[n.connection_status]
            tbl.add_row([
                n.name, n.type, ",".join(ips),
                tbl.color_cell(conn_stat[0], conn_stat[1])
            ])
        tbl.show()
Example #9
0
    def _show_query_max_volume(cls, args, lstmsg):
        tbl = linstor_client.Table(utf8=not args.no_utf8, colors=not args.no_color, pastable=args.pastable)
        tbl.add_column("StoragePool")
        tbl.add_column("MaxVolumeSize", just_txt='>')
        tbl.add_column("Nodes")

        def limited_string(obj_list):
            limit = 40
            s = ""
            list_length = len(obj_list)
            for i in range(0, len(obj_list)):
                obj = obj_list[i]
                s += obj + (", " if i != list_length - 1 else "")
                if len(s) > limit:
                    s = s[:limit-3] + "..."

            return s

        for candidate in lstmsg.candidates:
            if candidate.all_thin:
                max_vlm_size = "(thin)"
            else:
                max_vlm_size = SizeCalc.approximate_size_string(candidate.max_vlm_size)

            tbl.add_row([
                candidate.stor_pool_name,
                max_vlm_size,
                limited_string(candidate.node_names)
            ])
        tbl.show()
Example #10
0
 def show(cls, args, lstmsg):
     tbl = linstor_client.Table(utf8=not args.no_utf8,
                                colors=not args.no_color,
                                pastable=args.pastable)
     tbl.add_column("StoragePool")
     for storpool_dfn in lstmsg.storage_pool_definitions:
         tbl.add_row([storpool_dfn.name])
     tbl.show()
Example #11
0
    def _show_query_max_volume(self, args, lstmsg):
        """
        DEPRECATED will be removed
        :param args:
        :param lstmsg:
        :return:
        """
        print(
            Output.color_str("DEPRECATED:", Color.YELLOW, args.no_color) +
            " use `linstor controller query-max-volume-size`")
        tbl = linstor_client.Table(utf8=not args.no_utf8,
                                   colors=not args.no_color,
                                   pastable=args.pastable)
        tbl.add_column("StoragePool")
        tbl.add_column("MaxVolumeSize", just_txt='>')
        tbl.add_column("Provisioning")
        tbl.add_column("Nodes")

        def limited_string(obj_list):
            limit = 40
            s = ""
            list_length = len(obj_list)
            for i in range(0, len(obj_list)):
                obj = obj_list[i]
                s += obj + (", " if i != list_length - 1 else "")
                if len(s) > limit:
                    s = s[:limit - 3] + "..."

            return s

        storage_pool_dfns = self.get_linstorapi().storage_pool_dfn_list(
        )[0].storage_pool_definitions

        for candidate in lstmsg.candidates:
            max_vlm_size = SizeCalc.approximate_size_string(
                candidate.max_volume_size)

            storage_pool_props = [
                x for x in storage_pool_dfns
                if x.name == candidate.storage_pool
            ][0].properties
            max_oversubscription_ratio_props = \
                [x for x in storage_pool_props if x.key == KEY_STOR_POOL_DFN_MAX_OVERSUBSCRIPTION_RATIO]
            max_oversubscription_ratio_prop = max_oversubscription_ratio_props[0].value \
                if max_oversubscription_ratio_props \
                else lstmsg.default_max_oversubscription_ratio
            max_oversubscription_ratio = float(max_oversubscription_ratio_prop)

            tbl.add_row([
                candidate.storage_pool, max_vlm_size,
                "Thin, oversubscription ratio " +
                str(max_oversubscription_ratio)
                if candidate.all_thin else "Thick",
                limited_string(candidate.node_names)
            ])
        tbl.show()
Example #12
0
    def show_table(self, args, lstmsg):
        tbl = linstor_client.Table(utf8=not args.no_utf8,
                                   colors=not args.no_color,
                                   pastable=args.pastable)
        for hdr in FileCommands._file_headers:
            tbl.add_header(hdr)

        for file in lstmsg.files:
            tbl.add_row([file.path])

        tbl.show()
Example #13
0
    def show(cls, args, lstmsg):
        tbl = linstor_client.Table(utf8=not args.no_utf8,
                                   colors=not args.no_color,
                                   pastable=args.pastable)
        tbl.add_column("ResourceName")
        tbl.add_column("SnapshotName")
        tbl.add_column("NodeNames")
        tbl.add_column("Volumes")
        tbl.add_column("CreatedOn")
        tbl.add_column("State",
                       color=Output.color(Color.DARKGREEN, args.no_color))
        for snapshot_dfn in lstmsg.snapshots:
            if FLAG_DELETE in snapshot_dfn.flags:
                state_cell = tbl.color_cell("DELETING", Color.RED)
            elif FLAG_FAILED_DEPLOYMENT in snapshot_dfn.flags:
                state_cell = tbl.color_cell("Failed", Color.RED)
            elif FLAG_FAILED_DISCONNECT in snapshot_dfn.flags:
                state_cell = tbl.color_cell("Satellite disconnected",
                                            Color.RED)
            elif FLAG_SUCCESSFUL in snapshot_dfn.flags:
                in_backup_restore = False
                in_backup_create = False
                if FLAG_BACKUP in snapshot_dfn.flags and FLAG_SHIPPING in snapshot_dfn.flags:
                    for snap in snapshot_dfn.snapshots:
                        in_backup_create |= FLAG_BACKUP_SOURCE in snap.flags
                        in_backup_restore |= FLAG_BACKUP_TARGET in snap.flags
                if in_backup_create:
                    state_cell = tbl.color_cell("Shipping", Color.YELLOW)
                elif in_backup_restore:
                    state_cell = tbl.color_cell("Restoring", Color.YELLOW)
                else:
                    state_cell = tbl.color_cell("Successful", Color.DARKGREEN)
            else:
                state_cell = tbl.color_cell("Incomplete", Color.DARKBLUE)

            snapshot_date = ""
            if snapshot_dfn.snapshots and snapshot_dfn.snapshots[
                    0].create_datetime:
                snapshot_date = str(
                    snapshot_dfn.snapshots[0].create_datetime)[:19]

            tbl.add_row([
                snapshot_dfn.resource_name, snapshot_dfn.name,
                ", ".join([node_name for node_name in snapshot_dfn.nodes]),
                ", ".join([
                    str(snapshot_vlm_dfn.number) + ": " +
                    SizeCalc.approximate_size_string(snapshot_vlm_dfn.size)
                    for snapshot_vlm_dfn in
                    snapshot_dfn.snapshot_volume_definitions
                ]), snapshot_date, state_cell
            ])
        tbl.show()
Example #14
0
    def maintenance(self, args):
        state = self._state_of_the_world()

        found_issues = []

        rsc_to_check = args.resources or state.resource_definitions.keys()
        for rsc_name in rsc_to_check:
            if (args.node, rsc_name) not in state.resources:
                # Resource not deployed on node
                continue

            diskfull_nodes = [
                node for (node, name), rsc in state.resources.items() if
                name == rsc_name and apiconsts.FLAG_DISKLESS not in rsc.flags
            ]
            if diskfull_nodes == [args.node]:
                found_issues.append(
                    _Issue(resource=rsc_name,
                           what=_Issue.WHAT_SINGLE_REPLICA,
                           fix=_Issue.FIX_AUTOPLACE.format(rsc=rsc_name,
                                                           count=2)))
                continue

            all_deployed = [
                node for (node, name), rsc in state.resources.items()
                if name == rsc_name
            ]

            if len(all_deployed) < 3:
                # TODO: include quorum information: if explicit quorum is set, this advise is likely wrong
                # Also, in case the node to check is diskless, we may need to advise to add another diskfull replica.
                found_issues.append(
                    _Issue(
                        resource=rsc_name,
                        what=_Issue.WHAT_POTENTIAL_SPLIT_BRAIN,
                        fix=_Issue.FIX_AUTOPLACE_TIEBREAKER.format(
                            rsc=rsc_name),
                    ))

        if args.machine_readable:
            json.dump([issue.__dict__ for issue in found_issues], sys.stdout)
        else:
            tbl = linstor_client.Table(utf8=not args.no_utf8,
                                       colors=not args.no_color,
                                       pastable=args.pastable)
            tbl.add_headers(AdviceCommands._issue_headers)

            for issue in found_issues:
                tbl.add_row([issue.resource, issue.what, issue.fix])
            tbl.show()
Example #15
0
    def show(cls, args, lstmsg):
        tbl = linstor_client.Table(utf8=not args.no_utf8, colors=not args.no_color, pastable=args.pastable)
        for hdr in cls._rsc_dfn_headers:
            tbl.add_header(hdr)

        tbl.set_groupby(args.groupby if args.groupby else [tbl.header_name(0)])
        for rsc_dfn in cls.filter_rsc_dfn_list(lstmsg.rsc_dfns, args.resources):
            tbl.add_row([
                rsc_dfn.rsc_name,
                rsc_dfn.rsc_dfn_port,
                tbl.color_cell("DELETING", Color.RED)
                if FLAG_DELETE in rsc_dfn.rsc_dfn_flags else tbl.color_cell("ok", Color.DARKGREEN)
            ])
        tbl.show()
Example #16
0
    def show(cls, args, lstmsg):
        vlm_grps = lstmsg  # type: linstor.responses.VolumeGroupResponse
        tbl = linstor_client.Table(utf8=not args.no_utf8,
                                   colors=not args.no_color,
                                   pastable=args.pastable)

        for hdr in cls._vlm_grp_headers:
            tbl.add_header(hdr)

        tbl.set_groupby(args.groupby if args.groupby else [tbl.header_name(0)])

        for vlm_grp in vlm_grps.volume_groups:
            row = [str(vlm_grp.number)]
            tbl.add_row(row)
        tbl.show()
Example #17
0
    def show_nodes(cls, args, lstmsg):
        tbl = linstor_client.Table(utf8=not args.no_utf8, colors=not args.no_color, pastable=args.pastable)

        node_hdr = list(cls._node_headers)
        if args.show_aux_props:
            node_hdr.insert(-1, linstor_client.TableHeader("AuxProps"))

        for hdr in node_hdr:
            tbl.add_header(hdr)

        conn_stat_dict = {
            apiconsts.ConnectionStatus.OFFLINE.name: ("OFFLINE", Color.RED),
            apiconsts.ConnectionStatus.CONNECTED.name: ("Connected", Color.YELLOW),
            apiconsts.ConnectionStatus.ONLINE.name: ("Online", Color.GREEN),
            apiconsts.ConnectionStatus.VERSION_MISMATCH.name: ("OFFLINE(VERSION MISMATCH)", Color.RED),
            apiconsts.ConnectionStatus.FULL_SYNC_FAILED.name: ("OFFLINE(FULL SYNC FAILED)", Color.RED),
            apiconsts.ConnectionStatus.AUTHENTICATION_ERROR.name: ("OFFLINE(AUTHENTICATION ERROR)", Color.RED),
            apiconsts.ConnectionStatus.UNKNOWN.name: ("Unknown", Color.YELLOW),
            apiconsts.ConnectionStatus.HOSTNAME_MISMATCH.name: ("OFFLINE(HOSTNAME MISMATCH)", Color.RED),
            apiconsts.ConnectionStatus.OTHER_CONTROLLER.name: ("OFFLINE(OTHER_CONTROLLER)", Color.RED),
            apiconsts.ConnectionStatus.NO_STLT_CONN.name: ("OFFLINE(NO CONNECTION TO SATELLITE)", Color.RED)
        }

        tbl.set_groupby(args.groupby if args.groupby else [tbl.header_name(0)])

        for node in lstmsg.nodes:
            # concat a ip list with satellite connection indicator
            active_ip = ""
            for net_if in node.net_interfaces:
                if net_if.is_active and net_if.stlt_port:
                    active_ip = net_if.address + ":" + str(net_if.stlt_port) + " (" + net_if.stlt_encryption_type + ")"

            aux_props = ["{k}={v}".format(k=k, v=v)
                         for k, v in node.properties.items() if k.startswith(apiconsts.NAMESPC_AUXILIARY + '/')]

            if apiconsts.FLAG_EVICTED in node.flags:
                conn_stat = (apiconsts.FLAG_EVICTED, Color.RED)
            elif apiconsts.FLAG_DELETE in node.flags:
                conn_stat = (apiconsts.FLAG_DELETE, Color.RED)
            else:
                conn_stat = conn_stat_dict.get(node.connection_status)

            row = [node.name, node.type, active_ip]
            if args.show_aux_props:
                row.append("\n".join(aux_props))
            row += [tbl.color_cell(conn_stat[0], conn_stat[1])]
            tbl.add_row(row)
        tbl.show()
Example #18
0
    def _print_props(cls, prop_list_map, args):
        """Print properties in machine or human readable format"""

        if args.machine_readable:
            d = [[protobuf_to_dict(y) for y in x] for x in prop_list_map]
            s = json.dumps(d, indent=2)
            print(s)
            return None

        for prop_map in prop_list_map:
            tbl = linstor_client.Table(utf8=not args.no_utf8, colors=not args.no_color, pastable=args.pastable)
            tbl.add_column("Key")
            tbl.add_column("Value")
            for p in prop_map:
                tbl.add_row([p.key, p.value])
            tbl.show()
Example #19
0
 def show_netinterfaces(cls, args, lstnodes):
     node = NodeCommands.find_node(lstnodes, args.node_name)
     if node:
         tbl = linstor_client.Table(utf8=not args.no_utf8,
                                    colors=not args.no_color,
                                    pastable=args.pastable)
         tbl.add_column(node.name, color=Color.GREEN)
         tbl.add_column("NetInterface")
         tbl.add_column("IP")
         for netif in node.net_interfaces:
             tbl.add_row(["+", netif.name, netif.address])
         tbl.show()
     else:
         raise LinstorClientError(
             "Node '{n}' not found on controller.".format(n=args.node_name),
             ExitCode.OBJECT_NOT_FOUND)
Example #20
0
    def show_error_report_list(self, args, lstmsg):
        tbl = linstor_client.Table(utf8=not args.no_utf8, colors=not args.no_color, pastable=args.pastable)
        tbl.add_header(linstor_client.TableHeader("Nr.", alignment_text=">"))
        tbl.add_header(linstor_client.TableHeader("Id"))
        tbl.add_header(linstor_client.TableHeader("Datetime"))
        tbl.add_header(linstor_client.TableHeader("Node"))

        i = 1
        for error in lstmsg:
            tbl.add_row([
                str(i),
                error.id,
                str(error.datetime)[:19],
                error.node_names
            ])
            i += 1
        tbl.show()
Example #21
0
    def show_exos_dflts(cls, args, exos_dflts):
        tbl = linstor_client.Table(utf8=not args.no_utf8,
                                   colors=not args.no_color,
                                   pastable=args.pastable)

        header = list(cls._exos_defaults_headers)
        for hdr in header:
            tbl.add_header(hdr)

        # tbl.set_groupby([tbl.header_name(0)])

        tbl.add_row(cls._get_row("Username", exos_dflts.username))
        tbl.add_row(cls._get_row("UsernameEnv", exos_dflts.username_env))
        tbl.add_row(cls._get_row("Password", exos_dflts.password))
        tbl.add_row(cls._get_row("PasswordEnv", exos_dflts.password_env))

        tbl.show()
Example #22
0
    def _show_query_max_volume(self, args, lstmsg):
        tbl = linstor_client.Table(utf8=not args.no_utf8,
                                   colors=not args.no_color,
                                   pastable=args.pastable)
        tbl.add_column("StoragePool")
        tbl.add_column("MaxVolumeSize", just_txt='>')
        tbl.add_column("Provisioning")
        tbl.add_column("Nodes")

        def limited_string(obj_list):
            limit = 40
            s = ""
            list_length = len(obj_list)
            for i in range(0, len(obj_list)):
                obj = obj_list[i]
                s += obj + (", " if i != list_length - 1 else "")
                if len(s) > limit:
                    s = s[:limit - 3] + "..."

            return s

        storage_pool_dfns = self.get_linstorapi().storage_pool_dfn_list(
        )[0].storage_pool_definitions

        for candidate in lstmsg.candidates:
            max_vlm_size = SizeCalc.approximate_size_string(
                candidate.max_volume_size)

            storage_pool_props = [
                x for x in storage_pool_dfns
                if x.name == candidate.storage_pool
            ][0].properties
            max_oversubscription_ratio = float(
                storage_pool_props.get(
                    KEY_STOR_POOL_DFN_MAX_OVERSUBSCRIPTION_RATIO,
                    lstmsg.default_max_oversubscription_ratio))

            tbl.add_row([
                candidate.storage_pool, max_vlm_size,
                "Thin, oversubscription ratio " +
                str(max_oversubscription_ratio)
                if candidate.all_thin else "Thick",
                limited_string(candidate.node_names)
            ])
        tbl.show()
Example #23
0
    def show_map(cls, args, list_msg):
        tbl = linstor_client.Table(utf8=not args.no_utf8,
                                   colors=not args.no_color,
                                   pastable=args.pastable)

        header = list(cls._exos_map_headers)
        for hdr in header:
            tbl.add_header(hdr)

        tbl.set_groupby([tbl.header_name(0)])

        for con_map in list_msg.exos_connections:
            row = [
                con_map.node_name, con_map.enclosure_name,
                ", ".join(con_map.connections)
            ]
            tbl.add_row(row)
        tbl.show()
Example #24
0
    def show(self, args, lstmsg):
        tbl = linstor_client.Table(utf8=not args.no_utf8,
                                   colors=not args.no_color,
                                   pastable=args.pastable)
        for hdr in self._stor_pool_headers:
            tbl.add_header(hdr)

        storage_pool_resp = lstmsg  # type: StoragePoolListResponse

        tbl.set_groupby(args.groupby if args.
                        groupby else [self._stor_pool_headers[0].name])

        errors = []
        for storpool in storage_pool_resp.storage_pools:
            driver_device = linstor.StoragePoolDriver.storage_props_to_driver_pool(
                storpool.provider_kind, storpool.properties)

            free_capacity = ""
            total_capacity = ""
            if not storpool.is_diskless() and storpool.free_space is not None:
                free_capacity = SizeCalc.approximate_size_string(
                    storpool.free_space.free_capacity)
                total_capacity = SizeCalc.approximate_size_string(
                    storpool.free_space.total_capacity)

            for error in storpool.reports:
                if error not in errors:
                    errors.append(error)

            state_str, state_color = self.get_replies_state(storpool.reports)
            tbl.add_row([
                storpool.name, storpool.node_name, storpool.provider_kind,
                driver_device, free_capacity, total_capacity,
                storpool.supports_snapshots(),
                tbl.color_cell(state_str,
                               state_color), storpool.free_space_mgr_name
                if ':' not in storpool.free_space_mgr_name else ''
            ])
        tbl.show()
        for err in errors:
            Output.handle_ret(err,
                              warn_as_error=args.warn_as_error,
                              no_color=args.no_color)
Example #25
0
    def show(self, args, lstmsg):
        rsc_dfns = self._linstor.resource_dfn_list()
        if isinstance(rsc_dfns[0], linstor.ApiCallResponse):
            return self.handle_replies(args, rsc_dfns)
        rsc_dfns = rsc_dfns[0].proto_msg.rsc_dfns

        rsc_dfn_map = {x.rsc_name: x for x in rsc_dfns}

        tbl = linstor_client.Table(utf8=not args.no_utf8,
                                   colors=not args.no_color,
                                   pastable=args.pastable)
        for hdr in ResourceCommands._resource_headers:
            tbl.add_header(hdr)

        tbl.set_groupby(args.groupby if args.groupby else
                        [ResourceCommands._resource_headers[0].name])

        for rsc in lstmsg.resources:
            rsc_dfn = rsc_dfn_map[rsc.name]
            marked_delete = apiconsts.FLAG_DELETE in rsc.rsc_flags
            rsc_state_proto = ResourceCommands.find_rsc_state(
                lstmsg.resource_states, rsc.name, rsc.node_name)
            rsc_state = tbl.color_cell("Unknown", Color.YELLOW)
            if marked_delete:
                rsc_state = tbl.color_cell("DELETING", Color.RED)
            elif rsc_state_proto:
                if rsc_state_proto.HasField(
                        'in_use') and rsc_state_proto.in_use:
                    rsc_state = tbl.color_cell("InUse", Color.GREEN)
                else:
                    for vlm in rsc.vlms:
                        vlm_state = ResourceCommands.get_volume_state(
                            rsc_state_proto.vlm_states,
                            vlm.vlm_nr) if rsc_state_proto else None
                        state_txt, color = self.volume_state_cell(
                            vlm_state, rsc.rsc_flags, vlm.vlm_flags)
                        rsc_state = tbl.color_cell(state_txt, color)
                        if color is not None:
                            break
            tbl.add_row(
                [rsc.name, rsc.node_name, rsc_dfn.rsc_dfn_port, rsc_state])
        tbl.show()
    def show(self, args, lstmsg):
        tbl = linstor_client.Table(utf8=not args.no_utf8, colors=not args.no_color, pastable=args.pastable)

        for hdr in self._rsc_grp_headers:
            tbl.add_header(hdr)

        rsc_grps = lstmsg  # type: ResourceGroupResponse

        tbl.set_groupby(args.groupby if args.groupby else [tbl.header_name(0)])

        for rsc_grp in rsc_grps.resource_groups:
            vlm_grps = self.get_linstorapi().volume_group_list_raise(rsc_grp.name).volume_groups
            row = [
                rsc_grp.name,
                str(rsc_grp.select_filter),
                ",".join([str(x.number) for x in vlm_grps]),
                rsc_grp.description
            ]
            tbl.add_row(row)
        tbl.show()
Example #27
0
    def show_ship_list(self, args, shipping_resp):
        """

        :param args:
        :param shipping_resp: ShippingResponse
        :return:
        """
        tbl = linstor_client.Table(utf8=not args.no_utf8,
                                   colors=not args.no_color,
                                   pastable=args.pastable)
        tbl.add_headers(self._shipping_headers)
        for shipping in shipping_resp.shippings:
            tbl.add_row([
                shipping.snapshot_dfn.resource_name,
                shipping.snapshot_dfn.snapshot_name, shipping.from_node_name,
                shipping.to_node_name,
                tbl.color_cell(
                    shipping.status.value, None if shipping.status
                    == consts.SnapshotShipStatus.COMPLETE else Color.YELLOW)
            ])
        tbl.show()
Example #28
0
    def resource(self, args):
        state = self._state_of_the_world()

        found_issues = []
        rsc_to_check = args.resources or state.resource_definitions.keys()

        for rsc_name in rsc_to_check:
            r_def = state.resource_definitions[rsc_name]
            rg = state.resource_groups[r_def.resource_group_name
                                       or "DfltRscGrp"]
            r_deployed = {
                node: r
                for (node, name), r in state.resources.items()
                if name == rsc_name
            }
            r_states = {
                node: r
                for (node, name), r in state.resource_states.items()
                if name == rsc_name
            }

            found_issues.extend(
                _check_needless_diskless(r_def, r_deployed, r_states, rg,
                                         state.storage_pools))
            found_issues.extend(
                _check_expected_replicas(r_def, r_deployed, r_states, rg,
                                         state.storage_pools))

        if args.machine_readable:
            json.dump([issue.__dict__ for issue in found_issues], sys.stdout)
        else:
            tbl = linstor_client.Table(utf8=not args.no_utf8,
                                       colors=not args.no_color,
                                       pastable=args.pastable)
            tbl.add_headers(AdviceCommands._issue_headers)

            for issue in found_issues:
                tbl.add_row([issue.resource, issue.what, issue.fix])
            tbl.show()
Example #29
0
    def show(cls, args, lstmsg):
        tbl = linstor_client.Table(utf8=not args.no_utf8,
                                   colors=not args.no_color,
                                   pastable=args.pastable)
        for hdr in cls._vlm_dfn_headers:
            tbl.add_header(hdr)

        tbl.set_groupby(args.groupby if args.groupby else [tbl.header_name(0)])
        for rsc_dfn in cls.filter_rsc_dfn_list(lstmsg.rsc_dfns,
                                               args.resources):
            for vlmdfn in rsc_dfn.vlm_dfns:
                state = tbl.color_cell("ok", Color.DARKGREEN)
                if FLAG_DELETE in rsc_dfn.rsc_dfn_flags:
                    state = tbl.color_cell("DELETING", Color.RED)
                elif FLAG_RESIZE in vlmdfn.vlm_flags:
                    state = tbl.color_cell("resizing", Color.DARKPINK)

                tbl.add_row([
                    rsc_dfn.rsc_name, vlmdfn.vlm_nr, vlmdfn.vlm_minor,
                    SizeCalc.approximate_size_string(vlmdfn.vlm_size), state
                ])
        tbl.show()
Example #30
0
 def show_netinterfaces(cls, args, lstnodes):
     node = lstnodes.node(args.node_name)
     if node:
         tbl = linstor_client.Table(utf8=not args.no_utf8, colors=not args.no_color, pastable=args.pastable)
         tbl.add_column(node.name, color=Color.GREEN)
         tbl.add_column("NetInterface")
         tbl.add_column("IP")
         tbl.add_column("Port")
         tbl.add_column("EncryptionType")
         # warning: system test depends on alphabetical ordering
         for net_if in node.net_interfaces:
             tbl.add_row([
                 "+ StltCon" if net_if.is_active else "+",
                 net_if.name,
                 net_if.address,
                 net_if.stlt_port if net_if.stlt_port else "",
                 net_if.stlt_encryption_type if net_if.stlt_encryption_type else ""
             ])
         tbl.show()
     else:
         raise LinstorClientError("Node '{n}' not found on controller.".format(n=args.node_name),
                                  ExitCode.OBJECT_NOT_FOUND)