コード例 #1
0
def test_lab(lab_src_url, version=None):
    # check out the source with version provided
        # is repo already exists? if yes, then do a git pull
        # else clone the repo
    # get the labspec from /scripts/lab_spec.json
    # get the appropriate the actions from lab_spec.json
    # run LabAction Runner
        # instantiate the object
    e = EnvSetUp.Instance()
    git = GitCommands()
    logger.info("Environment http_proxy = %s" % os.environ["http_proxy"])
    logger.info("Environment https_proxy = %s" % os.environ["https_proxy"])

    def fill_aptconf():

        try:
            http_proxy = os.environ["http_proxy"]
            https_proxy = os.environ["https_proxy"]
            http_cmd = r'echo "Acquire::http::Proxy \"%s\";"%s' % (http_proxy, '>>/etc/apt/apt.conf')
            https_cmd = r'echo "Acquire::https::Proxy \"%s\";"%s' % (https_proxy, '>>/etc/apt/apt.conf')
            (ret_code, output) = execute_command(http_cmd)
            (ret_code, output) = execute_command(https_cmd)
        except Exception, e:
            logger.error("Writing to /etc/apt/apt.conf failed with error: %s"
                         % (str(e)))
            raise e
コード例 #2
0
def execute(command):
    # do some validation
    try:
        logger.info("Command executed: " + command)
        (ret_code, output) = execute_command(command)
        return output
    except Exception, e:
        logger.error("Execution failed: " + str(e))
        return "Error executing the command: " + str(e)
コード例 #3
0
ファイル: controller.py プロジェクト: vlead/ovpl
    def test_lab(self, current_user, lab_id, lab_src_url, revision_tag=None):
        logger.debug("test_lab() for lab ID %s, git url %s, current user %s"
                     % (lab_id, lab_src_url, current_user))
        try:
            '''
            record_list = self.state.read_record(lab_src_url)
            if record_list:
                msg = "Lab with the url = %s is already deployed" % lab_src_url
                logger.debug(msg)
                return msg
            '''
            # Get lab sources and from it the deployment specification
            # of the lab
            self.lab_spec = self.labmgr.get_lab_reqs(lab_src_url,
                                                     revision_tag)
            self.update_lab_spec(lab_id, lab_src_url, revision_tag)

            # create a VM to deploy the lab
            logger.debug("test_lab(); invoking create_vm() on vmpoolmgr")
            self.deploy_record.record = self.vmpoolmgr.create_vm(self.lab_spec)

            logger.debug("test_lab(): Returned from VMPool = %s" %
                         (str(self.deploy_record.record)))
            ip = self.deploy_record.record['vm_info']['vm_ip']
            port = self.deploy_record.record['vm_info']['vm_port']
            vmmgrurl = "http://" + ip
            lab_id = self.deploy_record.record['lab_spec']['lab_id']
            logger.debug("test_lab(): vmmgrurl = %s" % (vmmgrurl))

            # deploy the lab on the newly created container.
            try:
                (ret_val, ret_str) = self.labmgr.test_lab(vmmgrurl,
                                                          port,
                                                          lab_src_url,
                                                          revision_tag)
                if(ret_val):
                    self.update_deploy_record(current_user)
                    self.state.save(self.deploy_record.record)
                    logger.info("test_lab(): test succcessful, ip = %s" % ip)

                    if(base_config.ADS_USING_HOOKS):
                        domain_name = self.register_lab(lab_id, ip)
                        return domain_name + "\n" + "(Note : Very soon you will be allowed to access lab using given domain name)"
                    else:
                        return ip
                else:
                    logger.error("test_lab(); Test failed with error:" +
                                 str(ret_str))
                    return "Test failed: See log file for errors"
            except Exception, e:
                logger.error("test_lab(); Test failed with error: %s" % str(e))
                return "Test failed: See log file for errors"
        except Exception, e:
            logger.error("test_lab(): Test failed with error: %s" % str(e))
            return "Test failed: See log file for errors"
コード例 #4
0
 def post(self):
     post_data = dict(urlparse.parse_qsl(self.request.body))
     logger.info(
         "vm_manager_server: TestLabHandler: post(): post_data = %s" %
         str(post_data))
     logger.debug(
         "lab_src_url = %s, version = %s" %
         (post_data['lab_src_url'], post_data.get('version', None)))
     self.write(
         vm_manager.test_lab(post_data['lab_src_url'],
                             post_data.get('version', None)))
