Ejemplo n.º 1
0
def get_detailed_image_row(docker_image):
    row = []
    image_id = SelectableText(docker_image.short_id, maps=get_map())
    row.append(image_id)

    command = SelectableText(docker_image.command, maps=get_map(defult="main_list_ddg"))
    row.append(command)

    base_image = docker_image.base_image()
    base_image_text = ""
    if base_image:
        base_image_text = base_image.short_name
    base_image_w = SelectableText(base_image_text, maps=get_map())
    row.append(base_image_w)

    time = SelectableText(docker_image.display_time_created(),
                          maps=get_time_attr_map(docker_image.created))
    row.append(time)

    image_names_markup = get_image_names_markup(docker_image)
    # urwid.Text([]) tracebacks
    if image_names_markup:
        image_names = SelectableText(image_names_markup)
    else:
        image_names = SelectableText("")
    row.append(image_names)

    return row
Ejemplo n.º 2
0
 def _basic_data(self):
     data = [
         [
             SelectableText("Id", maps=get_map("main_list_green")),
             SelectableText(self.docker_container.container_id)
         ],
         [
             SelectableText("Status", maps=get_map("main_list_green")),
             ContainerStatusWidget(self.docker_container)
         ],
         [
             SelectableText("Created", maps=get_map("main_list_green")),
             SelectableText("{0}, {1}".format(
                 self.docker_container.display_formal_time_created(),
                 self.docker_container.display_time_created()))
         ],
         [
             SelectableText("Command", maps=get_map("main_list_green")),
             SelectableText(self.docker_container.command)
         ],
     ]
     if self.docker_container.names:
         data.append([
             SelectableText("Name", maps=get_map("main_list_green")),
             SelectableText("".join(self.docker_container.names))
         ], )
     self.walker.extend(assemble_rows(data, ignore_columns=[1]))
Ejemplo n.º 3
0
def get_detailed_container_row(docker_container):
    row = []
    container_id = SelectableText(docker_container.short_id)
    row.append(container_id)

    command = SelectableText(docker_container.command, get_map(defult="main_list_ddg"))
    row.append(command)

    image = SelectableText(docker_container.image_name())
    row.append(image)

    if docker_container.running:
        attr_map = get_map("main_list_green")
    elif docker_container.exited_well:
        attr_map = get_map("main_list_orange")
    elif docker_container.status_created:
        attr_map = get_map("main_list_yellow")
    else:
        attr_map = get_map("main_list_red")
    status = SelectableText(docker_container.status, attr_map)
    row.append(status)

    name = SelectableText(docker_container.short_name)
    row.append(name)

    return row
Ejemplo n.º 4
0
 def _labels(self):
     if not self.docker_image.labels:
         return []
     data = []
     self.walker.append(RowWidget([SelectableText("")]))
     self.walker.append(RowWidget([SelectableText("Labels", maps=get_map("main_list_white"))]))
     for label_key, label_value in self.docker_image.labels.items():
         data.append([SelectableText(label_key, maps=get_map("main_list_green")), SelectableText(label_value)])
     self.walker.extend(assemble_rows(data))
Ejemplo n.º 5
0
Archivo: util.py Proyecto: f-cap/sen
def get_container_status_markup(docker_container):
    if docker_container.running:
        attr_map = get_map("main_list_green")
    elif docker_container.exited_well:
        attr_map = get_map("main_list_orange")
    elif docker_container.status_created:
        attr_map = get_map("main_list_yellow")
    else:
        attr_map = get_map("main_list_red")
    return docker_container.status, attr_map
Ejemplo n.º 6
0
 def _labels(self):
     if not self.docker_container.labels:
         return []
     data = []
     self.walker.append(
         RowWidget(
             [SelectableText("Labels", maps=get_map("main_list_white"))]))
     for label_key, label_value in self.docker_container.labels.items():
         data.append([
             SelectableText(label_key, maps=get_map("main_list_green")),
             SelectableText(label_value)
         ])
     self.walker.extend(assemble_rows(data, ignore_columns=[1]))
