Code stringlengths 103 85.9k | Summary listlengths 0 94 |
|---|---|
Please provide a description of the function:def layers(self, rev=True):
image_layers = [
PodmanImage(None, identifier=x, pull_policy=PodmanImagePullPolicy.NEVER)
for x in self.get_layer_ids()
]
if not rev:
image_layers.reverse()
return image_... | [
"\n Get list of PodmanImage for every layer in image\n\n :param rev: get layers rev\n :return: list of :class:`conu.PodmanImage`\n "
] |
Please provide a description of the function:def get_metadata(self):
if self._metadata is None:
self._metadata = ImageMetadata()
inspect_to_metadata(self._metadata, self.inspect(refresh=True))
return self._metadata | [
"\n Provide metadata about this image.\n\n :return: ImageMetadata, Image metadata instance\n "
] |
Please provide a description of the function:def http_client(self, host=None, port=None):
host = host or self.get_IPv4s()[0]
port = port or self.get_ports()[0]
yield HttpClient(host, port, self.http_session) | [
"\n allow requests in context -- e.g.:\n\n .. code-block:: python\n\n with container.http_client(port=\"80\", ...) as c:\n assert c.get(\"/api/...\")\n\n\n :param host: str, if None, set self.get_IPv4s()[0]\n :param port: str or int, if None, set to self.get_por... |
Please provide a description of the function:def login_to_registry(username, token=None):
token = token or get_oc_api_token()
with DockerBackend() as backend:
backend.login(username, password=token,
registry=get_internal_registry_ip(), reauth=True) | [
"\n Login within docker daemon to docker registry running in this OpenShift cluster\n :return:\n "
] |
Please provide a description of the function:def push_to_registry(image, repository, tag, project):
return image.push("%s/%s/%s" % (get_internal_registry_ip(), project, repository), tag=tag) | [
"\n :param image: DockerImage, image to push\n :param repository: str, new name of image\n :param tag: str, new tag of image\n :param project: str, oc project\n :return: DockerImage, new docker image\n "
] |
Please provide a description of the function:def get_internal_registry_ip():
with conu.backend.origin.backend.OpenshiftBackend() as origin_backend:
services = origin_backend.list_services()
for service in services:
if service.name == 'docker-registry':
logger.debug("... | [
"\n Search for `docker-registry` IP\n :return: str, ip address\n "
] |
Please provide a description of the function:def delete(self):
body = client.V1DeleteOptions()
try:
status = self.core_api.delete_namespaced_pod(self.name, self.namespace, body)
logger.info("Deleting Pod %s in namespace %s", self.name, self.namespace)
self.p... | [
"\n delete pod from the Kubernetes cluster\n :return: None\n "
] |
Please provide a description of the function:def get_logs(self):
try:
api_response = self.core_api.read_namespaced_pod_log(self.name, self.namespace)
logger.debug("Logs from pod: %s in namespace: %s", self.name, self.namespace)
for line in api_response.split('\n'):
... | [
"\n print logs from pod\n :return: str or None\n "
] |
Please provide a description of the function:def get_phase(self):
if self.phase != PodPhase.TERMINATING:
self.phase = PodPhase.get_from_string(self.get_status().phase)
return self.phase | [
"\n get phase of the pod\n :return: PodPhase enum\n\n "
] |
Please provide a description of the function:def get_conditions(self):
# filter just values that are true (means that pod has that condition right now)
return [PodCondition.get_from_string(c.type) for c in self.get_status().conditions
if c.status == 'True'] | [
"\n get conditions through which the pod has passed\n :return: list of PodCondition enum or empty list\n "
] |
Please provide a description of the function:def is_ready(self):
if PodCondition.READY in self.get_conditions():
logger.info("Pod: %s in namespace: %s is ready!", self.name, self.namespace)
return True
return False | [
"\n Check if pod is in READY condition\n :return: bool\n "
] |
Please provide a description of the function:def wait(self, timeout=15):
Probe(timeout=timeout, fnc=self.is_ready, expected_retval=True).run() | [
"\n block until pod is not ready, raises an exc ProbeTimeout if timeout is reached\n :param timeout: int or float (seconds), time to wait for pod to run\n :return: None\n "
] |
Please provide a description of the function:def create(image_data):
# convert environment variables to Kubernetes objects
env_variables = []
for key, value in image_data.env_variables.items():
env_variables.append(client.V1EnvVar(name=key, value=value))
# convert ... | [
"\n :param image_data: ImageMetadata\n :return: V1Pod,\n https://github.com/kubernetes-client/python/blob/master/kubernetes/docs/V1Pod.md\n "
] |
Please provide a description of the function:def get_from_string(cls, string_phase):
if string_phase == 'Pending':
return cls.PENDING
elif string_phase == 'Running':
return cls.RUNNING
elif string_phase == 'Succeeded':
return cls.SUCCEEDED
el... | [
"\n Convert string value obtained from k8s API to PodPhase enum value\n :param string_phase: str, phase value from Kubernetes API\n :return: PodPhase\n "
] |
Please provide a description of the function:def get_from_string(cls, string_condition):
if string_condition == 'PodScheduled':
return cls.SCHEDULED
elif string_condition == 'Ready':
return cls.READY
elif string_condition == 'Initialized':
return cls... | [
"\n Convert string value obtained from k8s API to PodCondition enum value\n :param string_condition: str, condition value from Kubernetes API\n :return: PodCondition\n "
] |
Please provide a description of the function:def get_id(self):
if self._id is None:
self._id = graceful_get(self.inspect(refresh=True), "ID")
return self._id | [
"\n get unique identifier of this container\n\n :return: str\n "
] |
Please provide a description of the function:def get_name(self):
self.name = self.name or graceful_get(self.inspect(refresh=False), "Name")
return self.name | [
"\n Returns name of the container\n :return: str\n "
] |
Please provide a description of the function:def inspect(self, refresh=True):
if refresh or not self._inspect_data:
identifier = self._id or self.name
if not identifier:
raise ConuException("This container does not have a valid identifier.")
self._ins... | [
"\n return cached metadata by default\n\n :param refresh: bool, returns up to date metadata if set to True\n :return: dict\n "
] |
Please provide a description of the function:def is_running(self):
try:
return graceful_get(self.inspect(refresh=True), "State", "Running")
except subprocess.CalledProcessError:
return False | [
"\n returns True if the container is running\n\n :return: bool\n "
] |
Please provide a description of the function:def is_port_open(self, port, timeout=2):
addresses = self.get_IPv4s()
if not addresses:
return False
return check_port(port, host=addresses[0], timeout=timeout) | [
"\n check if given port is open and receiving connections on container ip_address\n\n :param port: int, container port\n :param timeout: int, how many seconds to wait for connection; defaults to 2\n :return: True if the connection has been established inside timeout, False otherwise\n ... |
Please provide a description of the function:def wait_for_port(self, port, timeout=10, **probe_kwargs):
Probe(timeout=timeout, fnc=functools.partial(self.is_port_open, port), **probe_kwargs).run() | [
"\n block until specified port starts accepting connections, raises an exc ProbeTimeout\n if timeout is reached\n\n :param port: int, port number\n :param timeout: int or float (seconds), time to wait for establishing the connection\n :param probe_kwargs: arguments passed to Probe... |
Please provide a description of the function:def delete(self, force=False, **kwargs):
cmdline = ["podman", "rm", "--force" if force else "", self.get_name()]
run_cmd(cmdline) | [
"\n remove this container; kwargs indicate that some container runtimes\n might accept more parameters\n\n :param force: bool, if container engine supports this, force the functionality\n :return: None\n "
] |
Please provide a description of the function:def mount(self, mount_point=None):
cmd = ["podman", "mount", self._id or self.get_id()]
output = run_cmd(cmd, return_output=True).rstrip("\n\r")
return output | [
"\n mount container filesystem\n\n :return: str, the location of the mounted file system\n "
] |
Please provide a description of the function:def umount(self, all=False, force=True):
# FIXME: handle error if unmount didn't work
options = []
if force:
options.append('--force')
if all:
options.append('--all')
cmd = ["podman", "umount"] + option... | [
"\n unmount container filesystem\n :param all: bool, option to unmount all mounted containers\n :param force: bool, force the unmounting of specified containers' root file system\n :return: str, the output from cmd\n "
] |
Please provide a description of the function:def logs(self, follow=False):
# TODO: podman logs have different behavior than docker
follow = ["--follow"] if follow else []
cmdline = ["podman", "logs"] + follow + [self._id or self.get_id()]
output = run_cmd(cmdline, return_output=... | [
"\n Get logs from this container. Iterator has one log line followed by a newline in next item.\n The logs are NOT encoded (they are str, not bytes).\n\n Let's look at an example::\n\n image = conu.PodmanImage(\"fedora\", tag=\"27\")\n command = [\"bash\", \"-c\", \"for x ... |
Please provide a description of the function:def wait(self, timeout=None):
timeout = ["--interval=%s" % timeout] if timeout else []
cmdline = ["podman", "wait"] + timeout + [self._id or self.get_id()]
return run_cmd(cmdline, return_output=True) | [
"\n Block until the container stops, then return its exit code. Similar to\n the ``podman wait`` command.\n\n :param timeout: int, microseconds to wait before polling for completion\n :return: int, exit code\n "
] |
Please provide a description of the function:def execute(self, command):
logger.info("running command %s", command)
cmd = ["podman", "exec", self.get_id()] + command
output = run_cmd(cmd, return_output=True)
return output | [
"\n Execute a command in this container -- the container needs to be running.\n\n :param command: list of str, command to execute in the container\n :return: str\n "
] |
Please provide a description of the function:def get_metadata(self):
if self._metadata is None:
self._metadata = ContainerMetadata()
inspect_to_container_metadata(self._metadata, self.inspect(refresh=True), self.image)
return self._metadata | [
"\n Convert dictionary returned after podman inspect command into instance of ContainerMetadata class\n :return: ContainerMetadata, container metadata instance\n "
] |
Please provide a description of the function:def k8s_ports_to_metadata_ports(k8s_ports):
ports = []
for k8s_port in k8s_ports:
if k8s_port.protocol is not None:
ports.append("%s/%s" % (k8s_port.port, k8s_port.protocol.lower()))
else:
ports.append(str(k8s_port.port)... | [
"\n :param k8s_ports: list of V1ServicePort\n :return: list of str, list of exposed ports, example:\n - ['1234/tcp', '8080/udp']\n "
] |
Please provide a description of the function:def metadata_ports_to_k8s_ports(ports):
exposed_ports = []
for port in ports:
splits = port.split("/", 1)
port = int(splits[0])
protocol = splits[1].upper() if len(splits) > 1 else None
exposed_ports.append(client.V1ServicePort(... | [
"\n :param ports: list of str, list of exposed ports, example:\n - ['1234/tcp', '8080/udp']\n :return: list of V1ServicePort\n "
] |
Please provide a description of the function:def p(self, path):
if path.startswith("/"):
path = path[1:]
p = os.path.join(self.mount_point, path)
logger.debug("path = %s", p)
return p | [
"\n provide absolute path within the container\n\n :param path: path with container\n :return: str\n "
] |
Please provide a description of the function:def copy_from(self, src, dest):
p = self.p(src)
if os.path.isfile(p):
logger.info("copying file %s to %s", p, dest)
shutil.copy2(p, dest)
else:
logger.info("copying directory %s to %s", p, dest)
... | [
"\n copy a file or a directory from container or image to host system. If you are copying\n directories, the target directory must not exist (this function is using `shutil.copytree`\n to copy directories and that's a requirement of the function). In case the directory exists,\n OSError ... |
Please provide a description of the function:def read_file(self, file_path):
try:
with open(self.p(file_path)) as fd:
return fd.read()
except IOError as ex:
logger.error("error while accessing file %s: %r", file_path, ex)
raise ConuException("... | [
"\n read file specified via 'file_path' and return its content - raises an ConuException if\n there is an issue accessing the file\n\n :param file_path: str, path to the file to read\n :return: str (not bytes), content of the file\n "
] |
Please provide a description of the function:def get_file(self, file_path, mode="r"):
return open(self.p(file_path), mode=mode) | [
"\n provide File object specified via 'file_path'\n\n :param file_path: str, path to the file\n :param mode: str, mode used when opening the file\n :return: File instance\n "
] |
Please provide a description of the function:def file_is_present(self, file_path):
p = self.p(file_path)
if not os.path.exists(p):
return False
if not os.path.isfile(p):
raise IOError("%s is not a file" % file_path)
return True | [
"\n check if file 'file_path' is present, raises IOError if file_path\n is not a file\n\n :param file_path: str, path to the file\n :return: True if file exists, False if file does not exist\n "
] |
Please provide a description of the function:def directory_is_present(self, directory_path):
p = self.p(directory_path)
if not os.path.exists(p):
return False
if not os.path.isdir(p):
raise IOError("%s is not a directory" % directory_path)
return True | [
"\n check if directory 'directory_path' is present, raise IOError if it's not a directory\n\n :param directory_path: str, directory to check\n :return: True if directory exists, False if directory does not exist\n "
] |
Please provide a description of the function:def get_selinux_context(self, file_path):
# what if SELinux is not enabled?
p = self.p(file_path)
if not HAS_XATTR:
raise RuntimeError("'xattr' python module is not available, hence we cannot "
"dete... | [
"\n Get SELinux file context of the selected file.\n\n :param file_path: str, path to the file\n :return: str, name of the SELinux file context\n "
] |
Please provide a description of the function:def _wrapper(self, q, start):
try:
func_name = self.fnc.__name__
except AttributeError:
func_name = str(self.fnc)
logger.debug("Running \"%s\" with parameters: \"%s\":\t%s/%s"
% (func_name, str(sel... | [
"\n _wrapper checks return status of Probe.fnc and provides the result for process managing\n\n :param q: Queue for function results\n :param start: Time of function run (used for logging)\n :return: Return value or Exception\n "
] |
Please provide a description of the function:def transport_param(image):
transports = {SkopeoTransport.CONTAINERS_STORAGE: "containers-storage:",
SkopeoTransport.DIRECTORY: "dir:",
SkopeoTransport.DOCKER: "docker://",
SkopeoTransport.DOCKER_ARCHIVE: "docker... | [
" Parse DockerImage info into skopeo parameter\n\n :param image: DockerImage\n :return: string. skopeo parameter specifying image\n "
] |
Please provide a description of the function:def get_metadata(self, refresh=True):
if refresh or not self._metadata:
ident = self._id or self.name
if not ident:
raise ConuException(
"This container does not have a valid identifier.")
... | [
"\n return cached metadata by default\n\n :param refresh: bool, returns up to date metadata if set to True\n :return: dict\n "
] |
Please provide a description of the function:def is_running(self):
cmd = ["machinectl", "--no-pager", "status", self.name]
try:
subprocess.check_call(cmd)
return True
except subprocess.CalledProcessError as ex:
logger.info("nspawn container %s is not ... | [
"\n return True when container is running, otherwise return False\n\n :return: bool\n "
] |
Please provide a description of the function:def copy_from(self, src, dest):
logger.debug("copying %s from host to container at %s", src, dest)
cmd = ["machinectl", "--no-pager", "copy-from", self.name, src, dest]
run_cmd(cmd) | [
"\n copy a file or a directory from container or image to host system.\n\n :param src: str, path to a file or a directory within container or image\n :param dest: str, path to a file or a directory on host system\n :return: None\n "
] |
Please provide a description of the function:def _wait_until_machine_finish(self):
self.image._wait_for_machine_finish(self.name)
# kill main run process
self.start_process.kill()
# TODO: there are some backgroud processes, dbus async events or something similar, there is better... | [
"\n Internal method\n wait until machine finish and kill main process (booted)\n\n :return: None\n "
] |
Please provide a description of the function:def delete(self, force=False, volumes=False):
try:
self.image.rmi()
except ConuException as ime:
if not force:
raise ime
else:
pass | [
"\n delete underlying image\n\n :param force: bool - force delete, do not care about errors\n :param volumes: not used anyhow\n :return: None\n "
] |
Please provide a description of the function:def _run_systemdrun_decide(self):
if self.systemd_wait_support is None:
self.systemd_wait_support = "--wait" in run_cmd(
["systemd-run", "--help"], return_output=True)
return self.systemd_wait_support | [
"\n Internal method\n decide if it is possible to use --wait option to systemd\n for example RHEL7 does not support --wait option\n\n :return: bool\n "
] |
Please provide a description of the function:def _systemctl_wait_until_finish(self, machine, unit):
while True:
metadata = convert_kv_to_dict(
run_cmd(
["systemctl", "--no-pager", "show", "-M", machine, unit],
return_output=True))
... | [
"\n Internal method\n workaround for systemd-run without --wait option\n see _run_systemdrun_decide method\n\n :param machine:\n :param unit:\n :return:\n "
] |
Please provide a description of the function:def run_systemdrun(
self, command, internal_background=False, return_full_dict=False,
**kwargs):
internalkw = deepcopy(kwargs) or {}
original_ignore_st = internalkw.get("ignore_status", False)
original_return_st = inte... | [
"\n execute command via systemd-run inside container\n\n :param command: list of command params\n :param internal_background: not used now\n :param kwargs: pass params to subprocess\n :return: dict with result\n "
] |
Please provide a description of the function:def _wait_for_machine_booted(name, suffictinet_texts=None):
# TODO: rewrite it using probes module in utils
suffictinet_texts = suffictinet_texts or ["systemd-logind"]
# optionally use: "Unit: machine"
for foo in range(constants.DEFAU... | [
"\n Internal method\n wait until machine is ready, in common case means there is running systemd-logind\n\n :param name: str with machine name\n :param suffictinet_texts: alternative text to check in output\n :return: True or exception\n "
] |
Please provide a description of the function:def _internal_reschedule(callback, retry=3, sleep_time=constants.DEFAULT_SLEEP):
for foo in range(retry):
container_process = callback[0](callback[1], *callback[2], **callback[3])
time.sleep(sleep_time)
container_process.p... | [
"\n workaround method for internal_run_container method\n It sometimes fails because of Dbus or whatever, so try to start it moretimes\n\n :param callback: callback method list\n :param retry: how many times try to invoke command\n :param sleep_time: how long wait before subproces... |
Please provide a description of the function:def internal_run_container(name, callback_method, foreground=False):
if not foreground:
logger.info("Stating machine (boot nspawn container) {}".format(name))
# wait until machine is booted when running at background, unable to execut... | [
"\n Internal method what runs container process\n\n :param name: str - name of container\n :param callback_method: list - how to invoke container\n :param foreground: bool run in background by default\n :return: suprocess instance\n "
] |
Please provide a description of the function:def get_container_output(backend, image_name, command, image_tag="latest",
additional_opts=None):
image = backend.ImageClass(image_name, tag=image_tag)
# FIXME: use run_via_api and make this a generic function
c = image.run_via_binar... | [
"\n Create a throw-away container based on provided image and tag, run the supplied command in it\n and return output. The container is stopped and removed after it exits.\n\n :param backend: instance of DockerBackend\n :param image_name: str, name of the container image\n :param command: list of str... |
Please provide a description of the function:def delete(self):
body = client.V1DeleteOptions()
try:
status = self.api.delete_namespaced_service(self.name, self.namespace, body)
logger.info(
"Deleting Service %s in namespace: %s", self.name, self.namesp... | [
"\n delete service from the Kubernetes cluster\n :return: None\n "
] |
Please provide a description of the function:def get_status(self):
try:
api_response = self.api.read_namespaced_service_status(self.name, self.namespace)
except ApiException as e:
raise ConuException(
"Exception when calling Kubernetes API - read_namespa... | [
"\n get status of service\n :return: V1ServiceStatus,\n https://github.com/kubernetes-client/python/blob/master/kubernetes/docs/V1ServiceStatus.md\n "
] |
Please provide a description of the function:def create_in_cluster(self):
try:
self.api.create_namespaced_service(self.namespace, self.body)
except ApiException as e:
raise ConuException(
"Exception when calling Kubernetes API - create_namespaced_service:... | [
"\n call Kubernetes API and create this Service in cluster,\n raise ConuExeption if the API call fails\n :return: None\n "
] |
Please provide a description of the function:def pull(self):
for json_e in self.d.pull(repository=self.name, tag=self.tag, stream=True, decode=True):
logger.debug(json_e)
status = graceful_get(json_e, "status")
if status:
logger.info(status)
... | [
"\n Pull this image from registry. Raises an exception if the image is not found in\n the registry.\n\n :return: None\n "
] |
Please provide a description of the function:def push(self, repository=None, tag=None):
image = self
if repository or tag:
image = self.tag_image(repository, tag)
for json_e in self.d.push(repository=image.name, tag=image.tag, stream=True, decode=True):
logger... | [
"\n Push image to registry. Raise exception when push fail.\n :param repository: str, see constructor\n :param tag: str, see constructor\n :return: None\n "
] |
Please provide a description of the function:def using_transport(self, transport=None, path=None, logs=True):
if not transport:
return self
if self.transport == transport and self.path == path:
return self
path_required = [SkopeoTransport.DIRECTORY,
... | [
" change used transport\n\n :param transport: from where will be this image copied\n :param path in filesystem\n :param logs enable/disable\n :return: self\n "
] |
Please provide a description of the function:def save_to(self, image):
if not isinstance(image, self.__class__):
raise ConuException("Invalid target image type", type(image))
self.copy(image.name, image.tag,
target_transport=image.transport, target_path=image.path,... | [
" Save this image to another DockerImage\n\n :param image: DockerImage\n :return:\n "
] |
Please provide a description of the function:def load_from(self, image):
if not isinstance(image, self.__class__):
raise ConuException("Invalid source image type", type(image))
image.save_to(self) | [
" Load from another DockerImage to this one\n\n :param image:\n :return:\n "
] |
Please provide a description of the function:def skopeo_pull(self):
return self.copy(self.name, self.tag,
SkopeoTransport.DOCKER, SkopeoTransport.DOCKER_DAEMON)\
.using_transport(SkopeoTransport.DOCKER_DAEMON) | [
" Pull image from Docker to local Docker daemon using skopeo\n\n :return: pulled image\n "
] |
Please provide a description of the function:def skopeo_push(self, repository=None, tag=None):
return self.copy(repository, tag, SkopeoTransport.DOCKER_DAEMON, SkopeoTransport.DOCKER)\
.using_transport(SkopeoTransport.DOCKER) | [
" Push image from Docker daemon to Docker using skopeo\n\n :param repository: repository to be pushed to\n :param tag: tag\n :return: pushed image\n "
] |
Please provide a description of the function:def copy(self, repository=None, tag=None,
source_transport=None,
target_transport=SkopeoTransport.DOCKER,
source_path=None, target_path=None,
logs=True):
if not repository:
repository = self.nam... | [
" Copy this image\n\n :param repository to be copied to\n :param tag\n :param source_transport Transport\n :param target_transport Transport\n :param source_path needed to specify for dir, docker-archive or oci transport\n :param target_path needed to specify for dir, docke... |
Please provide a description of the function:def tag_image(self, repository=None, tag=None):
if not (repository or tag):
raise ValueError("You need to specify either repository or tag.")
r = repository or self.name
t = "latest" if not tag else tag
self.d.tag(image=se... | [
"\n Apply additional tags to the image or even add a new name\n\n :param repository: str, see constructor\n :param tag: str, see constructor\n :return: instance of DockerImage\n "
] |
Please provide a description of the function:def inspect(self, refresh=True):
if refresh or not self._inspect_data:
identifier = self._id or self.get_full_name()
if not identifier:
raise ConuException("This image does not have a valid identifier.")
se... | [
"\n provide metadata about the image; flip refresh=True if cached metadata are enough\n\n :param refresh: bool, update the metadata with up to date content\n :return: dict\n "
] |
Please provide a description of the function:def rmi(self, force=False, via_name=False):
self.d.remove_image(self.get_full_name() if via_name else self.get_id(), force=force) | [
"\n remove this image\n\n :param force: bool, force removal of the image\n :param via_name: bool, refer to the image via name, if false, refer via ID\n :return: None\n "
] |
Please provide a description of the function:def _run_container(self, run_command_instance, callback):
tmpfile = os.path.join(get_backend_tmpdir(), random_tmp_filename())
# the cid file must not exist
run_command_instance.options += ["--cidfile=%s" % tmpfile]
logger.debug("docke... | [
" this is internal method "
] |
Please provide a description of the function:def run_via_binary(self, run_command_instance=None, command=None, volumes=None,
additional_opts=None, **kwargs):
logger.info("run container via binary in background")
if (command is not None or additional_opts is not None) \
... | [
"\n create a container using this image and run it in background;\n this method is useful to test real user scenarios when users invoke containers using\n binary\n\n :param run_command_instance: instance of DockerRunBuilder\n :param command: list of str, command to run in the cont... |
Please provide a description of the function:def run_via_binary_in_foreground(
self, run_command_instance=None, command=None, volumes=None,
additional_opts=None, popen_params=None, container_name=None):
logger.info("run container via binary in foreground")
if (command i... | [
"\n Create a container using this image and run it in foreground;\n this method is useful to test real user scenarios when users invoke containers using\n binary and pass input into the container via STDIN. You are also responsible for:\n\n * redirecting STDIN when intending to use cont... |
Please provide a description of the function:def run_via_api(self, container_params=None):
if not container_params:
container_params = DockerContainerParameters()
# Host-specific configuration
host_config = self.d.create_host_config(auto_remove=container_params.remove,
... | [
"\n create a container using this image and run it in background via Docker-py API.\n https://docker-py.readthedocs.io/en/stable/api.html\n Note: If you are using Healthchecks, be aware that support of some options were introduced\n just with version of Docker-py API 1.29\n :param... |
Please provide a description of the function:def run_in_pod(self, namespace="default"):
core_api = get_core_api()
image_data = self.get_metadata()
pod = Pod.create(image_data)
try:
pod_instance = core_api.create_namespaced_pod(namespace=namespace, body=pod)
... | [
"\n run image inside Kubernetes Pod\n :param namespace: str, name of namespace where pod will be created\n :return: Pod instance\n "
] |
Please provide a description of the function:def has_pkgs_signed_with(self, allowed_keys):
if not allowed_keys or not isinstance(allowed_keys, list):
raise ConuException("allowed_keys must be a list")
command = ['rpm', '-qa', '--qf', '%{name} %{SIGPGP:pgpsig}\n']
cont = sel... | [
"\n Check signature of packages installed in image.\n Raises exception when\n\n * rpm binary is not installed in image\n * parsing of rpm fails\n * there are packages in image that are not signed with one of allowed keys\n\n :param allowed_keys: list of allowed keys\n ... |
Please provide a description of the function:def build(cls, path, tag=None, dockerfile=None):
if not path:
raise ConuException('Please specify path to the directory containing the Dockerfile')
client = get_client()
response = [line for line in client.build(path,
... | [
"\n Build the image from the provided dockerfile in path\n\n :param path : str, path to the directory containing the Dockerfile\n :param tag: str, A tag to add to the final image\n :param dockerfile: str, path within the build context to the Dockerfile\n :return: instance of Docke... |
Please provide a description of the function:def get_layer_ids(self, rev=True):
layers = [x['Id'] for x in self.d.history(self.get_id())]
if not rev:
layers.reverse()
return layers | [
"\n Get IDs of image layers\n\n :param rev: get layers reversed\n :return: list of strings\n "
] |
Please provide a description of the function:def layers(self, rev=True):
image_layers = [
DockerImage(None, identifier=x, pull_policy=DockerImagePullPolicy.NEVER)
for x in self.get_layer_ids()
]
if not rev:
image_layers.reverse()
return image_... | [
"\n Get list of DockerImage for every layer in image\n\n :param rev: get layers rev\n :return: list of DockerImages\n "
] |
Please provide a description of the function:def extend(self, source, new_image_name, s2i_args=None):
s2i_args = s2i_args or []
c = self._s2i_command(["build"] + s2i_args + [source, self.get_full_name()])
if new_image_name:
c.append(new_image_name)
try:
r... | [
"\n extend this s2i-enabled image using provided source, raises ConuException if\n `s2i build` fails\n\n :param source: str, source used to extend the image, can be path or url\n :param new_image_name: str, name of the new, extended image\n :param s2i_args: list of str, additional... |
Please provide a description of the function:def usage(self):
c = self._s2i_command(["usage", self.get_full_name()])
with open(os.devnull, "w") as fd:
process = subprocess.Popen(c, stdout=fd, stderr=subprocess.PIPE)
_, output = process.communicate()
retcode =... | [
"\n Provide output of `s2i usage`\n\n :return: str\n "
] |
Please provide a description of the function:def http_request(self, path="/", method="GET", host=None, port=None, json=False, data=None):
host = host or '127.0.0.1'
port = port or 8080
url = get_url(host=host, port=port, path=path)
return self.http_session.request(method, url,... | [
"\n perform a HTTP request\n\n :param path: str, path within the request, e.g. \"/api/version\"\n :param method: str, HTTP method\n :param host: str, if None, set to 127.0.0.1\n :param port: str or int, if None, set to 8080\n :param json: bool, should we expect json?\n ... |
Please provide a description of the function:def deploy_image(self, image_name, oc_new_app_args=None, project=None, name=None):
self.project = project or self.get_current_project()
# app name is generated randomly
name = name or 'app-{random_string}'.format(random_string=random_str(5))... | [
"\n Deploy image in OpenShift cluster using 'oc new-app'\n :param image_name: image name with tag\n :param oc_new_app_args: additional parameters for the `oc new-app`, env variables etc.\n :param project: project where app should be created, default: current project\n :param name:... |
Please provide a description of the function:def create_new_app_from_source(self, image_name, project=None,
source=None, oc_new_app_args=None):
self.project = project or self.get_current_project()
# app name is generated randomly
name = 'app-{random_s... | [
"\n Deploy app using source-to-image in OpenShift cluster using 'oc new-app'\n :param image_name: image to be used as builder image\n :param project: project where app should be created, default: current project\n :param source: source used to extend the image, can be path or url\n ... |
Please provide a description of the function:def create_app_from_template(self, image_name, name, template, name_in_template,
other_images=None, oc_new_app_args=None, project=None):
self.project = project or self.get_current_project()
oc_new_app_args = oc_new_ap... | [
"\n Helper function to create app from template\n :param image_name: image to be used as builder image\n :param name: name of app from template\n :param template: str, url or local path to a template to use\n :param name_in_template: dict, {repository:tag} image name used in the t... |
Please provide a description of the function:def start_build(self, build, args=None):
args = args or []
c = self._oc_command(["start-build"] + [build] + args)
logger.info("Executing build %s", build)
logger.info("Build command: %s", " ".join(c))
try:
Prob... | [
"\n Start new build, raise exception if build failed\n :param build: str, name of the build\n :param args: list of str, another args of 'oc start-build' commands\n :return: None\n "
] |
Please provide a description of the function:def get_image_registry_url(self, image_name):
c = self._oc_command(["get", "is", image_name,
"--output=jsonpath=\'{ .status.dockerImageRepository }\'"])
try:
internal_registry_name = run_cmd(c, return_output=... | [
"\n Helper function for obtain registry url of image from it's name\n :param image_name: str, short name of an image, example:\n - conu:0.5.0\n :return: str, image registry url, example:\n - 172.30.1.1:5000/myproject/conu:0.5.0\n "
] |
Please provide a description of the function:def import_image(self, imported_image_name, image_name):
c = self._oc_command(["import-image", imported_image_name,
"--from=%s" % image_name, "--confirm"])
logger.info("Importing image from: %s, as: %s", image_name, im... | [
"\n Import image using `oc import-image` command.\n :param imported_image_name: str, short name of an image in internal registry, example:\n - hello-openshift:latest\n :param image_name: full repository name, example:\n - docker.io/openshift/hello-openshift:latest\n ... |
Please provide a description of the function:def request_service(self, app_name, port, expected_output=None):
# get ip of service
ip = [service.get_ip() for service in self.list_services(namespace=self.project)
if service.name == app_name][0]
# make http request to obtai... | [
"\n Make request on service of app. If there is connection error function return False.\n :param app_name: str, name of the app\n :param expected_output: str, If not None method will check output returned from request\n and try to find matching string.\n :param port: str or... |
Please provide a description of the function:def wait_for_service(self, app_name, port, expected_output=None, timeout=100):
logger.info('Waiting for service to get ready')
try:
Probe(timeout=timeout, pause=10, fnc=self.request_service, app_name=app_name,
port=port... | [
"\n Block until service is not ready to accept requests,\n raises an exc ProbeTimeout if timeout is reached\n :param app_name: str, name of the app\n :param port: str or int, port of the service\n :param expected_output: If not None method will check output returned from request\n... |
Please provide a description of the function:def all_pods_are_ready(self, app_name):
app_pod_exists = False
for pod in self.list_pods(namespace=self.project):
if app_name in pod.name and 'build' not in pod.name and 'deploy' not in pod.name:
app_pod_exists = True
... | [
"\n Check if all pods are ready for specific app\n :param app_name: str, name of the app\n :return: bool\n "
] |
Please provide a description of the function:def get_status(self):
try:
c = self._oc_command(["status"])
o = run_cmd(c, return_output=True)
for line in o.split('\n'):
logger.debug(line)
return o
except subprocess.CalledProcessError... | [
"\n Get status of OpenShift cluster, similar to `oc status`\n :return: str\n "
] |
Please provide a description of the function:def get_logs(self, name):
logs = self.get_status()
for pod in self.list_pods(namespace=self.project):
if name in pod.name: # get just logs from pods related to app
pod_logs = pod.get_logs()
if pod_logs:
... | [
"\n Obtain cluster status and logs from all pods and print them using logger.\n This method is useful for debugging.\n :param name: str, name of app generated by oc new-app\n :return: str, cluster status and logs from all pods\n "
] |
Please provide a description of the function:def get_current_project(self):
try:
command = self._oc_command(["project", "-q"])
output = run_cmd(command, return_output=True)
except subprocess.CalledProcessError as ex:
raise ConuException("Failed to obtain cur... | [
"\n Get name of current project using `oc project` command.\n Raise ConuException in case of an error.\n :return: str, project name\n "
] |
Please provide a description of the function:def clean_project(self, app_name=None, delete_all=False):
if not app_name and not delete_all:
ConuException("You need to specify either app_name or set delete_all=True")
if delete_all:
args = ["--all"]
logger.inf... | [
"\n Delete objects in current project in OpenShift cluster. If both parameters are passed,\n delete all objects in project.\n :param app_name: str, name of app\n :param delete_all: bool, if true delete all objects in current project\n :return: None\n "
] |
Please provide a description of the function:def system_requirements():
command_exists("systemd-nspawn",
["systemd-nspawn", "--version"],
"Command systemd-nspawn does not seems to be present on your system"
"Do you have system with systemd")
command_exists(
... | [
"\n Check if all necessary packages are installed on system\n\n :return: None or raise exception if some tooling is missing\n "
] |
Please provide a description of the function:def _generate_id(self):
name = self.name.replace(self.special_separator, "-").replace(".", "-")
loc = "\/"
if self.location:
loc = self.location
_id = "{PREFIX}{SEP}{NAME}{HASH}{SEP}".format(
PREFIX=constants.C... | [
" create new unique identifier "
] |
Please provide a description of the function:def pull(self):
if not os.path.exists(CONU_IMAGES_STORE):
os.makedirs(CONU_IMAGES_STORE)
logger.debug(
"Try to pull: {} -> {}".format(self.location, self.local_location))
if not self._is_local():
compresse... | [
"\n Pull this image from URL.\n\n :return: None\n "
] |
Please provide a description of the function:def create_snapshot(self, name, tag):
source = self.local_location
logger.debug("Create Snapshot: %s -> %s" % (source, name))
# FIXME: actually create the snapshot via clone command
if name and tag:
output_tag = "{}:{}".fo... | [
"\n Create new instance of image with snaphot image (it is copied inside class constructuor)\n\n :param name: str - name of image - not used now\n :param tag: str - tag for image\n :return: NspawnImage instance\n "
] |
Please provide a description of the function:def get_metadata(self, refresh=True):
if refresh or not self._metadata:
ident = self._id or self.get_full_name()
if not ident:
raise ConuException(
"This image does not have a valid identifier.")
... | [
"\n return cached metadata by default\n\n :param refresh: bool, update the metadata with up to date content\n :return: dict\n "
] |
Please provide a description of the function:def rmi(self, force=False, via_name=False):
return os.remove(self.local_location) | [
"\n remove this image\n\n :param force: bool, force removal of the image\n :param via_name: bool, refer to the image via name, if false, refer via ID, not used now\n :return: None\n "
] |
Please provide a description of the function:def _wait_for_machine_finish(self, name):
# TODO: rewrite it using probes module in utils
for foo in range(constants.DEFAULT_RETRYTIMEOUT):
time.sleep(constants.DEFAULT_SLEEP)
out = run_cmd(
["machinectl", "--n... | [
"\n Interna method\n wait until machine is really destroyed, machine does not exist.\n :param name: str machine name\n :return: True or exception\n "
] |
Please provide a description of the function:def run_via_binary(self, command=None, foreground=False, volumes=None,
additional_opts=None, default_options=None, name=None, *args, **kwargs):
command = deepcopy(command) or []
volumes = deepcopy(volumes) or []
additional_opts = ... | [
"\n Create new instance NspawnContianer in case of not running at foreground, in case foreground run, return process\n object\n\n :param command: list - command to run\n :param foreground: bool - run process at foreground\n :param volumes: list - put additional bind mounts\n ... |
Please provide a description of the function:def run_foreground(self, *args, **kwargs):
return self.run_via_binary(foreground=True, default_options=[], *args, **kwargs) | [
"\n Force to run process at foreground\n :param args: pass args to run command\n :param kwargs: pass args to run command\n :return: process or NspawnContianer instance\n "
] |
Please provide a description of the function:def bootstrap(
repositories, name, packages=None, additional_packages=None,
tag="latest", prefix=constants.CONU_ARTIFACT_TAG, packager=None):
additional_packages = additional_packages or []
if packages is None:
pac... | [
"\n bootstrap Image from scratch. It creates new image based on giver dnf repositories and package setts\n\n :param repositories:list of repositories\n :param packages: list of base packages in case you don't want to use base packages defined in contants\n :param additional_packages: lis... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.