コード例 #5
0
    def test_lab(self, current_user, lab_id, lab_src_url, revision_tag=None):
        logger.debug("test_lab() for lab ID %s, git url %s, current user %s" %
                     (lab_id, lab_src_url, current_user))
        try:
            '''
            record_list = self.state.read_record(lab_src_url)
            if record_list:
                msg = "Lab with the url = %s is already deployed" % lab_src_url
                logger.debug(msg)
                return msg
            '''
            # Get lab sources and from it the deployment specification
            # of the lab
            self.lab_spec = self.labmgr.get_lab_reqs(lab_src_url, revision_tag)
            self.update_lab_spec(lab_id, lab_src_url, revision_tag)

            # create a VM to deploy the lab
            logger.debug("test_lab(); invoking create_vm() on vmpoolmgr")
            self.deploy_record.record = self.vmpoolmgr.create_vm(self.lab_spec)

            logger.debug("test_lab(): Returned from VMPool = %s" %
                         (str(self.deploy_record.record)))
            ip = self.deploy_record.record['vm_info']['vm_ip']
            port = self.deploy_record.record['vm_info']['vm_port']
            vmmgrurl = "http://" + ip
            lab_id = self.deploy_record.record['lab_spec']['lab_id']
            logger.debug("test_lab(): vmmgrurl = %s" % (vmmgrurl))

            # deploy the lab on the newly created container.
            try:
                (ret_val,
                 ret_str) = self.labmgr.test_lab(vmmgrurl, port, lab_src_url,
                                                 revision_tag)
                if (ret_val):
                    self.update_deploy_record(current_user)
                    self.state.save(self.deploy_record.record)
                    logger.info("test_lab(): test succcessful, ip = %s" % ip)

                    if (base_config.ADS_USING_HOOKS):
                        domain_name = self.register_lab(lab_id, ip)
                        return domain_name + "\n" + "(Note : Very soon you will be allowed to access lab using given domain name)"
                    else:
                        return ip
                else:
                    logger.error("test_lab(); Test failed with error:" +
                                 str(ret_str))
                    return "Test failed: See log file for errors"
            except Exception, e:
                logger.error("test_lab(); Test failed with error: %s" % str(e))
                return "Test failed: See log file for errors"
        except Exception, e:
            logger.error("test_lab(): Test failed with error: %s" % str(e))
            return "Test failed: See log file for errors"
コード例 #6
0
ファイル: vm_manager_server.py プロジェクト: ksripathi/ovpl
 def post(self):
     post_data = dict(urlparse.parse_qsl(self.request.body))
     logger.info("vm_manager_server: TestLabHandler: post(): post_data = %s" % str(post_data))
     logger.debug("lab_src_url = %s, version = %s" % (post_data['lab_src_url'], post_data.get('version', None)))
     self.write(vm_manager.test_lab(post_data['lab_src_url'], post_data.get('version', None)))
コード例 #7
0
ファイル: vm_manager_server.py プロジェクト: ksripathi/ovpl
class TestLabHandler(tornado.web.RequestHandler):
    def post(self):
        post_data = dict(urlparse.parse_qsl(self.request.body))
        logger.info("vm_manager_server: TestLabHandler: post(): post_data = %s" % str(post_data))
        logger.debug("lab_src_url = %s, version = %s" % (post_data['lab_src_url'], post_data.get('version', None)))
        self.write(vm_manager.test_lab(post_data['lab_src_url'], post_data.get('version', None)))

    def get(self):
        logger.info("vm_manager_server: TestLabHandler: get()")
        self.write("Hello World")


if __name__ == "__main__":

    e = EnvSetUp.Instance()
    logger.info("vm_manager_server: __main()")
    tornado.options.parse_command_line()
    app = tornado.web.Application(
        handlers=[
            (r"/api/1.0/disk-usage", DiskUsageHandler),
            (r"/api/1.0/mem-usage", MemUsageHandler),
            (r"/api/1.0/running-time", RunningTimeHandler),
            (r"/api/1.0/running-processes", RunningProcHandler),
            (r"/api/1.0/cpu-load", CPULoadHandler),
            (r"/api/1.0/execute/([\w*\d*\%\-]+)", ExecuteHandler),
            (r"/api/1.0/test-lab", TestLabHandler)
        ],
        debug=False)
    http_server = tornado.httpserver.HTTPServer(app)
    http_server.listen(options.port)
    tornado.ioloop.IOLoop.instance().start()
