예제 #1
0
파일: build_image.py 프로젝트: uaoh/imager
 def handle_lifecycle_control(self, ctrl):
     """ participant control thread """
     if ctrl.message == "start":
         self.worker_config = dap(worker_config(config=ctrl.config))
         self.launcher = Launcher(
             amqp_host=ctrl.config.get("boss", "amqp_host"),
             amqp_user=ctrl.config.get("boss", "amqp_user"),
             amqp_pass=ctrl.config.get("boss", "amqp_pwd"),
             amqp_vhost=ctrl.config.get("boss", "amqp_vhost"))
예제 #2
0
def launch(process, fields):
    """ BOSS process launcher

    :param process: process definition
    :param fields: dict of workitem fields
    """

    launcher = Launcher(amqp_host = settings.BOSS_HOST,
                        amqp_user = settings.BOSS_USER,
                        amqp_pass = settings.BOSS_PASS,
                        amqp_vhost = settings.BOSS_VHOST)

    launcher.launch(process, fields)
예제 #3
0
파일: models.py 프로젝트: henriksa/imager
def launch(process, fields):
    """ BOSS process launcher

    :param process: process definition
    :param fields: dict of workitem fields
    """

    launcher = Launcher(amqp_host = settings.boss_host,
                        amqp_user = settings.boss_user,
                        amqp_pass = settings.boss_pass,
                        amqp_vhost = settings.boss_vhost)

    launcher.launch(process, fields)
예제 #4
0
def launch(process, fields):
    """ BOSS process launcher

    :param process: process definition
    :param fields: dict of workitem fields
    """

    launcher = Launcher(amqp_host=settings.boss_host,
                        amqp_user=settings.boss_user,
                        amqp_pass=settings.boss_pass,
                        amqp_vhost=settings.boss_vhost)

    fields.update({"priority": "high"})
    launcher.launch(process, fields)
예제 #5
0
def launch(process, fields):
    """ BOSS process launcher

    :param process: process definition file
    :param fields: dict of workitem fields
    """
    with open(process, mode='r') as process_file:
        pdef = process_file.read()

    launcher = Launcher(amqp_host=settings.BOSS_HOST,
                        amqp_user=settings.BOSS_USER,
                        amqp_pass=settings.BOSS_PASS,
                        amqp_vhost=settings.BOSS_VHOST)

    print "launching to (%s,%s)" % (settings.BOSS_HOST, settings.BOSS_VHOST)
    launcher.launch(pdef, fields)
예제 #6
0
 def handle_lifecycle_control(self, ctrl):
     if ctrl.message == "start":
         self.config = tester_config(config=ctrl.config)
         self.launcher = Launcher(amqp_host = ctrl.config.get("boss",
                                                              "amqp_host"),
                                  amqp_user = ctrl.config.get("boss",
                                                              "amqp_user"),
                                  amqp_pass = ctrl.config.get("boss",
                                                              "amqp_pwd"),
                                  amqp_vhost = ctrl.config.get("boss",
                                                               "amqp_vhost")
                                  )
예제 #7
0
 def handle_lifecycle_control(self, ctrl):
     """ participant control thread """
     if ctrl.message == "start":
         self.worker_config = dap(worker_config(config=ctrl.config))
         self.launcher = Launcher(amqp_host = ctrl.config.get("boss",
                                                              "amqp_host"),
                                  amqp_user = ctrl.config.get("boss",
                                                              "amqp_user"),
                                  amqp_pass = ctrl.config.get("boss",
                                                              "amqp_pwd"),
                                  amqp_vhost = ctrl.config.get("boss",
                                                               "amqp_vhost")
                                  )
