Exemplo n.º 1
0
    def provisioner(self, need_boot=True):
        """provision zone
        - configure zone
        - if snapof and zone brand is native
           then create zonepath from snapshot of snapof
           then attach zone
        - if snapof and zone brand is ipkg
           then try to detect zone associated with snapof
           then define container_origin
        - if container_origin
           then clone  container_origin
        - create sysidcfg
        - if need_boot boot and wait multiuser
        """
        self.osver = get_solaris_version()
        self.zone_configure()

        if self.osver >= 11:
            self.create_sysidcfg(self.r)
        else:
            if self.snapof is not None and self.r.brand == 'native':
                self.create_zonepath()
                self.r.zoneadm("attach", ["-F"])
            elif self.snapof is not None and self.r.brand == 'ipkg':
                zones = rcZone.Zones()
                src_dataset = Dataset(self.snapof)
                zonepath = src_dataset.getprop('mountpoint')
                self.container_origin = zones.zonename_from_zonepath(
                    zonepath).zonename
                self.log.info("source zone is %s (detected from snapof %s)" %
                              (self.container_origin, self.snapof))

        if self.container_origin is not None:
            lockname = 'create_zone2clone-' + self.container_origin
            lockfile = os.path.join(rcEnv.paths.pathlock, lockname)
            self.log.info("wait get lock %s" % (lockname))
            try:
                lockfd = lock.lock(timeout=1200, delay=5, lockfile=lockfile)
            except:
                raise (ex.excError("failure in get lock %s" % (lockname)))
            try:
                self.create_zone2clone()
            except:
                lock.unlock(lockfd)
                raise
            lock.unlock(lockfd)
            self.create_cloned_zone()

        if self.osver < 11:
            self.create_sysidcfg(self.r)

        if need_boot is True:
            self.r.zone_boot()
            self.r.wait_multi_user()

        self.r.log.info("provisioned")
        return True
Exemplo n.º 2
0
def update(fpath):
    try:
        # causing: pkgadd "unable to create temporary directory" errors
        del os.environ["TMPDIR"]
    except:
        pass
    # check downloaded package integrity
    cmd = ['pkgchk', '-d', fpath, 'all']
    print(' '.join(cmd))
    p = Popen(cmd)
    p.communicate()
    if p.returncode != 0:
        return 1

    # check if initially installed with pkgadd -G
    file = '/var/sadm/install/gz-only-packages'
    GlobalOnly = False
    if os.path.isfile(file):
        f = open(file)
        for line in f:
            if line.startswith("opensvc"):
                print(
                    "OpenSVC package was previously installed with pkgadd -G\n"
                )
                GlobalOnly = True

    admin = gen_adminfile()
    cmd = ['pkgrm', '-a', admin, '-n', 'opensvc']
    print(' '.join(cmd))
    p = Popen(cmd)
    p.communicate()
    if p.returncode != 0:
        return 1
    osver = get_solaris_version()
    if osver < 10.0:
        opts = ''
    else:
        if GlobalOnly is True:
            opts = '-G'
        else:
            opts = ''
    opts += " -a %s " % admin
    cmd = 'pkgadd %s -d %s all' % (opts, fpath)
    print(cmd)
    return os.system(cmd)
Exemplo n.º 3
0
 def do_check(self):
     if not which("dladm"):
         return self.undef
     self.osver = get_solaris_version()
     if self.osver >= 11:
         cmd = ['dladm', 'show-phys', '-p', '-o', 'link,state,speed,duplex']
         out, err, ret = justcall(cmd)
         if ret != 0:
             return self.undef
         self.phys = out.split('\n')
         cmd = ['dladm', 'show-aggr', '-p', '-o', 'link']
     else:
         cmd = ['dladm', 'show-aggr']
     out, err, ret = justcall(cmd)
     if ret != 0:
         return self.undef
     if self.osver >= 11:
         self.aggs = out.split('\n')
         if len(self.aggs) == 0:
             return self.undef
         self.listaggs = {}
         cmd = ['dladm', 'show-link', '-p', '-o', 'link,over']
         out, err, ret = justcall(cmd)
         if ret != 0:
             return self.undef
         lines = out.split('\n')
         for line in lines:
             if len(line) == 0:
                 break
             l = line.split(':')
             if l[0] in self.aggs:
                 self.listaggs[l[0]] = l[1]
     else:
         self.lines = out.split('\n')
         if len(self.lines) == 0:
             return self.undef
     r = []
     r += self.do_check_speed()
     r += self.do_check_duplex()
     r += self.do_check_link()
     r += self.do_check_attach()
     return r
Exemplo n.º 4
0
 def attach(self):
     if self.state in ("installed", "ready", "running"):
         self.log.info("zone container %s already installed" % self.name)
         return
     elif self.state is None:
         cmd = [ZONECFG, "-z", self.name, "-f", self.zone_cfg_path()]
         ret, out, err = self.vcall(cmd)
         self.zone_refresh()
         if ret != 0:
             raise ex.excError
     options = []
     if get_solaris_version() >= 11.3:
         options += ["-x", "deny-zbe-clone"]
     try:
         self.umount_fs_in_zonepath()
         self.zoneadm("attach", options)
     except ex.excError:
         options.append("-F")
         self.zoneadm("attach", options)
     self.can_rollback = True
Exemplo n.º 5
0
    def do_check(self):
        self.osver = get_solaris_version()
        self.ifs = []
        cmd = ['/usr/sbin/ifconfig', '-a']
        out, err, ret = justcall(cmd)
        if ret != 0:
            return self.undef
        lines = out.split('\n')
        if len(lines) == 0:
            return self.undef
        for line in lines:
            if line.startswith(' '):
                continue
            if line.startswith('lo'):
                continue
            if line.startswith('sppp'):
                continue
            if self.osver < 11:
                if line.startswith('aggr'):
                    continue
            if 'index' not in line:
                continue
            l = line.split(':')
            if 'index' not in l[1]:
                continue
            if len(l[0]) < 3:
                continue
            if l[0] in self.ifs:
                continue
            else:
                self.ifs.append(l[0])
        if self.osver >= 11:
            self.l = {}
            for ifn in self.ifs:
                if ifn not in self.l:
                    self.l[ifn] = set()
                    self.topif = ifn
                    ret = self._findphys(ifn)
            cmd = ['/usr/sbin/dladm', 'show-phys', '-p', '-o', 'link,state,speed,duplex,device']
            out, err, ret = justcall(cmd)
            if ret != 0:
                return self.undef
            """
            public0:up:1000:full:bnx0
            """
            self.phys = {}
            if len(lines) == 0:
                return self.undef
            for line in out.splitlines():
                l = line.split(':')
                if len(l) != 5:
                    continue
                self.phys[l[0]] = {
                    "link": l[0],
                    "state": l[1],
                    "speed": l[2],
                    "duplex": l[3],
                    "device": l[4],
                }

        r = []
        r += self.do_check_speed()
        r += self.do_check_duplex()
        r += self.do_check_link()
        return r