def initial_admin(): """Inserts an admin user into the database. This fixture is used by Test_user tests""" with app.app_context(): from hil.ext.auth.database import User db.session.add(User(username, password, is_admin=True)) db.session.commit()
def run(self, username, password): if not config.cfg.has_option('extensions', 'hil.ext.auth.database'): sys.exit("'create-admin-user' is only valid with the database auth" " backend.") from hil.ext.auth.database import User model.db.session.add( User(label=username, password=password, is_admin=True)) model.db.session.commit()
def create_admin_user(username, password): """Create an admin user. Only valid for the database auth backend. This must be run on the HIL API server, with access to hil.cfg and the database. It will create an user named <username> with password <password>, who will have administrator privileges. This command should only be used for bootstrapping the system; once you have an initial admin, you can (and should) create additional users via the API. """ if not config.cfg.has_option('extensions', 'hil.ext.auth.database'): sys.exit("'make_inital_admin' is only valid with the database auth" " backend.") from hil import model from hil.model import db from hil.ext.auth.database import User model.init_db() db.session.add(User(label=username, password=password, is_admin=True)) db.session.commit()
def populate_server(): """ this function will populate some mock objects to faciliate testing of the client library """ # create our initial admin user: with app.app_context(): from hil.ext.auth.database import User db.session.add(User(username, password, is_admin=True)) db.session.commit() # Adding nodes, node-01 - node-09 url_node = 'http://127.0.0.1:8000/node/' ipmi = 'http://schema.massopencloud.org/haas/v0/obm/ipmi' for i in range(1, 10): obminfo = { "type": ipmi, "host": "10.10.0.0" + repr(i), "user": "******", "password": "******" } http_client.request('PUT', url_node + 'node-0' + repr(i), data=json.dumps({"obm": obminfo})) http_client.request('PUT', url_node + 'node-0' + repr(i) + '/nic/eth0', data=json.dumps( {"macaddr": "aa:bb:cc:dd:ee:0" + repr(i)})) # Adding Projects proj-01 - proj-03 for i in ["proj-01", "proj-02", "proj-03"]: http_client.request('PUT', 'http://127.0.0.1:8000/project/' + i) # Adding switches one for each driver url_switch = 'http://127.0.0.1:8000/switch/' api_name = 'http://schema.massopencloud.org/haas/v0/switches/' dell_param = { 'type': api_name + 'powerconnect55xx', 'hostname': 'dell-01', 'username': '******', 'password': '******' } nexus_param = { 'type': api_name + 'nexus', 'hostname': 'nexus-01', 'username': '******', 'password': '******', 'dummy_vlan': '333' } mock_param = { 'type': api_name + 'mock', 'hostname': 'mockSwitch-01', 'username': '******', 'password': '******' } brocade_param = { 'type': api_name + 'brocade', 'hostname': 'brocade-01', 'username': '******', 'password': '******', 'interface_type': 'TenGigabitEthernet' } http_client.request('PUT', url_switch + 'dell-01', data=json.dumps(dell_param)) http_client.request('PUT', url_switch + 'nexus-01', data=json.dumps(nexus_param)) http_client.request('PUT', url_switch + 'mock-01', data=json.dumps(mock_param)) http_client.request('PUT', url_switch + 'brocade-01', data=json.dumps(brocade_param)) # Adding ports to the mock switch, Connect nics to ports: for i in range(1, 8): http_client.request('PUT', url_switch + 'mock-01/port/gi1/0/' + repr(i)) http_client.request('POST', url_switch + 'mock-01/port/gi1/0/' + repr(i) + '/connect_nic', data=json.dumps({ 'node': 'node-0' + repr(i), 'nic': 'eth0' })) # Adding port gi1/0/8 to switch mock-01 without connecting it to any node. http_client.request('PUT', url_switch + 'mock-01/port/gi1/0/8') # Adding Projects proj-01 - proj-03 for i in ["proj-01", "proj-02", "proj-03"]: http_client.request('PUT', 'http://127.0.0.1:8000/project/' + i) # Allocating nodes to projects assign_nodes2project('proj-01', 'node-01') assign_nodes2project('proj-02', 'node-02', 'node-04') assign_nodes2project('proj-03', 'node-03', 'node-05') # Assigning networks to projects url_network = 'http://127.0.0.1:8000/network/' for i in ['net-01', 'net-02', 'net-03']: http_client.request('PUT', url_network + i, data=json.dumps({ "owner": "proj-01", "access": "proj-01", "net_id": "" })) for i in ['net-04', 'net-05']: http_client.request('PUT', url_network + i, data=json.dumps({ "owner": "proj-02", "access": "proj-02", "net_id": "" }))
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()