def _render_conf(self, job_name):
     template = Template(CONF_TEMPLATE)
     isos_url = CONF.get('DEFAULT', 'isos_url')
     gitlab_server = CONF.get('DEFAULT', 'gitlab_server')
     git_url = gitlab_server + '/aibuild/' + job_name.split(
         '_')[2] + '-tpl.git'
     worker = self._choose_worker()
     return template.render(isos_url=isos_url,
                            git_url=git_url,
                            worker=worker)
Exemple #2
0
 def __init__(self):
     self.db_api = api.API()
     self.gitlab = gitlab.Gitlab(CONF.get('DEFAULT', 'gitlab_server'),
                                 private_token=CONF.get(
                                     'DEFAULT', 'access_token_gitlab'))
     self.aibuild_group = self._create_group('aibuild')
     self.jenkins = jenkins.Jenkins(
         CONF.get('DEFAULT', 'jenkins_server'),
         username=CONF.get('DEFAULT', 'jenkins_user'),
         password=CONF.get('DEFAULT', 'jenkins_password'))
Exemple #3
0
    def register(self, file=None):
        if not file or not os.path.exists(file):
            print('Please input valid file!')
            return

        url = CONF.get('DEFAULT', 'api_server') + '/env'
        book = xlrd.open_workbook(file)
        sh = book.sheet_by_name('envs')
        for row in range(1, sh.nrows):
            data = {
                'env_name': sh.cell_value(row, 1),
                'auth_url': sh.cell_value(row, 2),
                'project_domain_name': sh.cell_value(row, 3),
                'user_domain_name': sh.cell_value(row, 4),
                'project_name': sh.cell_value(row, 5),
                'username': sh.cell_value(row, 6),
                'password': sh.cell_value(row, 7),
                'region': sh.cell_value(row, 8)
            }
            res = requests.post(url, data=data)
            print('%s: %s' % (row, res.text))
            if res.status_code != '200':
                print('Failed to register %s env!' % sh.cell_value(row, 1))
                continue

        print('End registering env info!')
def get_servers():
    gitlab_server = CONF.get('DEFAULT', 'gitlab_server')
    access_token = CONF.get('DEFAULT', 'access_token_gitlab')
    print('Gitlab server %s access token %s' % (gitlab_server, access_token))
    gl = gitlab.Gitlab(gitlab_server, private_token=access_token)

    jenkins_server = CONF.get('DEFAULT', 'jenkins_server')
    jenkins_user = CONF.get('DEFAULT', 'jenkins_user')
    jenkins_password = CONF.get('DEFAULT', 'jenkins_password')
    print('Jenkins server %s user %s passwd %s' %
          (jenkins_server, jenkins_user, jenkins_password))
    jk = jenkins.Jenkins(jenkins_server,
                         username=jenkins_user,
                         password=jenkins_password)

    return gl, jk
 def _display_projects(self):
     print('===============================')
     projects = self.gl.projects.list()
     gitlab_server = CONF.get('DEFAULT', 'gitlab_server')
     for pr in projects:
         line = pr.name + ': ' + gitlab_server + '/' + pr.name + '.git'
         print(line)
Exemple #6
0
def create_tables():
    print('This operation is DANGEROUS. Please backup database first!!!')
    url = CONF.get('DEFAULT', 'db_connection')
    print('url: %s' % url)
    engine = sqlalchemy.create_engine(url, echo=True)
    # Clean
    models.Base.metadata.drop_all(engine)
    models.Base.metadata.create_all(engine)
    def _add_hook_on_gitlab(self):
        hooks = []
        for job in self.jk.get_jobs():
            job_name = job.get('name')
            # Gen project name of gitlab
            project_name = job_name.split('_')[2] + '-tpl'
            project = self.gl.projects.get('aibuild' + '/' + project_name)
            url = CONF.get('DEFAULT',
                           'jenkins_server') + '/project/' + job_name
            hook = project.hooks.create({'url': url, 'push_events': 1})
            hooks.append(hook)

        return hooks
Exemple #8
0
    def register(self, file=None):
        if not file or not os.path.exists(file):
            print('Please input valid xls file')
            return

        url = CONF.get('DEFAULT', 'api_server') + '/guestos'
        book = xlrd.open_workbook(file)
        sh = book.sheet_by_name('guestos')
        for row in range(1, sh.nrows):
            data = {
                'name': sh.cell_value(row, 1),
                'base_iso': sh.cell_value(row, 2),
                'type': sh.cell_value(row, 3),
                'distro': sh.cell_value(row, 4),
                'version': sh.cell_value(row, 5),
            }
            res = requests.post(url, data=data)
            print('%s: %s' % (row, res.text))

        print('End registering guest os!')
Exemple #9
0
 def _create_job(self, kwargs):
     job_name = 'image_build_' + kwargs.get('name')
     web_server = CONF.get('DEFAULT', 'web_server')
     conf_xml = self._render_conf(job_name, kwargs.get('base_iso'),
                                  web_server)
     self.jenkins.create_job(job_name, conf_xml)
Exemple #10
0
 def _add_webhook(self, kwargs):
     job_name = 'image_build_' + kwargs.get('name')
     project_name = kwargs.get('name') + '_tpl'
     project = self.gitlab.projects.get('aibuild' + '/' + project_name)
     url = CONF.get('DEFAULT', 'jenkins_server') + '/project/' + job_name
     return project.hooks.create({'url': url, 'push_events': 1})
Exemple #11
0
 def __init__(self):
     super(API, self).__init__()
     url = CONF.get('DEFAULT', 'db_connection')
     self.engine = sqlalchemy.create_engine(url)
Exemple #12
0
def get_vm_addr(dom_name):
    conn = libvirt.open('qemu:///system')
    dom = conn.lookupByName(dom_name)
    ifaces = dom.interfaceAddresses(
        libvirt.VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_LEASE)
    # Only one interface
    for (name, val) in ifaces.iteritems():
        if val['addrs']:
            for addr in val['addrs']:
                conn.close()
                return addr['addr']

    conn.close()
    return None


def send_test_result(image, case, result):
    '''
    Send result of testcase to aibuild-server
    :param image: name of image tested
    :param case: name of test case
    :param result: result of this test
    :return:
    '''
    url = CONF.get('DEFAULT', 'api_server') + '/test'
    data = {'image_name': image, 'case_name': case, 'result': result}
    res = requests.post(url, data=data)
    if res.status_code != '200':
        print('Failed to record result of this test')
Exemple #13
0
import os

from pecan.deploy import deploy

from aibuild.common.config import CONF

CONFIG_PATH = 'pecan_config_path'

# fix pecan configuration name
config_path = CONF.get('DEFAULT', CONFIG_PATH)
application = deploy(os.path.abspath(config_path))