Example #1
0
    def list(cc, args):
        lstmsg = Commands._get_list_message(cc, API_LST_RSC, MsgLstRsc(), args)

        if lstmsg:
            rsc_dfns = Commands._get_list_message(cc, API_LST_RSC_DFN,
                                                  MsgLstRscDfn(),
                                                  args).rsc_dfns
            rsc_dfn_map = {x.rsc_name: x for x in rsc_dfns}

            stor_pools = Commands._get_list_message(cc, API_LST_STOR_POOL,
                                                    MsgLstStorPool(),
                                                    args).stor_pools
            stor_pool_map = {x.stor_pool_name: x for x in stor_pools}

            tbl = Table(utf8=not args.no_utf8,
                        colors=not args.no_color,
                        pastable=args.pastable)
            tbl.add_column("ResourceName")
            tbl.add_column("Node")
            tbl.add_column("Port")
            tbl.add_column("Device",
                           color=Output.color(Color.DARKGREEN, args.no_color))
            tbl.add_column("State",
                           color=Output.color(Color.DARKGREEN, args.no_color),
                           just_txt='>')

            for rsc in lstmsg.resources:
                rsc_dfn = rsc_dfn_map[rsc.name]
                diskless = FLAG_DISKLESS in rsc.rsc_flags
                if not diskless:
                    storage_pool_name = Commands._get_prop(
                        rsc.props, KEY_STOR_POOL_NAME)
                    storage_pool = stor_pool_map[storage_pool_name]
                    driver_key = StoragePoolCommands.get_driver_key(
                        storage_pool.driver)
                    block_device = Commands._get_prop(storage_pool.props,
                                                      driver_key)
                    # print(storage_pool)
                marked_delete = FLAG_DELETE in rsc.rsc_flags
                # rsc_state = ResourceCommands.find_rsc_state(lstmsg.resource_states, rsc.name, rsc.node_name)
                tbl.add_row([
                    rsc.name, rsc.node_name, rsc_dfn.rsc_dfn_port,
                    tbl.color_cell("DISKLESS", Color.GREEN)
                    if diskless else block_device,
                    tbl.color_cell("DELETING", Color.RED)
                    if marked_delete else "ok"
                ])
            tbl.show()

        return None
Example #2
0
    def list(cc, args):
        lstmsg = Commands._get_list_message(cc, API_LST_NODE, MsgLstNode(),
                                            args)

        if lstmsg:
            tbl = Table(utf8=not args.no_utf8,
                        colors=not args.no_color,
                        pastable=args.pastable)
            tbl.add_column("Node")
            tbl.add_column("NodeType")
            tbl.add_column("IPs")
            tbl.add_column("State",
                           color=Output.color(Color.DARKGREEN, args.no_color))
            for n in lstmsg.nodes:
                ips = [if_.address for if_ in n.net_interfaces]
                tbl.add_row([
                    n.name, n.type, ",".join(ips),
                    tbl.color_cell("ok", Color.DARKGREEN)
                    if n.connected else tbl.color_cell("OFFLINE", Color.RED)
                ])
            tbl.show()

            # prntfrm = "{node:<20s} {type:<10s} {uuid:<40s}"
            # print(prntfrm.format(node="Node", type="NodeType", uuid="UUID"))

            # netiffrm = " +   {name:<20s} {address:>20s}"
            # for n in lstmsg.nodes:
            #     print(prntfrm.format(node=n.name, type=n.type, uuid=n.uuid))

            #     for interface in n.net_interfaces:
            #         print(netiffrm.format(
            #             name=interface.name,
            #             address=interface.address))

        return None
Example #3
0
    def list(cc, args):
        lstmsg = Commands._get_list_message(cc, API_LST_RSC_DFN,
                                            MsgLstRscDfn(), args)

        if lstmsg:
            tbl = Table(utf8=not args.no_utf8,
                        colors=not args.no_color,
                        pastable=args.pastable)
            tbl.add_column("ResourceName")
            tbl.add_column("Port")
            tbl.add_column("State",
                           color=Output.color(Color.DARKGREEN, args.no_color))
            for rsc_dfn in lstmsg.rsc_dfns:
                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()

            # prntfrm = "{rsc:<20s} {port:<10s} {uuid:<40s}"
            # print(prntfrm.format(rsc="Resource-name", port="Port", uuid="UUID"))
            # for rsc_dfn in lstmsg.rsc_dfns:
            #     print(prntfrm.format(rsc=rsc_dfn.rsc_name,
            #           port=str(rsc_dfn.rsc_dfn_port), uuid=rsc_dfn.rsc_dfn_uuid))

        return None
Example #4
0
    def completer(cc, prefix, **kwargs):
        possible = set()
        lstmsg = Commands._get_list_message(cc, API_LST_RSC, MsgLstRsc())

        if lstmsg:
            for rsc in lstmsg.resources:
                possible.add(rsc.name)

            if prefix:
                return [res for res in possible if res.startswith(prefix)]

        return possible
Example #5
0
    def completer(cc, prefix, **kwargs):
        possible = set()
        lstmsg = Commands._get_list_message(cc, API_LST_NODE, MsgLstNode())

        if lstmsg:
            for node in lstmsg.nodes:
                possible.add(node.name)

            if prefix:
                return [node for node in possible if node.startswith(prefix)]

        return possible
Example #6
0
    def completer(cc, prefix, **kwargs):
        possible = set()
        lstmsg = Commands._get_list_message(cc, API_LST_STOR_POOL, MsgLstStorPool())

        if lstmsg:
            for storpool in lstmsg.resources:
                possible.add(storpool.stor_pool_name)

            if prefix:
                return [res for res in possible if res.startswith(prefix)]

        return possible