예제 #8
0
파일: build_image.py 프로젝트: uaoh/imager
class ParticipantHandler(object):
    """Participant class as defined by the SkyNET API"""
    def __init__(self):
        self.worker_config = None
        self.launcher = None
        self.process = \
        """Ruote.process_definition 'create_image_ondemand' do
             sequence do
               set :f => 'debug_dump', :value => 'true'
               update_image_status :status => '%s'
             end
           end
        """

    def handle_wi_control(self, ctrl):
        """ job control thread """
        pass

    def handle_lifecycle_control(self, ctrl):
        """ participant control thread """
        if ctrl.message == "start":
            self.worker_config = dap(worker_config(config=ctrl.config))
            self.launcher = Launcher(
                amqp_host=ctrl.config.get("boss", "amqp_host"),
                amqp_user=ctrl.config.get("boss", "amqp_user"),
                amqp_pass=ctrl.config.get("boss", "amqp_pwd"),
                amqp_vhost=ctrl.config.get("boss", "amqp_vhost"))

    def push_img_status(self, status, fields):
        """ function to push status by launching a process, ?utility """
        fields.update({"priority": "high"})
        self.launcher.launch(self.process % status, fields)

    def handle_wi(self, wid):
        """Handle the workitem so that an image is created from the kickstart
        file correctly. One needs the kickstart as a complete file in the
        workitem, an unique id for image, image type as defined by MIC2, name
        for the image and architecture that the image root filesystem will use.
        """
        wid.result = False
        f = wid.fields
        if not f.msg:
            f.msg = []

        if f.image:
            # new API, image namespace
            args_dict = f.image.as_dict()
        else:
            # old API, flat workitem
            args_dict = {
                "kickstart": f.kickstart,
                "image_id": f.image_id,
                "image_type": f.image_type,
                "name": f.name,
                "arch": f.arch,
                "prefix": f.prefix,
                "extra_opts": f.extra_opts
            }
            f.image = args_dict

        jargs = dap(args_dict)

        if (not jargs.image_id or not jargs.kickstart or not jargs.image_type
                or not jargs.name or not jargs.arch):
            missing = [
                fname for fname in ("image_id", "kickstart", "image_type",
                                    "name", "arch")
                if not (args_dict.has_key(fname) and args_dict[fname])
            ]
            f.__error__ = "One of the mandatory fields: id, kickstart, type,"\
                          " name and arch in the image namespace doesn't exist."
            f.msg.append(f.__error__)
            raise RuntimeError("Missing mandatory fields: %s" %
                               ",".join(missing))

        if jargs.extra_opts:
            if not isinstance(jargs.extra_opts, list):
                f.__error__ = "Expected extra_opts field to be a list"
                f.msg.append(f.__error__)
                raise RuntimeError("Wrong type of field")
        else:
            jargs.extra_opts = []

        if self.worker_config.extra_opts:
            jargs.extra_opts.extend(self.worker_config.extra_opts)

        if (jargs.image_type == "fs"
                and (self.worker_config.fs_pack is not None)):
            jargs.extra_opts.append("--pack-to=%s" %
                                    self.worker_config.fs_pack)

        if not jargs.prefix or jargs.prefix == "":
            jargs.prefix = "requests"

        try:
            worker = ImageWorker(config=self.worker_config, job_args=jargs)

            results = worker.get_results()

            image = f.image.as_dict()

            image.update(results)

            f.image = image

            self.push_img_status("BUILDING", f.as_dict())

            worker.build()

            results = worker.get_results()

            image = f.image.as_dict()

            image.update(results)

            f.image = image

            msg = "Image %s build for arch %s" % (f.image.name, f.image.arch)

            if f.image.result:
                msg = "%s succeeded \nfiles: %s \nimage: %s \nlog %s" % (msg, \
                      f.image.files_url, f.image.image_url,f.image.logfile_url)
            else:
                msg = "%s failed \nlog %s\nerror %s" % (msg, f.image.image_log,
                                                        f.image.error)
                f.__error__ = 'Image build FAILED: %s' % f.image.error
                f.msg.append(f.__error__)

            f.msg.append(msg)

            wid.result = f.image.result
        except Exception, error:
            f.__error__ = 'Image build FAILED: %s' % error
            f.msg.append(f.__error__)
            raise
        finally:
예제 #9
0
        pconf = json.loads("\n".join(lines))
    print "Found valid conf %s.conf" % pdef[:-5]
except IOError as exc:
    # we don't care if there is no .conf file
    # so we ignore errorcode 2 which is file not found
    # otherwise print the error and don't launch the process
    if not exc.errno == 2:
        raise

if workitem:
    wid = open(workitem).read()
    pconf.update(json.loads(wid))

config = ConfigParser.ConfigParser(
                  {"amqp_host" : "127.0.0.1:5672",
                  "amqp_user" : "boss",
                  "amqp_pwd" : "boss",
                  "amqp_vhost" : "boss"
                  })

if os.path.exists("/etc/skynet/skynet.conf"):
    config.readfp(open('/etc/skynet/skynet.conf'))

launcher = Launcher(amqp_host = config.get("boss", "amqp_host"),
                    amqp_user = config.get("boss", "amqp_user"),
                    amqp_pass = config.get("boss", "amqp_pwd"),
                    amqp_vhost = config.get("boss", "amqp_vhost"))

launcher.launch(process, pconf)

예제 #10
0
                 else "" for line in config_file.readlines()]
        pconf = json.loads("\n".join(lines))
    print "Found valid conf %s.conf" % pdef[:-5]
except IOError as exc:
    # we don't care if there is no .conf file
    # so we ignore errorcode 2 which is file not found
    # otherwise print the error and don't launch the process
    if not exc.errno == 2:
        raise

if workitem:
    wid = open(workitem).read()
    pconf.update(json.loads(wid))

config = ConfigParser.ConfigParser({
    "amqp_host": "127.0.0.1:5672",
    "amqp_user": "******",
    "amqp_pwd": "boss",
    "amqp_vhost": "boss"
})

