Ejemplo n.º 1
0
    def system_rollback(self):
        containers = self.container.get_container(self.args.template)

        # By now only support "Pulsar" and "overc" Linux rollback
        DIST = "Pulsar overc"
        need_reboot = False
        for cn in containers:
            if self.container.is_active(cn, self.args.template):
                for dist in DIST.split():
                    if dist in self.container.get_issue(
                            cn, self.args.template).split():
                        log.info("Rollback container %s" % cn)
                        self._container_rollback(cn, None, self.args.template,
                                                 True)
                        if self.retval is not 0:
                            log.error("*** Failed to rollback container %s" %
                                      cn)
                        else:
                            need_reboot = True
                        break

        self.host_rollback()
        if need_reboot:
            log.info("rebooting...")
            os.system('reboot')
Ejemplo n.º 2
0
    def _overlay(self, cn, dirs, restore, sources=None):
        # Pararmeter check
        retval = 0
        if (dirs == None):
            log.error("No dirs in parameter")
            return -1
        if (restore == False):
            if (sources == None):
                log.error("No sources in parameter")
                return -1
            else:  # Check source container name
                for cn0 in sources.split(','):
                    if (cn0 == cn):
                        log.error("Can not set same container in source list")
                        return -1

        # check if overlay dir exists, ex /var/lib/lxc/dom0/rootfs/usr_temp
        for oldir in dirs.split(','):
            temppath = "%s/%s/rootfs%s_temp" % (CONTAINER_MOUNT, cn, oldir)
            fullpath = "%s/%s/rootfs%s" % (CONTAINER_MOUNT, cn, oldir)
            if (restore == True):  # Stop an overlay,
                if (os.path.isdir(temppath) == False):  #no such dir
                    log.error("%s:not an overlay-ed dir in container" %
                              (oldir))
                    return -1
            else:  # Create an overlay
                if (os.path.isdir(temppath) == True):  # already overlay dir
                    log.error("%s:already an overlay-ed dir in container" %
                              (oldir))
                    return -1
        # Insert request into lxc.service
        lxcfile = '%s/overlayrestore' % (CONTAINER_MOUNT)
        lxc = open(lxcfile, 'a+')
        lines = lxc.readlines().decode("utf-8").strip("\n")
        found = 0
        for oldir in dirs.split(','):
            basepara = "%s %s" % (cn, oldir)
            for line in lines:
                if (line.find(basepara) != -1):
                    found = 1
                    break
            if (found == 0):
                if (restore == True):
                    cmdline = "/etc/lxc/overlayrestore %s\n" % basepara
                else:
                    cmdline = "/etc/lxc/overlaycreate %s %s\n" % (basepara,
                                                                  sources)
                lxc.write(cmdline)
                retval = 1
            else:
                log.info("%s already in overlay rebuild list, ignored" %
                         basepara)
        lxc.close()
        return retval
Ejemplo n.º 3
0
    def host_update(self):
        rc = 0
        try:
            self.message += subprocess.check_output("cube-cmd dnf updateinfo --refresh", stderr=subprocess.STDOUT, shell=True).decode("utf-8").strip("\n")
        except subprocess.CalledProcessError as e:
            rc = e.returncode
            self.message += e.output.decode("utf-8").strip()

        if rc == 0:
            log.info(self.message)
        else:
            log.error(self.message)
        return rc
Ejemplo n.º 4
0
 def _smartpm(self, args, chroot=None):
     cmd = []
     if chroot != None:
         cmd.append("chroot")
         cmd.append(chroot)
     cmd.append("/usr/bin/smart")
     cmd.append(args)
     cmd_s = ' '.join(cmd)
     process = Process()
     retval = process.run(cmd_s)
     self.message = process.message
     if retval is not 0:
         log.error("%s" % cmd_s)
     return retval
Ejemplo n.º 5
0
    def host_rollback(self):
        if self.bakup_mode:
            self.message = "You are running in the backup mode, cannot do rollback!"
            log.error(self.message)
            return False

        log.info("Start doing host rollback")
        r = self.agency.do_rollback()
        self.message = self.agency.message
        if r:
            os.system('reboot')
        else:
            log.error(self.message)
            return False
Ejemplo n.º 6
0
    def host_rollback(self):
        if self.bakup_mode:
            self.message = "You are running in the backup mode, cannot do rollback!"
            log.error(self.message)
            return False

        log.info("Start doing host rollback")
        r = self.agency.do_rollback()
        self.message = self.agency.message
        if r:
            os.system('reboot')
        else:
            log.error(self.message)
            return False