Example #7
0
    def list_volumes(cc, args):
        lstmsg = Commands._get_list_message(cc, API_LST_RSC, MsgLstRsc(),
                                            args)  # type: MsgLstRsc

        if lstmsg:
            tbl = 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("VolumeNr")
            tbl.add_column("MinorNr")
            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:
                    if rsc_state:
                        vlm_state = ResourceCommands.get_volume_state(
                            rsc_state.vlm_states, vlm.vlm_nr)
                    else:
                        vlm_state = None
                    state = tbl.color_cell("unknown", Color.YELLOW)
                    if vlm_state:
                        state = "ok"
                        problems = []
                        if not vlm_state.is_present:
                            problems.append("not present")
                        if vlm_state.disk_failed:
                            problems.append("disk failed")

                        if problems:
                            state = tbl.color_cell(", ".join(problems),
                                                   Color.RED)
                    tbl.add_row([
                        rsc.node_name, rsc.name,
                        str(vlm.vlm_nr),
                        str(vlm.vlm_minor_nr), state
                    ])

            tbl.show()

        return None
Example #8
0
    def list(cc, args):
        lstmsg = Commands._get_list_message(cc, API_LST_STOR_POOL_DFN, MsgLstStorPoolDfn(), args)

        if lstmsg:
            tbl = Table(utf8=not args.no_utf8, colors=not args.no_color, pastable=args.pastable)
            tbl.add_column("StoragePool")
            for storpool_dfn in lstmsg.stor_pool_dfns:
                tbl.add_row([
                    storpool_dfn.stor_pool_name
                ])
            tbl.show()

            # prntfrm = "{storpool:<20s} {uuid:<40s}"
            # print(prntfrm.format(storpool="StorpoolDfn-name", uuid="UUID"))
            # for storpool_dfn in lstmsg.stor_pool_dfns:
            #     print(prntfrm.format(storpool=storpool_dfn.stor_pool_name, uuid=storpool_dfn.uuid))

        return None
Example #9
0
    def list(cc, args):
        lstmsg = Commands._get_list_message(cc, API_LST_RSC_DFN,
                                            MsgLstRscDfn(), args)

        if lstmsg:
            tbl = Table(utf8=not args.no_utf8,
                        colors=not args.no_color,
                        pastable=args.pastable)
            tbl.add_column("ResourceName")
            tbl.add_column("VolumeNr")
            tbl.add_column("VolumeMinor")
            tbl.add_column("Size")
            tbl.add_column("State",
                           color=Output.color(Color.DARKGREEN, args.no_color))
            for rsc_dfn in lstmsg.rsc_dfns:
                for vlmdfn in rsc_dfn.vlm_dfns:
                    tbl.add_row([
                        rsc_dfn.rsc_name, vlmdfn.vlm_nr, vlmdfn.vlm_minor,
                        approximate_size_string(vlmdfn.vlm_size),
                        tbl.color_cell("DELETING", Color.RED) if FLAG_DELETE
                        in rsc_dfn.rsc_dfn_flags else tbl.color_cell(
                            "ok", Color.DARKGREEN)
                    ])
            tbl.show()

            # prntfrm = "{res:<15s} {uuid:<40s} {vlmnr:<5s} {vlmminor:<10s} {vlmsize:<10s}"
            # print(prntfrm.format(res="Resource", uuid="UUID", vlmnr="VlmNr", vlmminor="VlmMinor", vlmsize="Size"))
            # prntfrm = "{res:<15s} {uuid:<40s} {vlmnr:<5d} {vlmminor:<10d} {vlmsize:<20s}"
            # for rscdfn in lstmsg.rsc_dfns:
            #     for vlmdfn in rscdfn.vlm_dfns:
            #         print(prntfrm.format(
            #             res=rscdfn.rsc_name,
            #             uuid=vlmdfn.vlm_dfn_uuid,
            #             vlmnr=vlmdfn.vlm_nr,
            #             vlmminor=vlmdfn.vlm_minor,
            #             vlmsize=approximate_size_string(vlmdfn.vlm_size)))

        return None
Example #10
0
    def list(cc, args):
        lstmsg = Commands._get_list_message(cc, API_LST_STOR_POOL, MsgLstStorPool(), args)

        if lstmsg:
            tbl = Table(utf8=not args.no_utf8, colors=not args.no_color, pastable=args.pastable)
            tbl.add_column("StoragePool")
            tbl.add_column("Node")
            tbl.add_column("Driver")
            tbl.add_column("DriverDevice")
            tbl.add_column("SupportsSnapshots")
            for storpool in lstmsg.stor_pools:
                driver_device_prop = [x for x in storpool.props
                                      if x.key == StoragePoolCommands.device_key_map[storpool.driver[:-len('Driver')]]]
                driver_device = driver_device_prop[0].value if driver_device_prop else ''

                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 ''

                tbl.add_row([
                    storpool.stor_pool_name,
                    storpool.node_name,
                    storpool.driver,
                    driver_device,
                    supports_snapshots
                ])
            tbl.show()

            # prntfrm = "{storpool:<20s} {uuid:<40s} {node:<30s} {driver:<20s}"
            # print(prntfrm.format(storpool="Storpool-name", uuid="UUID", node="Node", driver="Driver"))
            # for storpool in lstmsg.stor_pools:
            #     print(prntfrm.format(
            #         storpool=storpool.stor_pool_name,
            #         uuid=storpool.stor_pool_uuid,
            #         node=storpool.node_name,
            #         driver=storpool.driver))

        return None