common.py revision 2616
2339N/A# The contents of this file are subject to the terms of the 2339N/A# Common Development and Distribution License (the "License"). 2339N/A# You may not use this file except in compliance with the License. 2339N/A# See the License for the specific language governing permissions 2339N/A# and limitations under the License. 2339N/A# When distributing Covered Code, include this CDDL HEADER in each 2339N/A# If applicable, add the following below this CDDL HEADER, with the 2339N/A# fields enclosed by brackets "[]" replaced with your own identifying 2339N/A# information: Portions Copyright [yyyy] [name of copyright owner] 2616N/A# Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. 2339N/ALinked image module classes. 2339N/AThe following classes for manipulating linked images are defined here: 2339N/AThe following template classes which linked image plugins should inherit from 2339N/A# Too many lines in module; pylint: disable-msg=C0302 2339N/A# linked image relationship types (returned by LinkedImage.list_related()) 2339N/A# properties that never get saved 2339N/A# special linked image name values (PROP_NAME) 2339N/A# linked image model values (PROP_MODEL) 2339N/A# files which contain linked image data 2339N/A """This class is a template that all linked image plugins should 2339N/A inherit from. Linked image plugins derived from this class are 2339N/A designed to manage linked aspects of the current image (vs managing 2339N/A linked aspects of a specific child of the current image). 2339N/A All the interfaces exported by this class and its descendants are 2339N/A private to the linked image subsystem and should not be called 2339N/A directly by any other subsystem.""" 2339N/A """Initialize a linked image plugin. 2339N/A 'pname' is the name of the plugin class derived from this 2339N/A 'linked' is the LinkedImage object initializing this plugin. 2339N/A """Called when the path to the image that we're operating on 2339N/A is changing. This normally occurs when we clone an image 2339N/A after we've planned and prepared to do an operation.""" 2339N/A """If the linked image plugin is able to detect that we're 2339N/A operating on an image in an alternate root then return the 2339N/A path of the alternate root.""" 2339N/A # return value: string or None 2339N/A """Return a list of the child images associated with the 2339N/A """Get the linked image properties associated with the 2339N/A """Attach the specified child image. This operation should 2339N/A only affect in-memory state of the current image. It should 2339N/A not update any persistent on-disk linked image state or access 2339N/A the child image in any way. This routine should assume that 2339N/A the linked image properties have already been validated.""" 2339N/A """Detach the specified child image. This operation should 2339N/A only affect in-memory state of the current image. It should 2339N/A not update any persistent on-disk linked image state or access 2339N/A the child image in any way.""" 2339N/A """Sync out the in-memory linked image state of this image to 2339N/A # (pkgdefs EXIT_* return value, exception object or None) 2339N/A """This class is a template that all linked image child plugins should 2339N/A inherit from. Linked image child plugins derived from this class are 2339N/A designed to manage linked aspects of children of the current image. 2339N/A (vs managing linked aspects of the current image itself). 2339N/A All the interfaces exported by this class and its descendants are 2339N/A private to the linked image subsystem and should not be called 2339N/A directly by any other subsystem.""" 2339N/A """Initialize a linked image child plugin. 2339N/A 'lic' is the LinkedImageChild object initializing this plugin. 2339N/A """Called before a parent image saves linked image properties 2339N/A into a child image. Gives the linked image child plugin a 2339N/A chance to update the properties that will be saved within the 2339N/A """A class for naming child linked images. Linked image names are 2339N/A used for all child images (and only child images), and they encode two 2339N/A pieces of information. The name of the plugin used to manage the 2339N/A image and a linked image name. Linked image names have the following 2339N/A format "<linked_image_plugin>:<linked_image_name>""" 2339N/A """A LinkedImage object is used to manage the linked image aspects of 2339N/A an image. This image could be a child image, a parent image, or both 2339N/A a parent and child. This object allows for access to linked image 2339N/A properties and also provides routines that allow operations to be 2339N/A performed on child images.""" 2339N/A # Too many instance attributes; pylint: disable-msg=R0902 2339N/A # Too many public methods; pylint: disable-msg=R0904 2339N/A # Properties that a parent image with push children should save locally. 2339N/A # Properties that a pull child image should save locally. 2339N/A # Properties that a parent image with push children should save in 2339N/A # make sure there is no invalid overlap 2339N/A """Initialize a new LinkedImage object.""" 2339N/A # variables reset by self.__update_props() 2339N/A # variables reset by self.reset_recurse() 2339N/A # variables reset by self._init_root() 2339N/A # initialize with no properties 2339N/A # initialize linked image plugin objects 2339N/A # if the image has a path setup, we can load data from it. 2339N/A """Get a pointer to the image object associated with this 2339N/A """Called during object initialization and by 2339N/A root location of the image. (The only time we change the root 2339N/A path is when changes BEs during operations which clone BEs. 2339N/A So when this happens most our metadata shouldn't actually 2339N/A # save the old root image path 2339N/A # figure out the new root image path 2339N/A # initialize paths for linked image data files 2339N/A # if this isn't a reset, then load data from the image 2339N/A # we're not linked or we're not changing root paths we're done 2339N/A # get the old altroot directory 2339N/A # update the altroot property 2339N/A # Tell linked image plugins about the updated paths 2339N/A # Unused variable 'plugin'; pylint: disable-msg=W0612 2339N/A # Tell linked image children about the updated paths 2339N/A """Internal helper routine used when we want to update any 2339N/A linked image properties. This routine sanity check the 2339N/A new properties, updates them, and resets any cached state 2339N/A that is affected by property values.""" 2339N/A # all temporal properties must exist 2339N/A """Perform internal consistency checks for a set of linked 2339N/A image properties. Don't update any state.""" 2339N/A # if we're not a child image ourselves, then we're done 2339N/A # make sure PROP_MODEL was specified 2339N/A # validate the linked image name 2339N/A # make sure PROP_MODEL was specified 2339N/A """Given a set of linked image properties, strip out any 2339N/A altroot properties. This involves removing the altroot 2339N/A component from the image path property. This is normally done 2339N/A before we write image properties to disk.""" 2339N/A # remove it from the image path 2339N/A # remove it from the parent image path 2339N/A # delete the current altroot 2339N/A """Given a set of linked image properties, the image paths 2339N/A stored within those properties may not match the actual image 2339N/A paths if we're executing within an alternate root environment. 2339N/A We try to detect this condition here, and if this situation 2339N/A occurs we update the linked image paths to reflect the current 2339N/A image paths and we fabricate a new linked image altroot 2339N/A property that points to the new path prefix that was 2339N/A pre-pended to the image paths.""" 2339N/A # we may have to update the parent image path as well 2339N/A # remove the altroot from the image paths 2339N/A # update properties with altroot 2339N/A """If we're initializing parent linked image properties for 2339N/A the first time (or if those properties somehow got deleted) 2339N/A then we need to know if the parent image that we're currently 2339N/A operating on is located within an alternate root. One way to 2339N/A do this is to ask our linked image plugins if they can 2339N/A determine this (the zones linked image plugin usually can 2339N/A if the image is a global zone).""" 2339N/A # ask each plugin if we're operating in an alternate root 2339N/A # no altroot suggested by plugins 2339N/A # check for conflicting altroots 2339N/A # Unused variable; pylint: disable-msg=W0612 2339N/A # we have an altroot from our plugins 2339N/A # we have conflicting altroots, time to die 2339N/A """Fabricate the minimum set of properties required for a 2339N/A """Load linked image properties from disk and return them to 2339N/A the caller. We sanity check the properties, but we don't 2339N/A update any internal linked image state. 2339N/A linked image metadata files, or if we should access temporary 2339N/A versions (which have ".<runid>" appended to them.""" 2339N/A # read the linked image properties from disk 2339N/A # make sure there are no saved temporal properties 2339N/A # convert PROP_NAME into a linked image name obj 2339N/A # sanity check our properties 2339N/A """Load linked image parent constraints from disk. 2339N/A Don't update any internal state. 2339N/A linked image metadata files, or if we should access temporary 2339N/A versions (which have ".<runid>" appended to them.""" 2339N/A """Load linked image parent publishers from disk. 2339N/A Don't update any internal state. 2339N/A linked image metadata files, or if we should access temporary 2339N/A versions (which have ".<runid>" appended to them.""" 2339N/A """Load linked image properties and constraints from disk. 2339N/A Update the linked image internal state with the loaded data.""" 2444N/A # Normally, if we're a parent image we'll have linked image 2444N/A # properties stored on disk. So load those now. 2444N/A # If no properties are loaded, we may still be a parent image 2444N/A # that is just missing it's metadata. (oops.) We attempt to 2444N/A # detect this situation by invoking __isparent(), which will 2444N/A # ask each child if there are any children. This is a best 2444N/A # effort attempt, so when we do this we ignore any plugin 2444N/A # runtime errors since we really want Image object 2444N/A # initialization to succeed. If we don't have any linked 2444N/A # image metadata, and we're having runtime errors querying for 2444N/A # children, then we'll allow initialization here, but any 2444N/A # subsequent operation that tries to access children will fail 2444N/A # and the caller will have to specify that they want to ignore 2444N/A # all children to allow the operation to succeed. 2444N/A # Oops. We're a parent image with no properties 2444N/A # stored on disk. Rather than throwing an exception 2444N/A # try to fabricate up some props with reasonably 2444N/A # guessed values which the user can subsequently 2339N/A # load parent publisher data. if publisher data is missing 2339N/A # continue along and we'll just skip the publisher checks, 2339N/A # it's better than failing and preventing any image updates. 2339N/A """Verify property value for PROP_RECURSE.""" 2339N/A """Validate user supplied linked image attach properties. 2339N/A Don't update any internal state.""" 2339N/A # make sure that only attach time options have been 2339N/A # specified, and that they have allowed values. 2339N/A # check each property the user specified. 2339N/A # did the user specify an allowable property? 2339N/A # did the user specify a valid property value? 2339N/A # is this property valid for this type of image? 2339N/A """Initialize an Image object which can be used to access a 2339N/A """Return the altroot path prefix for the current image.""" 2339N/A """If our in-memory linked image state matches the on-disk 2339N/A linked image state then there's nothing to do. If the state 2339N/A differs then there is stuff to do since the new state needs 2339N/A # compare in-memory and on-disk properties 2339N/A # compare in-memory and on-disk constraints 2339N/A # compare in-memory and on-disk parent publishers 2339N/A """Return publisher information for the specified image. If 2339N/A no image is specified we return publisher information for the 2339N/A Publisher information is returned in a sorted list of lists 2339N/A <publisher name> is a string 2339N/A The tuples are sorted by publisher rank. 2339N/A # get a sorted list of the images publishers 2339N/A """If we're a child image's, verify that the parent image 2339N/A publisher configuration is a subset of the child images 2339N/A publisher configuration. This means that all publishers 2339N/A configured within the parent image must also be configured 2339N/A within the child image with the same: 2339N/A - sticky and disabled settings 2339N/A The child image may have additional publishers configured but 2339N/A they must all be lower ranked than the parent's publishers. 2339N/A # if we're not a child image then bail 2339N/A # if we're using the sysrepo then don't bother 2339N/A # we don't need to do a pubcheck for detach 2339N/A # parent publisher data is missing, press on and hope 2339N/A # child image needs at least as many publishers as the parent 2339N/A # check rank, sticky, and disabled settings 2339N/A """Update linked image constraint, publisher data, and 2339N/A state from our parent image.""" 2339N/A # we're not a child image, nothing to do 2339N/A # parent pushes data to us, nothing to do 2339N/A # initalize the parent image 2339N/A # check if anything has changed 2339N/A # parent has new publishers 2339N/A # if we're not planning an image attach operation then write 2339N/A # the linked image metadata to disk. 2339N/A """Write in-memory linked image state to disk.""" 2339N/A # create a list of metadata file paths 2339N/A # cleanup any temporary files 2339N/A # we're no longer linked; delete metadata 2339N/A # save our properties, but first remove altroot path prefixes 2339N/A # and any temporal properties 2339N/A # if we're not a child we don't have constraints 2339N/A # we're a child so save our latest constraints 2339N/A """If the current image is a child image, this function 2339N/A returns a linked image name object which represents the name 2339N/A """Indicates whether the current image is a child image.""" 2444N/A """Indicates whether the current image is a parent image. 2444N/A 'ignore_plugin_errors' ignore plugin runtime errors when 2444N/A trying to determine if we're a parent image. 2339N/A """Indicates whether the current image is a parent image.""" 2339N/A """Return a dictionary which represents the linked image 2339N/A properties associated with a linked image. 2339N/A 'lin' is the name of the child image. If lin is None then 2339N/A the current image is assumed to be a linked image and it's 2339N/A Always returns a copy of the properties in case the caller 2339N/A # If we're not linked we'll return an empty 2339N/A # make sure the specified child exists 2339N/A # make a copy of the props in case they are updated 2339N/A """Raise an exception because the current image is not a child 2339N/A """Check if a specific child image exists.""" 2339N/A """A set of the fmris installed in our parent image.""" 2339N/A # We return None since frozenset() would indicate 2339N/A # that there are no packages installed in the parent 2339N/A """Given a string representing a linked image child name, 2339N/A returns linked image name object representing the same name. 2339N/A 'allow_unknown' indicates whether the name must represent 2339N/A actual children or simply be syntactically correct.""" 2339N/A """Returns a list of linked child images associated with the 2339N/A 'li_ignore' see list_related() for a description. 2339N/A The returned value is a list of tuples where each tuple 2339N/A contains (<li name>, <li path>).""" 2339N/A # sort by linked image name 2339N/A # don't ignore any children 2339N/A """Returns a list of linked images associated with the 2339N/A current image. This includes both child and parent images. 2339N/A 'li_ignore' is either None or a list. If it's None (the 2339N/A default), all children will be listed. If it's an empty list 2339N/A no children will be listed. Otherwise, any children listed 2339N/A in li_ignore will be ommited from the results. 2339N/A The returned value is a list of tuples where each tuple 2339N/A contains (<li name>, <relationship>, <li path>).""" 2339N/A # we're linked so append ourself to the list 2339N/A # if we have a path to our parent then append that as well. 2339N/A # sort by linked image name 2339N/A """We only update in-memory state; nothing is written to 2339N/A disk, to sync linked image state to disk call syncmd.""" 2339N/A # Path must be an absolute path. 2339N/A # we don't bother to cleanup the path to the parent image here 2339N/A # because when we allocate an Image object for the parent 2339N/A # image, it will do that work for us. 2339N/A # make sure we're not linking to ourselves 2339N/A # make sure we're not linking the root image as a child 2339N/A # get the cleaned up parent image path. 2339N/A # If we're in an alternate root, the parent must also be within 2339N/A # make a copy of the properties 2339N/A # this prop doesn't apply to pull images 2339N/A """We only update in memory state; nothing is written to 2339N/A disk, to sync linked image state to disk call syncmd.""" 2339N/A # Generate a new set of linked image properties. If we have 2339N/A # no children then we don't need any more properties. 2339N/A # If we have children we'll need to keep some properties. 2339N/A # Update our linked image properties. 2339N/A """Determine if an image is in sync with its constraints.""" 2339N/A # get parent dependencies from the catalog 2339N/A # create a dictionary of packages installed in the parent 2339N/A """If the current image is a child image, this function 2339N/A audits the current image to see if it's in sync with its 2339N/A # try to refresh linked image constraints from 2339N/A """Internal helper function that takes a dictionary returned 2339N/A from an operations on multiple children and merges the results 2339N/A into a single return code.""" 2339N/A # keep track of all the return values that are mapped 2339N/A # the mappings better have included pkgdefs.EXIT_OK 2339N/A # if we had errors for unmapped return values, bundle them up 2339N/A # we have one consistent return value 2339N/A """Convenience function that takes a dictionary returned from 2339N/A an operations on multiple children and merges the results into 2339N/A """Convenience function that takes a dictionary returned from 2339N/A an operations on multiple children and merges the results into 2339N/A """Convenience function that takes a dictionary returned from 2339N/A an operations on multiple children and merges the results into 2339N/A """Sanity check the parameters associated with a child image 2339N/A that we are trying to attach.""" 2339N/A # check the name to make sure it doesn't already exist 2339N/A # Path must be an absolute path. 2339N/A # If we're in an alternate root, the child must also be within 2339N/A # Does the parent image (ourselves) reside in clonable BE? 2339N/A # Unused variable 'be_uuid'; pylint: disable-msg=W0612 2339N/A # If the parent image is clonable then the new child image 2339N/A # must be nested within the parents filesystem namespace. 2339N/A # Find the common parent directory of the both parent and the 2339N/A # Make sure there are no additional images in between the 2339N/A # parent and the child. (Ie, prevent linking of images if one 2339N/A # of the images is nested within another unrelated image.) 2339N/A # This is done by looking at all the parent directories for 2339N/A # both the parent and the child image until we reach a common 2339N/A # First check the parent directories of the child. 2339N/A # W0212 Access to a protected member 2339N/A # pylint: disable-msg=W0212 2339N/A # Then check the parent directories of the parent. 2339N/A # W0212 Access to a protected member 2339N/A # pylint: disable-msg=W0212 2339N/A # Child image should not already be linked 2339N/A # W0212 Access to a protected member 2339N/A # pylint: disable-msg=W0212 2339N/A """Attach an image as a child to the current image (the 2339N/A current image will become a parent image. This operation 2339N/A results in attempting to sync the child image with the parent 2444N/A For descriptions of parameters please see the descriptions in 2339N/A # Too many arguments; pylint: disable-msg=R0913 2339N/A # Too many return statements; pylint: disable-msg=R0911 2339N/A # Path must be an absolute path. 2339N/A # make sure we're not linking to ourselves 2339N/A # make sure we're not linking the root image as a child 2339N/A # if the current image isn't linked yet then we need to 2339N/A # generate some linked image properties for ourselves 2339N/A # make a copy of the options and start updating them 2339N/A # fill in any missing defaults options 2339N/A # attach the child in memory 2339N/A # we've validated parameters, nothing else to do 2339N/A # if noexecute then we're done 2339N/A # save child image properties 2339N/A # save parent image properties 2339N/A """Audit one or more children of the current image to see if 2339N/A they are in sync with this image.""" 2339N/A """Sync one or more children of the current image.""" 2339N/A """Detach one or more children from the current image. This 2339N/A operation results in the removal of any constraint package 2339N/A # get parameter meant for __detach_child() 2339N/A # expand lin_list before calling __detach_child() 2339N/A # if the detach failed leave metadata in parent 2339N/A # Unused variable 'rv'; pylint: disable-msg=W0612 2339N/A # detach the child in memory 2339N/A # sync out the fact that we detached the child 2339N/A # don't overwrite previous errors 2339N/A # we're not linked anymore, so delete all our linked 2339N/A """Perform a linked image operation on multiple children.""" 2339N/A # perform the requested operation 2339N/A # Unused variable; pylint: disable-msg=W0612 2339N/A """Recurse into a child image and audit it.""" 2339N/A """Recurse into a child image and sync it.""" 2339N/A """Recurse into a child image and detach it.""" 2339N/A # we can't detach this type of image. 2339N/A # remove linked data from the child 2339N/A """Reset all child recursion state.""" 2339N/A """When planning changes on a parent image, prepare to 2339N/A recurse into all child images and operate on them as well.""" 2500N/A # Too many arguments; pylint: disable-msg=R0913 2339N/A # we don't need to recurse for these operations 2339N/A # don't bother to recurse into children 2339N/A # Unused variable 'path'; pylint: disable-msg=W0612 2339N/A # no child images to recurse into 2401N/A # given the api operation being performed on the current 2401N/A # image, figure out what api operation should be performed on 2401N/A # the recursion policy which hard coded here is that if we do 2401N/A # an pkg update in the parent image without any packages 2401N/A # specified (ie, we want to update everything) then when we 2401N/A # recurse we'll also do an update of everything. but if we're 2401N/A # doing any other operation like install, uninstall, an update 2401N/A # of specific packages, etc, then when we recurse we'll do a 2339N/A """When planning changes within a parent image, recurse into 2339N/A all child images and operate on them as well.""" 2339N/A """Return True if there is no planned work to do on child 2339N/A """Check if a package has a parent dependency.""" 2339N/A """Since we don't publish packages with parent dependencies 2339N/A yet, but we want to be able to sync packages between zones, 2339N/A we'll need to fake up some extra package parent dependencies. 2339N/A Here we'll inspect the catalog to find packages that we think 2339N/A should have parent dependencies and then we'll return a 2339N/A dictionary, indexed by fmri, which contains the extra 2339N/A dependency actions that should be added to each package.""" 2339N/A # create a parent dependency action with a nonglobal zone 2339N/A # Used * or ** magic; pylint: disable-msg=W0142 2339N/A # we're not operating on a nonglobal zone image so we 2339N/A # don't need to fabricate parent zone dependencies 2339N/A # we're not a child image so parent dependencies are 2410N/A # it's time consuming to walk the catalog looking for packages 2410N/A # to dynamically add parent dependencies too. so to speed 2410N/A # things up we'll check if the currently installed osnet and 2410N/A # ips incorporations already have parent dependencies. if 2410N/A # they do then this image has already been upgraded to a build 2410N/A # where these dependencies are being published so there's no 2410N/A # need for us to dynamically add them. 2410N/A # osnet incorporation has parent deps 2410N/A # ips incorporation has parent deps 2339N/A # assume that the osnet and ips incorporations should always 2339N/A # have a parent dependencies. 2339N/A # create an fmri for the incorporated package 2339N/A # translate the incorporated package fmris into actual 2339N/A # packages in the known catalog 2339N/A # all the fmris we want to add dependencies to. 2369N/A # remove some unwanted fmris 2369N/A # eliminate renamed or obsoleted fmris 2369N/A # eliminate any group packages 2339N/A """A LinkedImageChild object is used when a parent image wants to 2339N/A access a child image. These accesses may include things like: 2339N/A auditing a child image, or recursing into a child image to keep it in 2339N/A sync with planned changes in the parent image.""" 2339N/A # Too many instance attributes; pylint: disable-msg=R0902 2339N/A # initialize paths for linked image data files 2339N/A # initialize a linked image child plugin 2339N/A # variables reset by self.child_reset_recurse() 2339N/A """Get the path associated with a child image.""" 2339N/A """Get the path associated with a child image.""" 2339N/A """Get a pointer to the parent image object associated with 2339N/A """Write data to a child image.""" 2339N/A # first save our data to a temporary file 2339N/A # check if we're updating the data 2339N/A # W0212 Access to a protected member 2339N/A # pylint: disable-msg=W0212 2339N/A # W0212 Access to a protected member 2339N/A # pylint: disable-msg=W0212 2339N/A # if we're not actually updating any data, or if we were just 2339N/A # doing a test to see if the data has changed, then delete the 2339N/A # we are updating the real data. 2339N/A # W0212 Access to a protected member 2339N/A # pylint: disable-msg=W0212 2339N/A """Sync linked image parent constraint data to a child image. 2339N/A linked image metadata files, or if we should access temporary 2339N/A versions (which have ".<runid>" appended to them.""" 2339N/A # there has to be an image plan to export 2339N/A # if there's an image plan the we need to update the 2339N/A # installed packages based on that plan. 2339N/A """Sync linked image properties data to a child image. 2339N/A linked image metadata files, or if we should access temporary 2339N/A versions (which have ".<runid>" appended to them.""" 2339N/A # make a copy of the props we want to push 2339N/A # delete temporal properties 2339N/A """Sync linked image parent publisher data to a child image. 2339N/A linked image metadata files, or if we should access temporary 2339N/A versions (which have ".<runid>" appended to them.""" 2339N/A """Sync linked image data to a child image. 2339N/A linked image metadata files, or if we should access temporary 2339N/A versions (which have ".<runid>" appended to them.""" 2339N/A """We flush stdout and stderr before and after operating on 2339N/A child images to avoid any out-of-order output problems that 2339N/A could be caused by caching of output.""" 2339N/A # W0212 Access to a protected member 2339N/A # pylint: disable-msg=W0212 2339N/A # W0212 Access to a protected member 2339N/A # pylint: disable-msg=W0212 2339N/A """Perform a pkg(1) operation on a child image.""" 2339N/A # Build up a command line to execute. Note that we take care 2339N/A # to try to run the exact same pkg command that we were 2339N/A # executed with. We do this because pkg commonly tries to 2339N/A # access the image that the command is being run from. 2339N/A # check if the currently running pkg command 2339N/A # exists and is accessible. 2339N/A # propagate certain debug options 2339N/A "broken-conflicting-action-handling",
2339N/A # add the subcommand argument 2339N/A # add the subcommand argument options 2339N/A # flush all output before recursing into child 2500N/A # If we're using --parsable, don't emit the child cmd 2500N/A # information as info because it will confuse the JSON parser. 2410N/A # Start the operation on the child. let the child have direct 2410N/A # access to stdout but capture stderr. 2500N/A # If we're using --parsable, then we need to capture stdout so 2500N/A # that we can parse the plan of the child image and include it 2339N/A # W0212 Access to a protected member 2339N/A # pylint: disable-msg=W0212 2410N/A # flush output generated by the child 2410N/A # get error output generated by the child 2500N/A # A parsable plan is only displayed if the operation was 2500N/A # successful and the stage was default or plan. 2500N/A # JSON raises a subclass of ValueError when it 2339N/A """Detach a child image.""" 2339N/A # When issuing a detach from a prent we must always use the 2339N/A # force flag. (Normally a child will refuse to detach from a 2339N/A # parent unless it attached to the parent, which is never the 2339N/A # if the detach command ran, return its status. 2339N/A """Audit a child image to see if it's in sync with its 2339N/A # recurse into the child image 2339N/A # if the audit command ran, return its status. 2339N/A # something went unexpectedly wrong. 2339N/A """Try to bring a child image into sync with its 2444N/A 'li_attach_sync' indicates if this sync is part of an attach 2444N/A For descriptions of parameters please see the descriptions in 2339N/A # Too many arguments; pylint: disable-msg=R0913 2339N/A # we're not going to recurse into the child image, 2339N/A # we're just going to update its metadata. 2339N/A # if we're doing this sync as part of an attach, then 2339N/A # temporarily sync the metadata since we don't know 2339N/A # yet if the attach will succeed. if the attach 2339N/A # doesn't succeed this means we don't have to delete 2339N/A # any metadata. if the attach succeeds the child will 2339N/A # make the temporary metadata permanent as part of the 2339N/A # if the audit command ran, return its status. 2339N/A # something went unexpectedly wrong. 2339N/A """Our image path is being updated, so figure out our new 2339N/A child image paths. This interface only gets invoked when: 2339N/A - We're doing a packaging operation on a parent image and 2339N/A we've just cloned that parent to create a new BE that we're 2339N/A going to update. This clone also cloned all the children 2339N/A and so now we need to update our paths to point to the newly 2339N/A - We tried to update a cloned image (as described above) and 2339N/A our update failed, hence we're changing paths back to the 2339N/A original images that were the source of the clone.""" 2339N/A # get the image path without the altroot 2339N/A # update the path with the current altroot 2339N/A # update properties with altroot 2339N/A # we don't bother to update update PROP_PARENT_PATH since 2339N/A # that is only used when reading constraint data from the 2339N/A # parent image, and this interface is only invoked when we're 2339N/A # starting or finishing execution of a plan on a cloned image 2339N/A # (at which point we have no need to access the parent 2339N/A """Check if there are any changes planned for a child 2339N/A """Reset child recursion state for child.""" 2339N/A """When planning changes on a parent image, prepare to 2339N/A recurse into a child image.""" 2339N/A # W0511 XXX / FIXME Comments; pylint: disable-msg=W0511 2339N/A # XXX: also need to support --licenses. 2339N/A # options specific to: attach, set-property-linked, sync 2339N/A # skip ipkg up to date check for child images 2339N/A """When planning changes within a parent image, recurse into 2410N/A # no metadata changes in the child image. 2339N/A # the child image told us it has no changes planned. 2339N/A # we're done with this operation 2339N/A# --------------------------------------------------------------------------- 2339N/A """Save JSON encoded linked image metadata to a file.""" 2339N/A # make sure the directory we're about to save data into exists. 2339N/A # write the output to a temporary file 2339N/A # atomically create the desired file 2339N/A # W0212 Access to a protected member 2339N/A # pylint: disable-msg=W0212 2339N/A """Load JSON encoded linked image metadata from a file.""" 2339N/A # W0212 Access to a protected member 2339N/A # pylint: disable-msg=W0212 2339N/A """Utility class used when json encoding linked image metadata.""" 2339N/A # E0202 An attribute inherited from JSONEncoder hide this method 2339N/A # pylint: disable-msg=E0202 2339N/A """Required routine that overrides the default base 2339N/A class version. This routine must serialize 'obj' when 2339N/A attempting to save 'obj' json format.""" 2339N/A """Utility class used when json decoding linked image metadata.""" 2339N/A # convert boolean strings values back into booleans 2339N/A """Remove a set of keys from a dictionary.""" 2339N/A """Oops. We hit a runtime error. Die with a nice informative 2339N/A message. Note that runtime errors should never happen and usually 2339N/A indicate bugs (or possibly corrupted linked image metadata), so they 2339N/A are not localized (just like asserts are not localized).""" 2339N/A # Too many arguments; pylint: disable-msg=R0913 2339N/A err =
"Missing required linked properties: %s" % \
2339N/A err =
"Multiple plugins reported different altroots:" 2339N/A err =
"Found saved temporal linked properties: %s" % \
2339N/A# --------------------------------------------------------------------------- 2339N/A# Functions for accessing files in the current root 2339N/A """Simple wrapper for accessing files in the current root.""" 2339N/A # W0212 Access to a protected member 2339N/A # pylint: disable-msg=W0212 2339N/A """Simple wrapper for accessing files in the current root.""" 2339N/A # W0212 Access to a protected member 2339N/A # pylint: disable-msg=W0212 2339N/A """Simple wrapper for accessing files in the current root.""" 2339N/A # W0212 Access to a protected member 2339N/A # pylint: disable-msg=W0212 2339N/A """Simple wrapper for accessing files in the current root.""" 2339N/A # W0212 Access to a protected member 2339N/A # pylint: disable-msg=W0212 2339N/A# --------------------------------------------------------------------------- 2339N/A# Functions for managing images which may be in alternate roots 2339N/A """Check if 'path' is nested within 'altroot'""" 2339N/A # make sure both paths have one trailing os.sep. 2339N/A # check for nested or equal paths 2339N/A """Return a path where 'path' is nested within 'altroot'""" 2339N/A """Return the relative porting of 'path', which must be nested within 2339N/A """Given 'path', and a relative path 'path_suffix' that must match 2339N/A the suffix of 'path', return the unmatched prefix of 'path'.""" 2339N/A # make sure both paths have one trailing os.sep. 2339N/A # path and path_suffix are either unrelated or equal