Lines Matching full:container
27 # Naming convention of test container, e.g., test_300_1422862512_2424, where:
29 # 1422862512: The tick when container is created.
30 # 2424: The PID of autoserv that starts the container.
32 # Name of the container ID file.
52 @param path: Path to a directory where the container ID will be
63 @param path: Path to check for a serialized container ID.
65 @return: A container ID if one is found on the given path, or None
82 # container ids have migrated to str.
89 """Creates a new container ID.
106 class Container(object): class
107 """A wrapper class of an LXC container.
109 The wrapper class provides methods to interact with a container, e.g.,
111 container, including:
112 name: Name of the container.
113 state: State of the container, e.g., ABORTING, RUNNING, STARTING, STOPPED,
116 lxc-ls can also collect other attributes of a container including:
119 autostart: If the container will autostart at system boot.
120 pid: Process ID of the container.
121 memory: Memory used by the container, as a string, e.g., "6.2MB"
122 ram: Physical ram used by the container, as a string, e.g., "6.2MB"
123 swap: swap used by the container, as a string, e.g., "1.0MB"
134 """Initialize an object of LXC container with given attribute values.
136 @param container_path: Directory that stores the container.
137 @param name: Name of the container.
139 container.
140 @param src: An optional source container. If provided, the source
141 continer is cloned, and the new container will point to the
143 @param snapshot: If a source container was specified, this argument
150 # Path to the rootfs of the container. This will be initialized when
157 # Clone the container
159 # Clone the source container to initialize this one.
165 # This may be an existing container. Try to read the ID.
171 # container quite frequently, and emitting exceptions here would
178 # provide APIs for checking if a container is in this state?
179 logging.exception('Error loading ID for container %s:',
183 if not Container._LXC_VERSION:
184 Container._LXC_VERSION = lxc_utils.get_lxc_version()
189 """Creates a new container instance for an lxc container that already
192 @param lxc_path: The LXC path for the container.
193 @param name: The container name.
195 @raise error.ContainerError: If the container doesn't already exist.
197 @return: The new container.
203 # container. The ID is the actual key that is used to identify the
204 # container to the autoserv system. In the case of a JIT-created container,
205 # we have the ID at the container's creation time so we use that to name the
206 # container. This may not be the case for other types of containers.
210 """Creates a clone of this container.
212 @param src: The original container.
213 @param new_name: Name for the cloned container. If this is not
214 provided, a random unique container name will be
216 @param new_path: LXC path for the cloned container (optional; if not
217 specified, the new container is created in the same
218 directory as the source container).
223 @param cleanup: If a container with the given name and path already
231 tempfile.mkdtemp(dir=new_path, prefix='container.'))
232 logging.debug('Generating new name for container: %s', new_name)
234 # If a container exists at this location, clean it up first
238 raise error.ContainerError('Container %s already exists.' %
240 container = Container.create_from_existing_dir(new_path,
243 container.destroy()
245 # The container could be created in a incompleted
246 # state. Delete the container folder instead.
247 logging.warn('Failed to destroy container %s, error: %s',
250 # Create the directory prior to creating the new container. This
251 # puts the ownership of the container under the current process's
256 # Create and return the new container.
263 """Refresh the status information of the container.
268 'No container found in directory %s with name of %s.' %
277 """Path to the rootfs of the container.
279 This property returns the path to the rootfs of the container, that is,
280 the folder where the container stores its local files. It reads the
281 attribute lxc.rootfs from the config file of the container, e.g.,
283 If the container is created with snapshot, the rootfs is a chain of
291 Files in the rootfs will be accessible directly within container. For
293 inside container by path "/usr/local/file1". Note that symlink in the
294 host can not across host/container boundary, instead, directory mount
297 @return: Path to the rootfs of the container.
301 if Container._LXC_VERSION:
302 logging.info("Detected lxc version %s", Container._LXC_VERSION)
303 if Container._LXC_VERSION[0] >= 3:
316 """Attach to a given container and run the given command.
318 @param command: Command to run in the container.
324 @raise error.CmdError: If container does not exist, or not running.
331 # container can be unprivileged container.
336 """Check if network is up in the container by curl base container url.
351 """Start the container.
356 @raise ContainerError: If container does not exist, or fails to start.
362 'Container %s failed to start. lxc command output:\n%s' %
380 """Stop the container.
382 @raise ContainerError: If container does not exist, or fails to start.
389 'Container %s failed to be stopped. lxc command output:\n'
397 """Destroy the container.
399 @param force: Set to True to force to destroy the container even if it's
400 running. This is faster than stop a container first then
403 @raise ContainerError: If container does not exist or failed to destroy
404 the container.
406 logging.debug('Destroying container %s/%s',
417 """Mount a directory in host to a directory in the container.
420 @param destination: Directory in container to mount the source directory
423 # Destination path in container must be relative.
425 # Create directory in container for mount. Changes to container rootfs
433 """Verify autotest code is set up properly in the container.
455 # TODO(dshi): Remove this code after lab container is updated with
466 container: /usr/local/lib/python2.7/dist-packages/. The modules include
470 When pip is installed inside the container, it installs requests module
492 """Returns whether or not this container is currently running."""
498 """Sets the hostname within the container.
500 This method can only be called on a running container.
502 @param hostname The new container hostname.
504 @raise ContainerError: If the container is not running.
524 # Changes within the container rootfs require sudo.
562 The given file will be copied into the container.
572 """Copies files into the container.
575 @param container_path: Path to the destination dir (in the container).
584 """Returns the container ID."""
590 """Sets the container ID."""
592 # Persist the ID so other container objects can pick it up.
613 """Sets an LXC config value for this container.
615 Configuration changes made while a container is running don't take
616 effect until the container is restarted. Since this isn't a scenario
618 running container will cause a ContainerError.
623 @raise error.ContainerError: If the container is already started.
627 '_set_lxc_config(%s, %s) called on a running container.' %
636 """Retrieves an LXC config value from the container.
648 'Config %s not found for container %s. (%s)' %