Ejemplo n.º 7
0
 def _basic_data(self):
     data = [
         [SelectableText("Id", maps=get_map("main_list_green")),
          SelectableText(self.docker_image.image_id)],
         [SelectableText("Created", maps=get_map("main_list_green")),
          SelectableText("{0}, {1}".format(self.docker_image.display_formal_time_created(),
                                           self.docker_image.display_time_created()))],
         [SelectableText("Size", maps=get_map("main_list_green")),
          SelectableText(humanize_bytes(self.docker_image.size))],
         [SelectableText("Command", maps=get_map("main_list_green")),
          SelectableText(self.docker_image.container_command)],
     ]
     self.walker.extend(assemble_rows(data))
Ejemplo n.º 8
0
 def _image_names(self):
     if not self.docker_image.names:
         return
     self.walker.append(RowWidget([SelectableText("")]))
     self.walker.append(RowWidget([SelectableText("Image Names", maps=get_map("main_list_white"))]))
     for n in self.docker_image.names:
         self.walker.append(RowWidget([TagWidget(self.docker_image, n)]))
Ejemplo n.º 9
0
 def _containers(self):
     if not self.docker_image.containers():
         return
     self.walker.append(RowWidget([SelectableText("")]))
     self.walker.append(RowWidget([SelectableText("Containers", maps=get_map("main_list_white"))]))
     for container in self.docker_image.containers():
         self.walker.append(RowWidget([SelectableText(str(container))]))
Ejemplo n.º 10
0
 def _image(self):
     self.walker.append(RowWidget([SelectableText("")]))
     self.walker.append(
         RowWidget(
             [SelectableText("Image", maps=get_map("main_list_white"))]))
     self.walker.append(
         RowWidget([LayerWidget(self.ui, self.docker_container.image)]))
Ejemplo n.º 11
0
 def _logs(self):
     operation = self.docker_container.logs(follow=False, lines=10)
     if operation.response:
         self.walker.append(RowWidget([SelectableText("")]))
         self.walker.append(
             RowWidget(
                 [SelectableText("Logs", maps=get_map("main_list_white"))]))
         for x in operation.response.splitlines():
             self.walker.append(RowWidget([SelectableText(x)]))
Ejemplo n.º 12
0
 def _image_names(self):
     if not self.docker_image.names:
         return
     self.walker.append(RowWidget([SelectableText("")]))
     self.walker.append(
         RowWidget([
             SelectableText("Image Names", maps=get_map("main_list_white"))
         ]))
     for n in self.docker_image.names:
         self.walker.append(RowWidget([TagWidget(self.docker_image, n)]))
Ejemplo n.º 13
0
 def _containers(self):
     if not self.docker_image.containers():
         return
     self.walker.append(RowWidget([SelectableText("")]))
     self.walker.append(
         RowWidget([
             SelectableText("Containers", maps=get_map("main_list_white"))
         ]))
     for container in self.docker_image.containers():
         self.walker.append(
             RowWidget([ContainerOneLinerWidget(self.ui, container)]))
Ejemplo n.º 14
0
 def _process_tree(self):
     top = self.docker_container.top().response
     logger.debug(top)
     if top:
         self.walker.append(RowWidget([SelectableText("")]))
         self.walker.append(
             RowWidget([
                 SelectableText("Process Tree",
                                maps=get_map("main_list_white"))
             ]))
         self.walker.append(BoxAdapter(ProcessTree(top), len(top)))
Ejemplo n.º 15
0
 def _basic_data(self):
     data = [
         [
             SelectableText("Id", maps=get_map("main_list_green")),
             SelectableText(self.docker_image.image_id)
         ],
         [
             SelectableText("Created", maps=get_map("main_list_green")),
             SelectableText("{0}, {1}".format(
                 self.docker_image.display_formal_time_created(),
                 self.docker_image.display_time_created()))
         ],
         [
             SelectableText("Size", maps=get_map("main_list_green")),
             SelectableText(humanize_bytes(self.docker_image.size))
         ],
         [
             SelectableText("Command", maps=get_map("main_list_green")),
             SelectableText(self.docker_image.container_command)
         ],
     ]
     self.walker.extend(assemble_rows(data, ignore_columns=[1]))
