Lines Matching full:container
31 # Naming convention of test container, e.g., test_300_1422862512_2424, where:
33 # 1422862512: The tick when container is created.
34 # 2424: The PID of autoserv that starts the container.
36 # Name of the container ID file.
59 @param path: Path to a directory where the container ID will be
67 logging.debug('Container id saved to %s (content: %s)', dst,
74 @param path: Path to check for a serialized container ID.
76 @return: A container ID if one is found on the given path, or None
91 logging.warning('Load container id file "%s" error: %s', src, err)
94 # container ids have migrated to str.
101 """Creates a new container ID.
118 class Container(object): class
119 """A wrapper class of an LXC container.
121 The wrapper class provides methods to interact with a container, e.g.,
123 container, including:
124 name: Name of the container.
125 state: State of the container, e.g., ABORTING, RUNNING, STARTING, STOPPED,
128 lxc-ls can also collect other attributes of a container including:
131 autostart: If the container will autostart at system boot.
132 pid: Process ID of the container.
133 memory: Memory used by the container, as a string, e.g., "6.2MB"
134 ram: Physical ram used by the container, as a string, e.g., "6.2MB"
135 swap: swap used by the container, as a string, e.g., "1.0MB"
146 """Initialize an object of LXC container with given attribute values.
148 @param container_path: Directory that stores the container.
149 @param name: Name of the container.
151 container.
152 @param src: An optional source container. If provided, the source
153 continer is cloned, and the new container will point to the
155 @param snapshot: If a source container was specified, this argument
162 # Path to the rootfs of the container. This will be initialized when
169 # Clone the container
171 # Clone the source container to initialize this one.
177 # This may be an existing container. Try to read the ID.
181 logging.debug('Container %s has id: "%s"', self.name, self._id)
184 # container quite frequently, and emitting exceptions here would
187 logging.warning('Unable to determine ID for container %s:',
191 if not Container._LXC_VERSION:
192 Container._LXC_VERSION = lxc_utils.get_lxc_version()
197 """Creates a new container instance for an lxc container that already
200 @param lxc_path: The LXC path for the container.
201 @param name: The container name.
203 @raise error.ContainerError: If the container doesn't already exist.
205 @return: The new container.
211 # container. The ID is the actual key that is used to identify the
212 # container to the autoserv system. In the case of a JIT-created container,
213 # we have the ID at the container's creation time so we use that to name the
214 # container. This may not be the case for other types of containers.
218 """Creates a clone of this container.
220 @param src: The original container.
221 @param new_name: Name for the cloned container. If this is not
222 provided, a random unique container name will be
224 @param new_path: LXC path for the cloned container (optional; if not
225 specified, the new container is created in the same
226 directory as the source container).
231 @param cleanup: If a container with the given name and path already
239 tempfile.mkdtemp(dir=new_path, prefix='container.'))
240 logging.debug('Generating new name for container: %s', new_name)
242 # If a container exists at this location, clean it up first
246 raise error.ContainerError('Container %s already exists.' %
248 container = Container.create_from_existing_dir(new_path,
251 container.destroy()
253 # The container could be created in a incompleted
254 # state. Delete the container folder instead.
255 logging.warning('Failed to destroy container %s, error: %s',
258 # Create the directory prior to creating the new container. This
259 # puts the ownership of the container under the current process's
264 # Create and return the new container.
271 """Refresh the status information of the container.
276 'No container found in directory %s with name of %s.' %
285 """Path to the rootfs of the container.
287 This property returns the path to the rootfs of the container, that is,
288 the folder where the container stores its local files. It reads the
289 attribute lxc.rootfs from the config file of the container, e.g.,
291 If the container is created with snapshot, the rootfs is a chain of
299 Files in the rootfs will be accessible directly within container. For
301 inside container by path "/usr/local/file1". Note that symlink in the
302 host can not across host/container boundary, instead, directory mount
305 @return: Path to the rootfs of the container.
309 if Container._LXC_VERSION:
310 logging.info("Detected lxc version %s", Container._LXC_VERSION)
311 if Container._LXC_VERSION[0] >= 3:
324 """Attach to a given container and run the given command.
326 @param command: Command to run in the container.
332 @raise error.CmdError: If container does not exist, or not running.
339 # container can be unprivileged container.
344 """Check if network is up in the container by curl base container url.
369 """Start the container.
374 @raise ContainerError: If container does not exist, or fails to start.
387 'Container %s failed to start. lxc command output:\n%s' %
412 """Stop the container.
414 @raise ContainerError: If container does not exist, or fails to start.
421 'Container %s failed to be stopped. lxc command output:\n'
429 """Destroy the container.
431 @param force: Set to True to force to destroy the container even if it's
432 running. This is faster than stop a container first then
435 @raise ContainerError: If container does not exist or failed to destroy
436 the container.
438 logging.debug('Destroying container %s/%s',
445 """Mount a directory in host to a directory in the container.
448 @param destination: Directory in container to mount the source directory
451 # Destination path in container must be relative.
453 # Create directory in container for mount. Changes to container rootfs
461 """Verify autotest code is set up properly in the container.
483 # TODO(dshi): Remove this code after lab container is updated with
494 container: /usr/local/lib/python2.7/dist-packages/. The modules include
498 When pip is installed inside the container, it installs requests module
520 """Returns whether or not this container is currently running."""
526 """Sets the hostname within the container.
528 This method can only be called on a running container.
530 @param hostname The new container hostname.
532 @raise ContainerError: If the container is not running.
552 # Changes within the container rootfs require sudo.
561 The given file will be copied into the container.
571 """Copies files into the container.
574 @param container_path: Path to the destination dir (in the container).
583 """Returns the container ID."""
589 """Sets the container ID."""
591 # Persist the ID so other container objects can pick it up.
612 """Sets an LXC config value for this container.
614 Configuration changes made while a container is running don't take
615 effect until the container is restarted. Since this isn't a scenario
617 running container will cause a ContainerError.
622 @raise error.ContainerError: If the container is already started.
626 '_set_lxc_config(%s, %s) called on a running container.' %
635 """Retrieves an LXC config value from the container.
647 'Config %s not found for container %s. (%s)' %