예제 #1
0
    def GetHistory(self, show_empty_layers=False):
        """Returns a dict containing the modification history of the container.

    Args:
      show_empty_layers (bool): whether to display empty layers.
    Returns:
      dict: object describing history of the container.
    """
        result_dict = {}
        for layer in self.GetOrderedLayers():
            layer_info = self.GetLayerInfo(layer)
            layer_dict = {}

            if layer is None:
                raise ValueError('Layer {0:s} does not exist'.format(layer))
            layer_size = self.GetLayerSize(layer)
            layer_dict['size'] = layer_size
            if layer_size > 0 or show_empty_layers or self.docker_version == 2:
                layer_dict['created_at'] = utils.FormatDatetime(
                    layer_info['created'])
                container_cmd = layer_info['container_config'].get('Cmd', None)
                if container_cmd:
                    layer_dict['container_cmd'] = ' '.join(container_cmd)
                comment = layer_info.get('comment', None)
                if comment:
                    layer_dict['comment'] = comment
            result_dict[layer] = layer_dict

        return result_dict
예제 #2
0
    def GetContainersJson(self, only_running=False):
        """Returns a dict describing the running containers.

    Args:
      only_running (bool): Whether we display only running Containers.

    Returns:
      dict: A dict object representing the containers.
    """
        result = []
        for container_object in self.GetContainersList(
                only_running=only_running):
            image_id = container_object.image_id
            if self.docker_version == 2:
                image_id = image_id.split(':')[1]
            container_json = {
                'container_id': container_object.container_id,
                'image_id': image_id
            }

            if container_object.config_labels:
                container_json['labels'] = container_object.config_labels
            container_json['start_date'] = utils.FormatDatetime(
                container_object.start_timestamp)
            container_json['image_name'] = container_object.config_image_name

            if container_object.mount_id:
                container_json['mount_id'] = container_object.mount_id

            result.append(container_json)

        return result
예제 #3
0
    def GetContainersJson(self, only_running=False, filter_repositories=None):
        """Returns a dict describing the running containers.

    Args:
      only_running (bool): Whether we display only running Containers.
      filter_repositories (list(str)): Filter out containers running an image
        from a repository which domain is included in the list.
        Example: ['k8s.gcr.io', 'gke.gcr.io']

    Returns:
      dict: A dict object representing the containers.
    """
        result = []
        for container_object in self.GetContainersList(
                only_running=only_running,
                filter_repositories=filter_repositories):
            image_id = container_object.image_id
            if self.docker_version == 2:
                image_id = image_id.split(':')[1]
            container_json = collections.OrderedDict()
            container_json['image_name'] = container_object.config_image_name
            container_json['container_id'] = container_object.container_id
            container_json['image_id'] = image_id

            if container_object.config_labels:
                container_json['labels'] = container_object.config_labels
            container_json['start_date'] = utils.FormatDatetime(
                container_object.start_timestamp)

            if container_object.mount_id:
                container_json['mount_id'] = container_object.mount_id

            mount_points = container_object.GetMountpoints()
            for source, destination in mount_points:
                mountpoint_dict = collections.OrderedDict()
                mountpoint_dict['source'] = os.path.join(
                    self.docker_directory, source)
                mountpoint_dict['destination'] = os.path.join(
                    os.path.sep, destination)
                container_json.setdefault('mount_points',
                                          []).append(mountpoint_dict)

            if container_object.upper_dir:
                container_json['upper_dir'] = container_object.upper_dir

            if container_object.log_path:
                container_json['log_path'] = container_object.log_path

            if container_object.exposed_ports:
                container_json[
                    'exposed_ports'] = container_object.exposed_ports

            result.append(container_json)

        return result
예제 #4
0
    def GetContainersJson(self, only_running=False):
        """Returns a dict describing the running containers.

    Args:
      only_running (bool): Whether we display only running Containers.

    Returns:
      dict: A dict object representing the containers.
    """
        result = []
        for container_object in self.GetContainersList(
                only_running=only_running):
            image_id = container_object.image_id
            if self.docker_version == 2:
                image_id = image_id.split(':')[1]
            container_json = collections.OrderedDict()
            container_json['image_name'] = container_object.config_image_name
            container_json['container_id'] = container_object.container_id
            container_json['image_id'] = image_id

            if container_object.config_labels:
                container_json['labels'] = container_object.config_labels
            container_json['start_date'] = utils.FormatDatetime(
                container_object.start_timestamp)

            if container_object.mount_id:
                container_json['mount_id'] = container_object.mount_id

            if container_object.mount_points:
                container_json['mount_points'] = {}
                for mount_point, details in container_object.mount_points.items(
                ):
                    d = collections.OrderedDict()
                    d['type'] = details.get('Type')
                    d['mount_point'] = mount_point
                    d['source'] = details.get('Source')
                    d['RW'] = details.get('RW')
                    container_json['mount_points'][mount_point] = d

            if container_object.upper_dir:
                container_json['upper_dir'] = container_object.upper_dir

            if container_object.log_path:
                container_json['log_path'] = container_object.log_path

            result.append(container_json)

        return result
예제 #5
0
    def GetContainersJson(self, only_running=False):
        """Returns a dict describing the running containers.

    Args:
      only_running (bool): Whether we display only running Containers.

    Returns:
      dict: A dict object representing the containers.
    """
        result = []
        for container_object in self.GetContainersList(
                only_running=only_running):
            image_id = container_object.image_id
            if self.docker_version == 2:
                image_id = image_id.split(':')[1]
            container_json = collections.OrderedDict()
            container_json['image_name'] = container_object.config_image_name
            container_json['container_id'] = container_object.container_id
            container_json['image_id'] = image_id

            if container_object.config_labels:
                container_json['labels'] = container_object.config_labels
            container_json['start_date'] = utils.FormatDatetime(
                container_object.start_timestamp)

            if container_object.mount_id:
                container_json['mount_id'] = container_object.mount_id

            mount_points = container_object.GetMountpoints()
            for source, destination in mount_points:
                mountpoint_dict = collections.OrderedDict()
                mountpoint_dict['source'] = os.path.join(
                    self.docker_directory, source)
                mountpoint_dict['destination'] = os.path.join(
                    os.path.sep, destination)
                container_json.setdefault('mount_points',
                                          []).append(mountpoint_dict)

            if container_object.upper_dir:
                container_json['upper_dir'] = container_object.upper_dir

            if container_object.log_path:
                container_json['log_path'] = container_object.log_path

            result.append(container_json)

        return result
예제 #6
0
 def testFormatDatetime(self):
     """Tests the utils.FormatDatetime function."""
     test_date = '2017-12-25T15:59:59.102938 msqedigrb msg'
     expected_time_str = '2017-12-25T15:59:59.102938'
     self.assertEqual(expected_time_str, utils.FormatDatetime(test_date))