Ejemplo n.º 16
0
    def _net(self):
        ports = self.docker_container.net.ports
        data = []
        if ports:
            data.extend([[SelectableText("")],
                         [
                             SelectableText("Host Port",
                                            maps=get_map("main_list_white")),
                             SelectableText("Container Port",
                                            maps=get_map("main_list_white"))
                         ]])
            for container_port, host_port in ports.items():
                if host_port and container_port:
                    data.append([
                        SelectableText(host_port),
                        SelectableText(container_port)
                    ])

        ips = self.docker_container.net.ips
        logger.debug(ips)
        if ips:
            data.extend([[SelectableText("")],
                         [
                             SelectableText("Network Name",
                                            maps=get_map("main_list_white")),
                             SelectableText("IP Address",
                                            maps=get_map("main_list_white"))
                         ]])
            for net_name, net_data in ips.items():
                a4 = net_data.get("ip_address4", "none")
                a6 = net_data.get("ip_address6", "")
                data.append([SelectableText(net_name), SelectableText(a4)])
                if a6:
                    data.append([SelectableText(net_name), SelectableText(a6)])
        if data:
            self.walker.extend(
                assemble_rows(data, dividechars=3, ignore_columns=[1]))
Ejemplo n.º 17
0
    def _layers(self):
        self.walker.append(RowWidget([SelectableText("")]))
        self.walker.append(RowWidget([SelectableText("Layers", maps=get_map("main_list_white"))]))

        i = self.docker_image
        index = 0
        self.walker.append(RowWidget([LayerWidget(self.ui, self.docker_image, index=index)]))
        while True:
            index += 1
            parent = i.parent_image
            if parent:
                self.walker.append(RowWidget([LayerWidget(self.ui, parent, index=index)]))
                i = parent
            else:
                break
Ejemplo n.º 18
0
Archivo: main.py Proyecto: f-cap/sen
def get_detailed_container_row(docker_container):
    row = []
    container_id = SelectableText(docker_container.short_id)
    row.append(container_id)

    command = SelectableText(docker_container.command, get_map(defult="main_list_ddg"))
    row.append(command)

    image = SelectableText(docker_container.image_name())
    row.append(image)

    row.append(ContainerStatusWidget(docker_container))

    name = SelectableText(docker_container.short_name)
    row.append(name)

    return row
Ejemplo n.º 19
0
    def _layers(self):
        self.walker.append(RowWidget([SelectableText("")]))
        self.walker.append(
            RowWidget(
                [SelectableText("Layers", maps=get_map("main_list_white"))]))

        i = self.docker_image
        index = 0
        self.walker.append(
            RowWidget([LayerWidget(self.ui, self.docker_image, index=index)]))
        while True:
            index += 1
            parent = i.parent_image
            if parent:
                self.walker.append(
                    RowWidget([LayerWidget(self.ui, parent, index=index)]))
                i = parent
            else:
                break
Ejemplo n.º 20
0
Archivo: util.py Proyecto: f-cap/sen
 def __init__(self, text, maps=None):
     maps = maps or get_map()
     super().__init__(urwid.Text(text, align="left", wrap="clip"), maps)