Ejemplo n.º 7
0
    def _overlay(self, cn, dirs, restore, sources=None):
        # Pararmeter check
        retval = 0
        if (dirs == None):
            log.error("No dirs in parameter")
            return -1
        if (restore == False):
            if (sources == None):
                log.error("No sources in parameter")
                return -1
            else: # Check source container name
                for cn0 in sources.split(','):
                    if (cn0 == cn):
                        log.error("Can not set same container in source list")
                        return -1

        # check if overlay dir exists, ex /var/lib/lxc/dom0/rootfs/usr_temp
        for oldir in dirs.split(','):
            temppath="%s/%s/rootfs%s_temp" % (CONTAINER_MOUNT,cn,oldir)
            fullpath="%s/%s/rootfs%s" % (CONTAINER_MOUNT,cn,oldir)
            if (restore == True): # Stop an overlay,
                if (os.path.isdir(temppath) == False): #no such dir
                    log.error("%s:not an overlay-ed dir in container" % (oldir))
                    return -1
            else: # Create an overlay
                if (os.path.isdir(temppath) == True): # already overlay dir
                    log.error("%s:already an overlay-ed dir in container" % (oldir))
                    return -1
        # Insert request into lxc.service
        lxcfile = '%s/overlayrestore' % (CONTAINER_MOUNT)
        lxc = open(lxcfile, 'a+')
        lines=lxc.readlines().decode("utf-8").strip("\n")
        found = 0
        for oldir in dirs.split(','):
            basepara = "%s %s" % (cn,oldir)
            for line in lines:
                if (line.find(basepara) != -1):
                    found = 1
                    break
            if (found == 0):
                if (restore == True):
                    cmdline = "/etc/lxc/overlayrestore %s\n" % basepara
                else:
                    cmdline = "/etc/lxc/overlaycreate %s %s\n" % (basepara, sources)
                lxc.write(cmdline)
                retval = 1
            else:
                log.info("%s already in overlay rebuild list, ignored" % basepara)
        lxc.close()
        return retval
Ejemplo n.º 8
0
 def run_script(self, template, args, failok=False, liveoutput=True):
     fname = CONTAINER_SCRIPT_PATH + "/" + template
     if not os.path.isfile(fname):
         self.message = "Error! Missing file: %s" % fname
         return 1
     cmd = "%s %s" % (fname, args)
     process = Process()
     retval = process.run(cmd, liveoutput)
     self.message = process.message
     if retval is 0:
         log.info("%s ok" % fname)
     elif not failok:
         log.error("%s failed" % fname)
     return retval
Ejemplo n.º 9
0
 def run_script(self, template, args, failok=False, liveoutput=True):
     fname = CONTAINER_SCRIPT_PATH + "/" + template
     if not os.path.isfile(fname):
         self.message = "Error! Missing file: %s" % fname
         return 1
     cmd = "%s %s" % (fname, args)
     process = Process()
     retval = process.run(cmd, liveoutput)
     self.message = process.message
     if retval is 0:
         log.info("%s ok" % fname)
     elif not failok:
         log.error("%s failed" % fname)
     return retval
Ejemplo n.º 10
0
 def _smartpm(self, args, chroot=None):
     cmd = []
     if chroot != None:
         cmd.append("chroot")
         cmd.append(chroot)
     cmd.append("/usr/bin/smart")
     cmd.append(args)
     cmd_s = ' '.join(cmd)
     process = Process()
     retval = process.run(cmd_s)
     self.message = process.message
     if retval is not 0:
         log.error("%s" % cmd_s)
     return retval
Ejemplo n.º 11
0
    def __init__(self):
        if Host_update is None:
            log.error("Not using a supported filesystem!")
            sys.exit(1)
        self.agency = Host_update()
        self.package = Package()
        self.container = Container()
        self.utils = Utils()
        self.message = ""
        
        if not self.agency:
            log.error("cannot get the right backends!")
            sys.exit(2)

        self.bakup_mode = self.agency.bakup_mode
Ejemplo n.º 12
0
    def __init__(self):
        if Host_update is None:
            log.error("Not using a supported filesystem!")
            sys.exit(1)
        self.agency = Host_update()
        self.package = Package()
        self.container = Container()
        self.utils = Utils()
        self.message = ""

        if not self.agency:
            log.error("cannot get the right backends!")
            sys.exit(2)

        self.bakup_mode = self.agency.bakup_mode
