Ejemplo n.º 1
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))
Ejemplo n.º 2
0
            def event_handler(event_header, event_data):
                if event_header.node_name == node_name:
                    if event_header.event_name in [
                            apiconsts.EVENT_RESOURCE_STATE,
                            apiconsts.EVENT_RESOURCE_DEPLOYMENT_STATE
                    ]:
                        if event_header.event_action == apiconsts.EVENT_STREAM_CLOSE_NO_CONNECTION:
                            print(
                                Output.color_str('WARNING:', Color.YELLOW,
                                                 args.no_color) +
                                " Satellite connection lost")
                            return ExitCode.NO_SATELLITE_CONNECTION
                        if event_header.event_action == apiconsts.EVENT_STREAM_CLOSE_REMOVED:
                            print((Output.color_str('ERROR:', Color.RED,
                                                    args.no_color)) +
                                  " Resource removed")
                            return ExitCode.API_ERROR

                    if event_header.event_name == apiconsts.EVENT_RESOURCE_STATE and \
                            event_data is not None and event_data.ready:
                        return ExitCode.OK

                    return self.check_failure_events(event_header.event_name,
                                                     event_data)

                return None
Ejemplo n.º 3
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()
Ejemplo n.º 4
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()
Ejemplo n.º 5
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)
Ejemplo n.º 6
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()
Ejemplo n.º 7
0
    def handle_replies(cls, args, replies):
        rc = ExitCode.OK
        if args and args.machine_readable:
            Commands._print_machine_readable(replies, args.output_version)
            return rc

        for call_resp in replies:
            current_rc = Output.handle_ret(call_resp,
                                           warn_as_error=args.warn_as_error,
                                           no_color=args.no_color)
            if current_rc != ExitCode.OK:
                rc = current_rc

        return rc
Ejemplo n.º 8
0
    def clone(self, args):
        clone_resp = self.get_linstorapi().resource_dfn_clone(
            args.source_resource,
            args.clone_name,
            args.external_name,
            use_zfs_clone=args.use_zfs_clone)

        rc = self.handle_replies(args, clone_resp.messages)

        if rc == ExitCode.OK and not args.no_wait:
            if not args.machine_readable:
                print("Waiting for cloning to complete...")
            try:
                res = self.get_linstorapi().resource_dfn_clone_wait_complete(
                    clone_resp.source_name,
                    clone_resp.clone_name,
                    timeout=args.wait_timeout)
                if not res:
                    rc = ExitCode.API_ERROR
                if not args.machine_readable:
                    if res:
                        print("{msg} cloning {c}.".format(
                            c=clone_resp.clone_name,
                            msg=Output.color_str("Completed", Color.GREEN,
                                                 args.no_color)))
                    else:
                        print(
                            "{msg} cloning {c}, please check resource status or satellite errors."
                            .format(c=clone_resp.clone_name,
                                    msg=Output.color_str(
                                        "Failed", Color.RED, args.no_color)))
            except linstor.LinstorApiCallError as e:
                rc = ExitCode.API_ERROR
                Output.handle_ret(e.main_error, args.no_color, False,
                                  sys.stderr)

        return rc
Ejemplo n.º 9
0
                def event_handler(event_header, event_data):
                    if event_header.event_name == apiconsts.EVENT_RESOURCE_DEFINITION_READY:
                        if event_header.event_action == apiconsts.EVENT_STREAM_CLOSE_REMOVED:
                            print((Output.color_str('ERROR:', Color.RED,
                                                    args.no_color)) +
                                  " Resource removed")
                            return ExitCode.API_ERROR

                        if event_data is not None:
                            if event_data.error_count > 0:
                                return ExitCode.API_ERROR

                            if event_data.ready_count == args.auto_place:
                                return ExitCode.OK

                    return None
Ejemplo n.º 10
0
            def event_handler(event_header, event_data):
                if event_header.event_name in [
                        apiconsts.EVENT_RESOURCE_DEPLOYMENT_STATE
                ]:
                    if event_header.event_action == apiconsts.EVENT_STREAM_CLOSE_NO_CONNECTION:
                        print(
                            Output.color_str('WARNING:', Color.YELLOW,
                                             args.no_color) +
                            " Satellite connection lost")
                        return ExitCode.NO_SATELLITE_CONNECTION
                    if event_header.event_action == apiconsts.EVENT_STREAM_CLOSE_REMOVED:
                        return [
                            linstor.ApiCallResponse(response)
                            for response in event_data.responses
                        ]

                    return self.check_failure_events(event_header.event_name,
                                                     event_data)
                return None
Ejemplo n.º 11
0
 def show_error_report(self, args, lstmsg):
     for error in lstmsg:
         print(Output.utf8(error.text))
Ejemplo n.º 12
0
    def show_volumes(cls, args, lstmsg):
        """

        :param args:
        :param responses.ResourceResponse lstmsg: resource response data to display
        :return: None
        """
        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("StoragePool")
        tbl.add_column("VolNr", just_txt='>')
        tbl.add_column("MinorNr", just_txt='>')
        tbl.add_column("DeviceName")
        tbl.add_column("Allocated", just_txt='>')
        tbl.add_column("InUse",
                       color=Output.color(Color.DARKGREEN, args.no_color))
        tbl.add_column("State",
                       color=Output.color(Color.DARKGREEN, args.no_color),
                       just_txt='>')

        rsc_state_lkup = {
            x.node_name + x.name: x
            for x in lstmsg.resource_states
        }

        reports = []
        for rsc in lstmsg.resources:
            if not args.all and apiconsts.FLAG_TIE_BREAKER in rsc.flags:
                continue  # skip tie breaker resources

            if apiconsts.FLAG_RSC_INACTIVE in rsc.flags:
                continue  # do not show non existing volumes for inactive resources

            rsc_state = rsc_state_lkup.get(rsc.node_name + rsc.name)
            rsc_usage = ""
            if rsc_state and rsc_state.in_use is not None:
                if rsc_state.in_use:
                    rsc_usage = tbl.color_cell("InUse", Color.GREEN)
                else:
                    rsc_usage = "Unused"
            for vlm in rsc.volumes:
                vlm_state = cls.get_volume_state(
                    rsc_state.volume_states, vlm.number) if rsc_state else None
                state_txt, color = cls.volume_state_cell(
                    vlm_state, rsc.flags, vlm.flags)
                has_errors = any([x.is_error() for x in vlm.reports])
                conn_failed = (rsc.layer_data.drbd_resource
                               and any(not v.connected
                                       for k, v in rsc.layer_data.
                                       drbd_resource.connections.items()))
                if conn_failed:
                    color = Color.RED

                state = tbl.color_cell(state_txt,
                                       color) if color else state_txt
                if has_errors:
                    state = tbl.color_cell("Error", Color.RED)
                for x in vlm.reports:
                    reports.append(x)
                vlm_drbd_data = vlm.drbd_data
                tbl.add_row([
                    rsc.node_name, rsc.name, vlm.storage_pool_name,
                    str(vlm.number),
                    str(vlm_drbd_data.drbd_volume_definition.minor)
                    if vlm_drbd_data else "", vlm.device_path,
                    SizeCalc.approximate_size_string(vlm.allocated_size)
                    if vlm.allocated_size else "", rsc_usage, state
                ])

        tbl.show()
        for x in reports:
            Output.handle_ret(x,
                              args.no_color,
                              warn_as_error=args.warn_as_error)