Esempio n. 1
0
 def test_labmgr_test_lab():
     vmmgrurl = "http://172.16.0.2"
     lab_src_url = \
         "https://github.com/Virtual-Labs/computer-programming-iiith.git"
     port = "9089"
     revision_tag = None
     labmgr = LabManager()
     try:
         (ret_val, ret_str) = labmgr.test_lab(vmmgrurl, port, lab_src_url,
                                              revision_tag)
     except Exception, e:
         logger.error("test_lab(); Test failed with error: " + str(e))
Esempio n. 2
0
 def test_labmgr_test_lab():
     vmmgrurl = "http://172.16.0.2"
     lab_src_url = \
         "https://github.com/Virtual-Labs/computer-programming-iiith.git"
     port = "9089"
     revision_tag = None
     labmgr = LabManager()
     try:
         (ret_val, ret_str) = labmgr.test_lab(vmmgrurl,
                                              port,
                                              lab_src_url,
                                              revision_tag)
     except Exception, e:
         logger.error("test_lab(); Test failed with error: " + str(e))
Esempio n. 3
0
class Controller:
    state = None
    lab_spec = None
    lab_deployment_record = None
    labmgr = None
    vmpoolmgr = None
    git = None
    deploy_recod = None

    def __init__(self):
        self.state = State.Instance()
        self.lab_spec = {}
        self.labmgr = LabManager()
        self.vmpoolmgr = VMPoolManager()
        self.git = GitCommands()
        self.deploy_record = Record()

    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"
Esempio n. 4
0
class Controller:
    state = None
    lab_spec = None
    lab_deployment_record = None
    labmgr = None
    vmpoolmgr = None
    git = None
    deploy_recod = None

    def __init__(self):
        self.state = State.Instance()
        self.lab_spec = {}
        self.labmgr = LabManager()
        self.vmpoolmgr = VMPoolManager()
        self.git = GitCommands()
        self.deploy_record = Record()

    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"