Ejemplo n.º 21
0
    def _resources(self):
        self.walker.append(RowWidget([SelectableText("")]))
        self.walker.append(
            RowWidget([
                SelectableText("Resource Usage",
                               maps=get_map("main_list_white"))
            ]))
        cpu_g = ContainerInfoGraph("graph_lines_cpu_tips", "graph_lines_cpu")
        mem_g = ContainerInfoGraph("graph_lines_mem_tips", "graph_lines_mem")
        blk_r_g = ContainerInfoGraph("graph_lines_blkio_r_tips",
                                     "graph_lines_blkio_r")
        blk_w_g = ContainerInfoGraph("graph_lines_blkio_w_tips",
                                     "graph_lines_blkio_w")
        net_r_g = ContainerInfoGraph("graph_lines_net_r_tips",
                                     "graph_lines_net_r")
        net_w_g = ContainerInfoGraph("graph_lines_net_w_tips",
                                     "graph_lines_net_w")

        cpu_label = ColorText("CPU ", "graph_lines_cpu_legend")
        cpu_value = ColorText("0.0 %", "graph_lines_cpu_legend")
        mem_label = ColorText("Memory ", "graph_lines_mem_legend")
        mem_value = ColorText("0.0 %", "graph_lines_mem_legend")
        blk_r_label = ColorText("I/O Read ", "graph_lines_blkio_r_legend")
        blk_r_value = ColorText("0 B", "graph_lines_blkio_r_legend")
        blk_w_label = ColorText("I/O Write ", "graph_lines_blkio_w_legend")
        blk_w_value = ColorText("0 B", "graph_lines_blkio_w_legend")
        net_r_label = ColorText("Net Rx ", "graph_lines_net_r_legend")
        net_r_value = ColorText("0 B", "graph_lines_net_r_legend")
        net_w_label = ColorText("Net Tx ", "graph_lines_net_w_legend")
        net_w_value = ColorText("0 B", "graph_lines_net_w_legend")
        self.walker.append(
            urwid.Columns([
                BoxAdapter(cpu_g, 12),
                BoxAdapter(mem_g, 12),
                ("weight", 0.5, BoxAdapter(blk_r_g, 12)),
                ("weight", 0.5, BoxAdapter(blk_w_g, 12)),
                ("weight", 0.5, BoxAdapter(net_r_g, 12)),
                ("weight", 0.5, BoxAdapter(net_w_g, 12)),
                BoxAdapter(
                    UnselectableListBox(
                        urwid.SimpleFocusListWalker([
                            UnselectableRowWidget([(12, cpu_label),
                                                   cpu_value]),
                            UnselectableRowWidget([(12, mem_label),
                                                   mem_value]),
                            UnselectableRowWidget([(12, blk_r_label),
                                                   blk_r_value]),
                            UnselectableRowWidget([(12, blk_w_label),
                                                   blk_w_value]),
                            UnselectableRowWidget([(12, net_r_label),
                                                   net_r_value]),
                            UnselectableRowWidget([(12, net_w_label),
                                                   net_w_value]),
                        ])), 12),
            ]))
        self.walker.append(RowWidget([SelectableText("")]))

        @log_traceback
        def realtime_updates():
            g = self.docker_container.stats().response
            while True:
                try:
                    update = next(g)
                except Exception as ex:
                    logger.warning("exception when reading stats: %r", ex)
                    g = self.docker_container.stats().response
                    continue

                if self.stop.is_set():
                    break
                logger.debug(update)
                cpu_percent = update["cpu_percent"]
                cpu_value.text = "%.2f %%" % cpu_percent
                cpu_g.rotate_value(int(cpu_percent), max_val=100)

                mem_percent = update["mem_percent"]
                mem_current = humanize_bytes(update["mem_current"])
                mem_value.text = "%.2f %% (%s)" % (mem_percent, mem_current)
                mem_g.rotate_value(int(mem_percent), max_val=100)

                blk_read = update["blk_read"]
                blk_write = update["blk_write"]
                blk_r_value.text = humanize_bytes(blk_read)
                blk_w_value.text = humanize_bytes(blk_write)
                r_max_val = blk_r_g.rotate_value(blk_read, adaptive_max=True)
                w_max_val = blk_w_g.rotate_value(blk_write, adaptive_max=True)
                blk_r_g.set_max(max((r_max_val, w_max_val)))
                blk_w_g.set_max(max((r_max_val, w_max_val)))

                net_read = update["net_rx"]
                net_write = update["net_tx"]
                net_r_value.text = humanize_bytes(net_read)
                net_w_value.text = humanize_bytes(net_write)
                r_max_val = net_r_g.rotate_value(net_read, adaptive_max=True)
                w_max_val = net_w_g.rotate_value(net_write, adaptive_max=True)
                net_r_g.set_max(max((r_max_val, w_max_val)))
                net_w_g.set_max(max((r_max_val, w_max_val)))

        self.thread = threading.Thread(target=realtime_updates, daemon=True)
        self.thread.start()