Ejemplo n.º 1
0
def headnode_create(headnode, project, base_img):
    """Create headnode.

    If a headnode with the same name already exists, a DuplicateError will be
    raised.

    If the project does not exist, a NotFoundError will be raised.

    If the base image does not exist (is not specified in hil.cfg) a
    BadArgumentError will be raised.
    """

    valid_imgs = cfg.get('headnode', 'base_imgs')
    valid_imgs = [img.strip() for img in valid_imgs.split(',')]

    if base_img not in valid_imgs:
        raise errors.BadArgumentError('Provided image is not a valid image.')

    absent_or_conflict(model.Headnode, headnode)
    project = get_or_404(model.Project, project)
    get_auth_backend().require_project_access(project)

    headnode = model.Headnode(project, headnode, base_img)

    db.session.add(headnode)
    db.session.commit()
Ejemplo n.º 2
0
def create_bigint_db():
    """Create database objects used in 'after-PK-bigint.sql'"""
    from hil.ext.switches.n3000 import DellN3000
    from hil.ext.switches.dell import PowerConnect55xx
    from hil.ext.switches.brocade import Brocade
    from hil.ext.switches.nexus import Nexus
    from hil.ext.switches.mock import MockSwitch
    from hil.ext.obm.ipmi import Ipmi
    from hil.ext.obm.mock import MockObm
    from hil.ext.auth.database import User
    from hil.ext.auth import database as dbauth
    with app.app_context():
        db.session.add(
            DellN3000(label='sw-n3000',
                      hostname='host',
                      username='******',
                      password='******',
                      dummy_vlan='5',
                      type=DellN3000.api_name))
        dell1 = PowerConnect55xx(label='sw-dell',
                                 hostname='host',
                                 username='******',
                                 password='******',
                                 type=PowerConnect55xx.api_name)
        db.session.add(dell1)
        db.session.add(
            Nexus(label='sw-nexus',
                  hostname='host',
                  username='******',
                  password='******',
                  dummy_vlan='5',
                  type=Nexus.api_name))
        db.session.add(
            Brocade(label='sw-brocade',
                    hostname='host',
                    username='******',
                    password='******',
                    interface_type='4',
                    type=Brocade.api_name))
        db.session.add(
            MockSwitch(label='sw0',
                       hostname='host',
                       username='******',
                       password='******',
                       type=MockSwitch.api_name))
        proj = model.Project(label='runway')
        db.session.add(proj)
        headnode1 = model.Headnode(label='runway_headnode',
                                   project=proj,
                                   base_img='image1')
        db.session.add(headnode1)
        db.session.add(model.Hnic(label='hnic1', headnode=headnode1))
        ipmi = Ipmi(host='host', user='******', password='******')
        db.session.add(ipmi)
        mock_obm = MockObm(host='host', user='******', password='******')
        db.session.add(mock_obm)
        node1 = model.Node(label='node-1', obm=ipmi)
        db.session.add(node1)

        db.session.add(
            model.Metadata(label='meta',
                           value="it is a true value",
                           node=node1))
        network1 = model.Network(owner=None,
                                 access=[proj],
                                 allocated=False,
                                 network_id="networking network",
                                 label='hil wireless')
        db.session.add(network1)
        nic1 = model.Nic(node=node1, label='pxe', mac_addr='ff:ff:ff:ff:ff:fe')
        model.Port(label='A fine port', switch=dell1)
        db.session.add(nic1)
        db.session.add(
            model.NetworkAttachment(nic=nic1, network_id=1,
                                    channel='vlan/100'))
        db.session.add(
            model.NetworkingAction(type='modify_port',
                                   nic=nic1,
                                   new_network=network1,
                                   channel='vlan/100'))
        jim = User(label='jim', password='******', is_admin=True)
        db.session.add(jim)

        local.auth = dbauth.User.query.filter_by(label='jim').one()

        dbauth.user_add_project('jim', 'runway')

        db.session.commit()

        # Original password is "pass"
        db.session.query(User).get(1).hashed_password = \
            ('$6$rounds=656000$iTyrApYTUhMx4b4g$YcaMExV'
             'YtS0ut2yXWrT64OggFpE4lLg12QsAuyMA3YKX6Czth'
             'XeisA47dJZW9GwU2q2CTIVrsbpxAVT64Pih2/')
        db.session.commit()