if os.path.exists("/etc/skynet/skynet.conf"):
    config.readfp(open('/etc/skynet/skynet.conf'))

launcher = Launcher(amqp_host=config.get("boss", "amqp_host"),
                    amqp_user=config.get("boss", "amqp_user"),
                    amqp_pass=config.get("boss", "amqp_pwd"),
                    amqp_vhost=config.get("boss", "amqp_vhost"))

launcher.launch(process, pconf)
예제 #11
0
class ParticipantHandler(object):
    """Participant class as defined by the SkyNET API"""

    def __init__(self):
        self.worker_config = None
        self.launcher = None
        self.process = \
        """Ruote.process_definition 'create_image_ondemand' do
             sequence do
               set :f => 'debug_dump', :value => 'true'
               update_image_status :status => '%s'
             end
           end
        """

    def handle_wi_control(self, ctrl):
        """ job control thread """
        pass

    def handle_lifecycle_control(self, ctrl):
        """ participant control thread """
        if ctrl.message == "start":
            self.worker_config = dap(worker_config(config=ctrl.config))
            self.launcher = Launcher(amqp_host = ctrl.config.get("boss",
                                                                 "amqp_host"),
                                     amqp_user = ctrl.config.get("boss",
                                                                 "amqp_user"),
                                     amqp_pass = ctrl.config.get("boss",
                                                                 "amqp_pwd"),
                                     amqp_vhost = ctrl.config.get("boss",
                                                                  "amqp_vhost")
                                     )
 

    def push_img_status(self, status, fields):
        """ function to push status by launching a process, ?utility """
        fields.update({"priority" : "high"})
        self.launcher.launch(self.process % status, fields)

    def handle_wi(self, wid):
        """Handle the workitem so that an image is created from the kickstart
        file correctly. One needs the kickstart as a complete file in the
        workitem, an unique id for image, image type as defined by MIC2, name
        for the image and architecture that the image root filesystem will use.
        """
        wid.result = False
        f = wid.fields
        if not f.msg:
            f.msg = []

        if f.image:
            # new API, image namespace
            args_dict = f.image.as_dict()
        else:
            # old API, flat workitem
            args_dict = {
                          "kickstart" : f.kickstart,
                          "image_id" : f.image_id,
                          "image_type" : f.image_type,
                          "name" : f.name,
                          "arch" : f.arch,
                          "prefix" : f.prefix,
                          "extra_opts" : f.extra_opts
                         }
            f.image = args_dict

        jargs = dap(args_dict)

        if (not jargs.image_id or not jargs.kickstart or not jargs.image_type
            or not jargs.name or not jargs.arch):
            missing = [fname for fname in ("image_id", "kickstart",
                                           "image_type", "name", "arch")
                             if not (args_dict.has_key(fname) and
                                     args_dict[fname])]
            f.__error__ = "One of the mandatory fields: id, kickstart, type,"\
                          " name and arch in the image namespace doesn't exist."
            f.msg.append(f.__error__)
            raise RuntimeError("Missing mandatory fields: %s"
                               % ",".join(missing))

        if jargs.extra_opts:
            if not isinstance(jargs.extra_opts, list):
                f.__error__ = "Expected extra_opts field to be a list"
                f.msg.append(f.__error__)
                raise RuntimeError("Wrong type of field")
        else:
            jargs.extra_opts = []

        if self.worker_config.extra_opts:
            jargs.extra_opts.extend(self.worker_config.extra_opts)

        if (jargs.image_type == "fs" and (self.worker_config.fs_pack is not None)):
            jargs.extra_opts.append("--pack-to=%s" % self.worker_config.fs_pack)

        if not jargs.prefix or jargs.prefix == "":
            jargs.prefix = "requests"

        try:
            worker = ImageWorker(config=self.worker_config,
                                 job_args=jargs)

            results = worker.get_results()

            image = f.image.as_dict()

            image.update(results)

            f.image = image

            self.push_img_status("BUILDING", f.as_dict())

            worker.build()

            results = worker.get_results()

            image = f.image.as_dict()

            image.update(results)

            f.image = image

            msg = "Image %s build for arch %s" % (f.image.name, f.image.arch)

            if f.image.result:
                msg = "%s succeeded \nfiles: %s \nimage: %s \nlog %s" % (msg, \
                      f.image.files_url, f.image.image_url,f.image.logfile_url)
            else:
                msg = "%s failed \nlog %s\nerror %s" % (msg, f.image.image_log,
                                                        f.image.error)
                f.__error__ = 'Image build FAILED: %s' % f.image.error
                f.msg.append(f.__error__)

            f.msg.append(msg)

            wid.result = f.image.result
        except Exception, error:
            f.__error__ = 'Image build FAILED: %s' % error
            f.msg.append(f.__error__)
            raise
        finally: