def __call(args, zone=None): # a way to invoke a separate executable for testing cmds_dir = DebugValues.get_value("smf_cmds_dir") # returned values will be in the user's locale # so we need to ensure that the force_str uses # their locale. encoding = locale.getpreferredencoding(do_setlocale=False) if cmds_dir: args = ( os.path.join(cmds_dir, args[0].lstrip("/")),) + args[1:] if zone: cmd = DebugValues.get_value("bin_zlogin") if cmd is None: cmd = zlogin_path args = (cmd, zone) + args try: proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) buf = [misc.force_str(l, encoding=encoding) for l in proc.stdout.readlines()] ret = proc.wait() except OSError as e: raise RuntimeError("cannot execute {0}: {1}".format(args, e)) if ret != 0: raise NonzeroExitException(args, ret, buf) return buf
def exec_prep(self, image): if not image.is_liveroot(): # # XXX don't create the marker file as illumos doesn't support self-assembly # milestone # # # we're doing off-line pkg ops; we need # # to support self-assembly milestone # # so create the necessary marker file # # if image.type != IMG_USER: # path = os.path.join(image.root, # ".SELF-ASSEMBLY-REQUIRED") # # create only if it doesn't exist # # if not os.path.exists(path): # os.close(os.open(path, # os.O_EXCL | # os.O_CREAT | # os.O_WRONLY)) if not DebugValues.get_value("smf_cmds_dir") and \ not self.zone: return self.do_nothing = False
def _zonename(): """Get the zonname of the current system.""" cmd = DebugValues.get_value("bin_zonename") # pylint: disable=E1120 if cmd is not None: cmd = [cmd] else: cmd = ["/bin/zonename"] # if the command doesn't exist then bail. if not li.path_exists(cmd[0]): return # open a temporary file in text mode for compatible string handling fout = tempfile.TemporaryFile(mode="w+") ferrout = tempfile.TemporaryFile(mode="w+") p = pkg.pkgsubprocess.Popen(cmd, stdout=fout, stderr=ferrout) p.wait() if p.returncode != 0: cmd = " ".join(cmd) ferrout.seek(0) errout = "".join(ferrout.readlines()) ferrout.close() raise apx.LinkedImageException(cmd_failed=(p.returncode, cmd, errout)) # parse the command output fout.seek(0) l = fout.readlines()[0].rstrip() fout.close() return l
def exec_prep(self, image): if not image.is_liveroot(): dir = DebugValues.get_value("actuator_cmds_dir") if not dir: return self.cmd_path = dir self.do_nothing = False
def _zonename(): """Get the zonname of the current system.""" cmd = DebugValues.get_value("zone_name") # pylint: disable=E1120 if not cmd: cmd = ["/bin/zonename"] # if the command doesn't exist then bail. if not li.path_exists(cmd[0]): return fout = tempfile.TemporaryFile() ferrout = tempfile.TemporaryFile() p = pkg.pkgsubprocess.Popen(cmd, stdout=fout, stderr=ferrout) p.wait() if (p.returncode != 0): cmd = " ".join(cmd) ferrout.seek(0) errout = "".join(ferrout.readlines()) raise apx.LinkedImageException( cmd_failed=(p.returncode, cmd, errout)) # parse the command output fout.seek(0) l = fout.readlines()[0].rstrip() return l
def exec_prep(self, image): if not image.is_liveroot(): cmds_dir = DebugValues.get_value("actuator_cmds_dir") if not cmds_dir: return self.cmd_path = cmds_dir self.do_nothing = False
def __call(args): # a way to invoke a separate executable for testing cmds_dir = DebugValues.get_value("smf_cmds_dir") if cmds_dir: args = (os.path.join(cmds_dir, args[0].lstrip("/")),) + args[1:] try: proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) buf = proc.stdout.readlines() ret = proc.wait() except OSError, e: raise RuntimeError, "cannot execute %s: %s" % (args, e)
def __call(args, zone=None): # a way to invoke a separate executable for testing cmds_dir = DebugValues.get_value("smf_cmds_dir") if cmds_dir: args = (os.path.join(cmds_dir, args[0].lstrip("/")), ) + args[1:] if zone: cmd = DebugValues.get_value("bin_zlogin") if cmd is None: cmd = zlogin_path args = (cmd, zone) + args try: proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) buf = [misc.force_str(l) for l in proc.stdout.readlines()] ret = proc.wait() except OSError as e: raise RuntimeError("cannot execute {0}: {1}".format(args, e)) if ret != 0: raise NonzeroExitException(args, ret, buf) return buf
def __zones_supported(self): """Check to see if zones are supported in the current image. i.e. can the current image have zone children.""" # pylint: disable=E1120 if DebugValues.get_value("zones_supported"): return True # pylint: enable=E1120 # first check if the image variant is global variant = "variant.opensolaris.zone" value = self.__img.cfg.variants[variant] if value != "global": return False # # sanity check the path to to /etc/zones. below we check for # the zones packages, and any image that has the zones # packages installed should have a /etc/zones file (since # those packages deliver this file) but it's possible that the # image was corrupted and the user now wants to be able to run # pkg commands to fix it. if the path doesn't exist then we # don't have any zones so just report that zones are # unsupported (since zoneadm may fail to run anyway). # path = self.__img.root if not os.path.isdir(os.path.join(path, "etc")): return False if not os.path.isdir(os.path.join(path, "etc/zones")): return False # get a set of installed packages cati = self.__img.get_catalog(self.__img.IMG_CATALOG_INSTALLED) pkgs_inst = frozenset([ stem # Unused variable 'pub'; pylint: disable=W0612 for pub, stem in cati.pkg_names() # pylint: enable=W0612 ]) # check if the zones packages are installed for pkgs in self.__zone_pkgs: if (pkgs & pkgs_inst) == pkgs: return True return False
def exec_prep(self, image): if not image.is_liveroot(): # we're doing off-line pkg ops; we need # to support self-assembly milestone # so create the necessary marker file if image.type != IMG_USER: path = os.path.join(image.root, ".SELF-ASSEMBLY-REQUIRED") # create only if it doesn't exist if not os.path.exists(path): os.close(os.open(path, os.O_EXCL | os.O_CREAT | os.O_WRONLY)) if not DebugValues.get_value("smf_cmds_dir"): return self.do_nothing = False
def _list_zones(root, path_transform): """Get the zones associated with the image located at 'root'. We return a dictionary where the keys are zone names and the values are tuples containing zone root path and current state. The global zone is excluded from the results. Solaris10 branded zones are excluded from the results.""" rv = dict() cmd = DebugValues.get_value("bin_zoneadm") # pylint: disable=E1120 if cmd is not None: cmd = [cmd] else: cmd = ["/usr/sbin/zoneadm"] # if the command doesn't exist then bail. if not li.path_exists(cmd[0]): return rv # make sure "root" has a trailing '/' root = root.rstrip(os.sep) + os.sep # create the zoneadm command line cmd.extend(["-R", str(root), "list", "-cp"]) # execute zoneadm and save its output to a file # open a temporary file in text mode for compatible string handling fout = tempfile.TemporaryFile(mode="w+") ferrout = tempfile.TemporaryFile(mode="w+") p = pkg.pkgsubprocess.Popen(cmd, stdout=fout, stderr=ferrout) p.wait() if p.returncode != 0: cmd = " ".join(cmd) ferrout.seek(0) errout = "".join(ferrout.readlines()) ferrout.close() raise apx.LinkedImageException(cmd_failed=(p.returncode, cmd, errout)) # parse the command output fout.seek(0) output = fout.readlines() fout.close() for l in output: l = l.rstrip() z_name, z_state, z_path, z_brand = \ _zoneadm_list_parse(l, cmd, output) # skip brands that we don't care about # W0511 XXX / FIXME Comments; pylint: disable=W0511 # XXX: don't hard code brand names, use a brand attribute # pylint: enable=W0511 if z_brand not in ["lipkg", "solaris", "sn1", "labeled", "sparse"]: continue # we don't care about the global zone. if z_name == "global": continue # append "/root" to zonepath z_rootpath = os.path.join(z_path, "root") assert z_rootpath.startswith(root), \ "zone path '{0}' doesn't begin with '{1}".format( z_rootpath, root) # If there is a current path transform in effect then revert # the path reported by zoneadm to the original zone path. if li.path_transform_applied(z_rootpath, path_transform): z_rootpath = li.path_transform_revert(z_rootpath, path_transform) # we only care about zones that have been installed if z_state not in zone_installed_states: continue rv[z_name] = (z_rootpath, z_state) return rv
import six # pkg classes import pkg.client.api_errors as apx import pkg.client.pkgdefs as pkgdefs import pkg.misc import pkg.nrlock import pkg.pipeutils from pkg.client import global_settings from pkg.client.debugvalues import DebugValues # debugging aids # DebugValues is a singleton; pylint: disable=E1120 pkgremote_debug = (DebugValues.get_value("pkgremote_debug") is not None or os.environ.get("PKG_PKGREMOTE_DEBUG", None) is not None) class PkgRemote(object): """This class is used to perform packaging operation on an image. It utilizes the "remote" subcommand within the pkg.1 client to manipulate images. Communication between this class and the "pkg remote" process is done via RPC. This class essentially implements an RPC client and the "pkg remote" process is an RPC server.""" # variables to keep track of our RPC client call state. __IDLE = "call-idle" __SETUP = "call-setup" __STARTED = "call-started"
import traceback # pkg classes import pkg.client.api_errors as apx import pkg.client.pkgdefs as pkgdefs import pkg.misc import pkg.nrlock import pkg.pipeutils from pkg.client import global_settings from pkg.client.debugvalues import DebugValues # debugging aids # DebugValues is a singleton; pylint: disable=E1120 pkgremote_debug = ( DebugValues.get_value("pkgremote_debug") is not None or os.environ.get("PKG_PKGREMOTE_DEBUG", None) is not None) class PkgRemote(object): """This class is used to perform packaging operation on an image. It utilizes the "remote" subcommand within the pkg.1 client to manipulate images. Communication between this class and the "pkg remote" process is done via RPC. This class essentially implements an RPC client and the "pkg remote" process is an RPC server.""" # variables to keep track of our RPC client call state. __IDLE = "call-idle" __SETUP = "call-setup" __STARTED = "call-started" def __init__(self):