コード例 #8
0
 def get(self):
     logger.info("vm_manager_server: TestLabHandler: get()")
     self.write("Hello World")
コード例 #9
0
def cpu_load():
    logger.info("Command executed: ps -e -o pcpu")
    return execute("ps -e -o pcpu | awk '{s+=$1} END {print s\"%\"}'")
コード例 #10
0
def running_processes():
    logger.info("Command executed: ps -e -o command")
    return execute("ps -e -o command")
コード例 #11
0
def disk_usage():
    logger.info("Command executed: df -h")
    return execute("df -h")
コード例 #12
0
def mem_usage():
    logger.info("Command executed: free -mg")
    return execute("free -mg")
コード例 #13
0
ファイル: vm_manager_server.py プロジェクト: ksripathi/ovpl
 def get(self):
     logger.info("vm_manager_server: TestLabHandler: get()")
     self.write("Hello World")
コード例 #14
0
                         % (str(e)))
            raise e

    def get_build_steps_spec(lab_spec):
        return {"build_steps": lab_spec['lab']['build_requirements']['platform']['build_steps']}

    def get_build_installer_steps_spec(lab_spec):
        return {"installer": lab_spec['lab']['build_requirements']['platform']['installer']}

    def get_runtime_installer_steps(lab_spec):
        return {"installer": lab_spec['lab']['runtime_requirements']['platform']['installer']}

    def get_runtime_actions_steps(lab_spec):
        return lab_spec['lab']['runtime_requirements']['platform']['lab_actions']

    logger.info("Starting test_lab")

    try:
        fill_aptconf()
        repo_name = git.construct_repo_name(lab_src_url)
        lab_spec = git.get_lab_spec(repo_name)
        spec_path = git.get_spec_path(repo_name)
        logger.debug("spec_path: %s" % spec_path)
        os.chdir(spec_path)
        logger.debug("Changed to Diretory: %s" % spec_path)
        logger.debug("CWD: %s" % str(os.getcwd()))

        lar = LabActionRunner(get_build_installer_steps_spec(lab_spec))
        lar.run_install_source()

        lar = LabActionRunner(get_build_steps_spec(lab_spec))
コード例 #15
0
 def status(steps):
     logger.info("Checking the status of the build...")
     if steps.has_key(LabActionScript.CHECK_STATUS_SCRIPT_KEY):
         return self._run_(steps[LabActionScript.CHECK_STATUS_SCRIPT_KEY])
     return 0
コード例 #16
0
 def post_build(steps):
     logger.info("Running the post-build scripts...")
     if steps.has_key(LabActionScript.POST_BUILD_SCRIPT_KEY):
         self._run_(steps[LabActionScript.POST_BUILD_SCRIPT_KEY])
コード例 #17
0
 def configure(steps):
     logger.info("Configuring the lab...")
     if steps.has_key(LabActionScript.CONFIGURE_SCRIPT_KEY):
         self._run_(steps[LabActionScript.CONFIGURE_SCRIPT_KEY])
コード例 #18
0
def running_time():
    logger.info("Command executed: uptime")
    return execute("uptime")
コード例 #19
0
        logger.debug(
            "lab_src_url = %s, version = %s" %
            (post_data['lab_src_url'], post_data.get('version', None)))
        self.write(
            vm_manager.test_lab(post_data['lab_src_url'],
                                post_data.get('version', None)))

    def get(self):
        logger.info("vm_manager_server: TestLabHandler: get()")
        self.write("Hello World")


if __name__ == "__main__":

    e = EnvSetUp.Instance()
    logger.info("vm_manager_server: __main()")
    tornado.options.parse_command_line()
    app = tornado.web.Application(handlers=[
        (r"/api/1.0/disk-usage", DiskUsageHandler),
        (r"/api/1.0/mem-usage", MemUsageHandler),
        (r"/api/1.0/running-time", RunningTimeHandler),
        (r"/api/1.0/running-processes", RunningProcHandler),
        (r"/api/1.0/cpu-load", CPULoadHandler),
        (r"/api/1.0/execute/([\w*\d*\%\-]+)", ExecuteHandler),
        (r"/api/1.0/test-lab", TestLabHandler)
    ],
                                  debug=False)
    http_server = tornado.httpserver.HTTPServer(app)
    http_server.listen(options.port)
    tornado.ioloop.IOLoop.instance().start()