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 _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 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 _list_zones(root): """Get the zones associated with the image located at 'root'. We return a dictionary where the keys are zone names and the values are zone root pahts. The global zone is excluded from the results. Solaris10 branded zones are excluded from the results. """ rv = dict() cmd = ["/usr/sbin/zoneadm"] # if the command doesn't exist then bail. if not li.path_exists(cmd[0]): return rv # create the zoneadm command line if (root and (root != "/")): cmd.extend(["-R", str(root)]) cmd.extend(["list", "-cp"]) # execute zoneadm and save its output to a file 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) for l in fout.readlines(): l = l.rstrip() # Unused variable; pylint: disable=W0612 z_id, z_name, z_state, z_path, z_uuid, z_brand, \ z_iptype = l.strip().split(':', 6) # pylint: enable=W0612 z_rootpath = os.path.join(z_path, "root") # we don't care about the global zone. if (z_name == "global"): continue # 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 ["ipkg", "solaris", "sn1", "labeled"]: continue # we only care about zones that have been installed if z_state not in zone_installed_states: continue rv[z_name] = z_rootpath return rv
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 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) output = fout.readlines() 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 ["ipkg", "solaris", "sn1", "labeled"]: 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