def network_create(network, owner, access, net_id): """Create a network. If the network with that name already exists, a DuplicateError will be raised. If the combination of owner, access, and net_id is illegal, a BadArgumentError will be raised. If network ID allocation was requested, and the network cannot be allocated (due to resource exhaustion), an AllocationError will be raised. Pass 'admin' as owner for an administrator-owned network. Pass '' as access for a publicly accessible network. Pass '' as net_id if you wish to use the HIL's network-id allocation pool. Details of the various combinations of network attributes are in docs/networks.md """ auth_backend = get_auth_backend() absent_or_conflict(model.Network, network) # Check authorization and legality of arguments, and find correct 'access' # and 'owner' if owner != "admin": owner = get_or_404(model.Project, owner) auth_backend.require_project_access(owner) # Project-owned network if access != owner.label: raise errors.BadArgumentError( "Project-owned networks must be accessible by the owner.") if net_id != "": raise errors.BadArgumentError( "Project-owned networks must use network ID allocation") access = [get_or_404(model.Project, access)] else: # Administrator-owned network auth_backend.require_admin() owner = None if access == "": access = [] else: access = [get_or_404(model.Project, access)] # Allocate net_id, if requested if net_id == "": net_id = get_network_allocator().get_new_network_id() if net_id is None: raise errors.AllocationError('No more networks') else: if not get_network_allocator().validate_network_id(net_id): raise errors.BadArgumentError("Invalid net_id") get_network_allocator().claim_network_id(net_id) allocated = get_network_allocator().is_network_id_in_pool(net_id) network = model.Network(owner, access, allocated, net_id, network) db.session.add(network) db.session.commit()
def network(self): """Create a network object (and associated project) to work with.""" project = model.Project('anvil-nextgen') return model.Network(project, [project], True, '102', 'hammernet')
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()
def network(self): project = model.Project('anvil-nextgen') return model.Network(project, [project], True, '102', 'hammernet')