def list_deployments(self, namespace=None): """ List all available deployments. :param namespace: str, if not specified list deployments for all namespaces :return: collection of instances of :class:`conu.backend.k8s.deployment.Deployment` """ if namespace: return [ Deployment( name=d.metadata.name, namespace=d.metadata.namespace, labels=d.metadata.labels, selector=d.spec.selector, image_metadata=ImageMetadata( name=d.spec.template.spec.containers[0].name.split( "-", 1)[0])) for d in self.apps_api.list_namespaced_deployment( namespace, watch=False).items ] return [ Deployment(name=d.metadata.name, namespace=d.metadata.namespace, labels=d.metadata.labels, selector=d.spec.selector, image_metadata=ImageMetadata( name=d.spec.template.spec.containers[0].name.split( "-", 1)[0])) for d in self.apps_api.list_deployment_for_all_namespaces( watch=False).items ]
def buildah_image_inspect_to_metadata(inspect_data): """ process data from `buildah inspect -t image` and return ImageMetadata :param inspect_data: dict, metadata from `buildah inspect -t image` :return: instance of ImageMetadata """ im = ImageMetadata() im.name = graceful_get(inspect_data, "FromImage") im.identifier = graceful_get(inspect_data, "FromImageID") buildah_common_inspect_to_metadata(im, inspect_data) return im
def __init__(self, repository, tag="latest", identifier=None, pull_policy=DockerImagePullPolicy.IF_NOT_PRESENT): """ :param repository: str, image name, examples: "fedora", "registry.fedoraproject.org/fedora", "tomastomecek/sen", "docker.io/tomastomecek/sen" :param tag: str, tag of the image, when not specified, "latest" is implied :param identifier: str, unique identifier for this image :param pull_policy: enum, strategy to apply for pulling the image """ super(DockerImage, self).__init__(repository, tag=tag) if not isinstance(tag, (six.string_types, None.__class__)): raise ConuException("'tag' is not a string type") if not isinstance(pull_policy, DockerImagePullPolicy): raise ConuException("'pull_policy' is not an instance of DockerImagePullPolicy") if identifier: self._id = identifier self.d = get_client() self.pull_policy = pull_policy self._inspect_data = None self.metadata = ImageMetadata() self.transport = SkopeoTransport.DOCKER if pull_policy == DockerImagePullPolicy.NEVER \ else SkopeoTransport.DOCKER_DAEMON self.path = None if self.pull_policy == DockerImagePullPolicy.ALWAYS: logger.debug("pull policy set to 'always', pulling the image") self.pull() elif self.pull_policy == DockerImagePullPolicy.IF_NOT_PRESENT and not self.is_present(): logger.debug("pull policy set to 'if_not_present' and image is not present, " "pulling the image") self.pull() elif self.pull_policy == DockerImagePullPolicy.NEVER: logger.debug("pull policy set to 'never'")
def get_metadata(self): """ Provide metadata about this image. :return: ImageMetadata, Image metadata instance """ if self._metadata is None: self._metadata = ImageMetadata() inspect_to_metadata(self._metadata, self.inspect(refresh=True)) return self._metadata