Ejemplo n.º 13
0
    def host_update(self):
        rc = 0
        try:
            self.message += subprocess.check_output(
                "cube-cmd dnf updateinfo --refresh",
                stderr=subprocess.STDOUT,
                shell=True).decode("utf-8").strip("\n")
        except subprocess.CalledProcessError as e:
            rc = e.returncode
            self.message += e.output.decode("utf-8").strip()

        if rc == 0:
            log.info(self.message)
        else:
            log.error(self.message)
        return rc
Ejemplo n.º 14
0
    def _system_upgrade(self, template, reboot, force, skipscan, skip_del):
        containers = self.container.get_container(template)
        overlay_flag = 0

        # By now only support "Pulsar" and "overc" Linux upgrading
        DIST = "Pulsar overc"
        succeeded = []
        for cn in containers:
            self.retval = 0
            if self.container.is_active(cn, template):
                for dist in DIST.split():
                    if dist in self.container.get_issue(cn, template).split():
                        log.info("Updating container %s" % cn)
                        self._container_upgrade(
                            cn, template, True, False,
                            skip_del)  #by now only rpm upgrade support
                        if self.retval is not 0:
                            log.error("*** Failed to upgrade container %s" %
                                      cn)
                            log.error("*** Abort the system upgrade action")
                            break
                        else:
                            succeeded.append(cn)
                            if self.container.is_overlay(cn) > 0:
                                overlay_flag = 1
                        break
            if self.retval is not 0:
                break

        if self.retval is not 0:
            for cn in succeeded:
                self._container_rollback(cn, None, template, True)
            sys.exit(self.retval)

        rc = self._host_upgrade(0, force)

        if ((overlay_flag == 1) and (skipscan == 0) and (rc == 1)):
            # Enable lxc-overlay service in essential by create a flagfile in CONTAINER_MOUNT
            lxcfile = '%s/need_scan_duplicate' % (CONTAINER_MOUNT)
            lxc = open(lxcfile, 'w+')
            lxc.close()

        if ((rc == 1) and (reboot != 0)):
            log.info("rebooting...")
            os.system('reboot')
Ejemplo n.º 15
0
    def _system_upgrade(self, template, reboot, force, skipscan, skip_del):
        containers = self.container.get_container(template)
        overlay_flag = 0

        # By now only support "Pulsar" and "overc" Linux upgrading
        DIST = "Pulsar overc"
        succeeded = []
        for cn in containers:
            self.retval = 0
            if self.container.is_active(cn, template):
                for dist in DIST.split():
                    if dist in self.container.get_issue(cn, template).split():
                        log.info("Updating container %s" % cn)
                        self._container_upgrade(cn, template, True, False, skip_del) #by now only rpm upgrade support
                        if self.retval is not 0:
                            log.error("*** Failed to upgrade container %s" % cn)
                            log.error("*** Abort the system upgrade action")
                            break
                        else:
                            succeeded.append(cn)
                            if self.container.is_overlay(cn) > 0:
                                overlay_flag = 1
                        break
            if self.retval is not 0:
                break

        if self.retval is not 0:
            for cn in succeeded:
                self._container_rollback(cn, None, template, True)
            sys.exit(self.retval)

        rc = self._host_upgrade(0, force)

        if ((overlay_flag == 1) and (skipscan == 0) and (rc == 1)):
            # Enable lxc-overlay service in essential by create a flagfile in CONTAINER_MOUNT
            lxcfile = '%s/need_scan_duplicate' % (CONTAINER_MOUNT)
            lxc = open(lxcfile, 'w+')
            lxc.close()

        if ((rc == 1) and (reboot != 0)):
            log.info("rebooting...")
            os.system('reboot')
Ejemplo n.º 16
0
    def system_rollback(self):
        containers = self.container.get_container(self.args.template)

        # By now only support "Pulsar" and "overc" Linux rollback
        DIST = "Pulsar overc"
        need_reboot=False
        for cn in containers:
            if self.container.is_active(cn, self.args.template):
                for dist in DIST.split():
                    if dist in self.container.get_issue(cn, self.args.template).split():
                        log.info("Rollback container %s" % cn)
                        self._container_rollback(cn, None, self.args.template, True)
                        if self.retval is not 0:
                            log.error("*** Failed to rollback container %s" % cn)
                        else:
                            need_reboot=True
                        break


        self.host_rollback()
        if need_reboot:
            log.info("rebooting...")
            os.system('reboot')