def network_delete(network): """Delete network. If the network does not exist, a NotFoundError will be raised. """ db = model.Session() network = _must_find(db, model.Network, network) if cfg.getboolean('recursive', 'rHaaS'): bHaaS_out = check_output(['haas','network_delete', network.label+'_'+network.creator.label], stderr=STDOUT, shell=False) error_checker(bHaaS_out) else: if network.nics: raise BlockedError("Network still connected to nodes") if network.hnics: raise BlockedError("Network still connected to headnodes") if network.scheduled_nics: raise BlockedError("Network scheduled to become connected to nodes.") if network.allocated: driver_name = cfg.get('general', 'driver') driver = importlib.import_module('haas.drivers.' + driver_name) driver.free_network_id(db, network.network_id) db.delete(network) if cfg.getboolean('recursive', 'rHaaS'): b_project = cfg.get('recursive', 'project') network_name = network.label + b_project cli.network_delete(network_name) db.commit()
def get_switch_vlans(vlan_list): config = json.loads(cfg.get('driver simple_vlan', 'switch')) driver = importlib.import_module('haas.drivers.switches.' + config['switch']) returnee = driver.get_switch_vlans(config, vlan_list) # Remove the trunk port from the vlan_lists trunk_port = cfg.get('driver simple_vlan', 'trunk_port') for vlan in returnee: if trunk_port in returnee[vlan]: returnee[vlan].remove(trunk_port) return returnee
def headnode_create(headnode, project, base_img): """Create headnode. If a node with the same name already exists, a DuplicateError will be raised. If the project already has a headnode, a DuplicateError will be raised. If the project does not exist, a NotFoundError will be raised. """ if not cfg.getboolean('recursive', 'rHaaS'): 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 BadArgumentError('Provided image is not a valid image.') # first check the local database to make sure the headnode doesn't already exist # and the project is valid db = model.Session() _assert_absent(db, model.Headnode, headnode) project = _must_find(db, model.Project, project) #check for recursive HaaS instance, pass down to base HaaS and check for success/failure if cfg.getboolean('recursive', 'rHaaS'): b_project = cfg.get('recursive', 'project') bHaaS_out = check_output([ 'haas', 'headnode_create', headnode + '_' + project.label, b_project, base_img ], stderr=STDOUT, shell=False) error_checker(bHaaS_out) #else if not recursive, do anything that should only happen @ bHaaS else: 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 BadArgumentError('Provided image is not a valid image.') headnode = model.Headnode(project, headnode, base_img) db.add(headnode) db.commit()
def headnode_create(headnode, project, base_img): """Create headnode. If a node with the same name already exists, a DuplicateError will be raised. If the project already has a headnode, a DuplicateError will be raised. If the project does not exist, a NotFoundError 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 BadArgumentError('Provided image is not a valid image.') db = model.Session() _assert_absent(db, model.Headnode, headnode) project = _must_find(db, model.Project, project) headnode = model.Headnode(project, headnode, base_img) db.add(headnode) db.commit()
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 haas.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 BadArgumentError('Provided image is not a valid image.') _assert_absent(model.Headnode, headnode) project = _must_find(model.Project, project) get_auth_backend().require_project_access(project) headnode = model.Headnode(project, headnode, base_img) db.session.add(headnode) db.session.commit()
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 (not specified in haas.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 BadArgumentError('Provided image is not a valid image.') _assert_absent(model.Headnode, headnode) project = _must_find(model.Project, project) get_auth_backend().require_project_access(project) headnode = model.Headnode(project, headnode, base_img) db.session.add(headnode) db.session.commit()
def set_access_vlan(port, vlan_id): # load the configuration: switch_ip = cfg.get('switch dell', 'ip') switch_user = cfg.get('switch dell', 'user') switch_pass = cfg.get('switch dell', 'pass') # connect to the switch, and log in: console = pexpect.spawn('telnet ' + switch_ip) console.expect('User Name:') console.sendline(switch_user) console.expect('Password:'******'[\r\n]+.+#') cmd_prompt = console.after cmd_prompt = cmd_prompt.strip(' \r\n\t') #:-1 omits the last hash character config_prompt = re.escape(cmd_prompt[:-1] + '(config)#') if_prompt = re.escape(cmd_prompt[:-1] + '(config-if)#') main_prompt = re.escape(cmd_prompt) # select the right interface: console.sendline('config') console.expect(config_prompt) console.sendline('int gi1/0/%d' % port) console.expect(if_prompt) # set the vlan: console.sendline('sw access vlan %d' % vlan_id) console.expect(if_prompt) # set it to access mode: console.sendline('sw mode access') console.expect(if_prompt) # log out: console.sendline('exit') console.expect(config_prompt) console.sendline('exit') console.expect(main_prompt) console.sendline('exit') console.expect(pexpect.EOF)
def set_access_vlan(port, vlan_id): # load the configuration: switch_ip = cfg.get("switch dell", "ip") switch_user = cfg.get("switch dell", "user") switch_pass = cfg.get("switch dell", "pass") # connect to the switch, and log in: console = pexpect.spawn("telnet " + switch_ip) console.expect("User Name:") console.sendline(switch_user) console.expect("Password:"******"[\r\n]+.+#") cmd_prompt = console.after cmd_prompt = cmd_prompt.strip(" \r\n\t") #:-1 omits the last hash character config_prompt = re.escape(cmd_prompt[:-1] + "(config)#") if_prompt = re.escape(cmd_prompt[:-1] + "(config-if)#") main_prompt = re.escape(cmd_prompt) # select the right interface: console.sendline("config") console.expect(config_prompt) console.sendline("int gi1/0/%d" % port) console.expect(if_prompt) # set the vlan: console.sendline("sw access vlan %d" % vlan_id) console.expect(if_prompt) # set it to access mode: console.sendline("sw mode access") console.expect(if_prompt) # log out: console.sendline("exit") console.expect(config_prompt) console.sendline("exit") console.expect(main_prompt) console.sendline("exit") console.expect(pexpect.EOF)
def _on_virt_uri(args_list): """Make an argument list to libvirt tools use right URI. This will work for virt-clone and virsh, at least. It gets the appropriate endpoint URI from the config file. """ libvirt_endpoint = cfg.get('headnode', 'libvirt_endpoint') return [args_list[0], '--connect', libvirt_endpoint] + args_list[1:]
def headnode_create(headnode, project, base_img): """Create headnode. If a node with the same name already exists, a DuplicateError will be raised. If the project already has a headnode, a DuplicateError will be raised. If the project does not exist, a NotFoundError will be raised. """ if not cfg.getboolean('recursive', 'rHaaS'): 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 BadArgumentError('Provided image is not a valid image.') # first check the local database to make sure the headnode doesn't already exist # and the project is valid db = model.Session() _assert_absent(db, model.Headnode, headnode) project = _must_find(db, model.Project, project) #check for recursive HaaS instance, pass down to base HaaS and check for success/failure if cfg.getboolean('recursive', 'rHaaS'): b_project = cfg.get('recursive', 'project') bHaaS_out = check_output(['haas','headnode_create', headnode+'_'+project.label, b_project, base_img],stderr=STDOUT, shell=False) error_checker(bHaaS_out) #else if not recursive, do anything that should only happen @ bHaaS else: 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 BadArgumentError('Provided image is not a valid image.') headnode = model.Headnode(project, headnode, base_img) db.add(headnode) db.commit()
def object_url(*args): # Prefer an environmental variable for getting the endpoint if available. url = os.environ.get('HAAS_ENDPOINT') if url is None: url = cfg.get('client', 'endpoint') for arg in args: url += '/' + urllib.quote(arg,'') return url
def init_db(uri=None): """Start up the DB connection. `uri` is the uri to use for the databse. If it is None, the uri from the config file will be used. """ if uri is None: uri = cfg.get('database', 'uri') app.config.update(SQLALCHEMY_DATABASE_URI=uri)
def object_url(*args): # Prefer an environmental variable for getting the endpoint if available. url = os.environ.get('HAAS_ENDPOINT') if url is None: url = cfg.get('client', 'endpoint') for arg in args: url += '/' + urllib.quote(arg, '') return url
def network_create(network, creator, access, net_id): """Create a network. If the network with that name already exists, a DuplicateError will be raised. If the combination of creator, 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 creator for an administrator-owned network. Pass '' as access for a publicly accessible network. Pass '' as net_id if you wish to use the HaaS's network-id allocation pool. Details of the various combinations of network attributes are in docs/networks.md """ db = model.Session() _assert_absent(db, model.Network, network) # Check legality of arguments, and find correct 'access' and 'creator' if creator != "admin": # Project-owned network if access != creator: raise BadArgumentError( "Project-created networks must be accessed only by that project." ) if net_id != "": raise BadArgumentError( "Project-created networks must use network ID allocation") creator = _must_find(db, model.Project, creator) access = _must_find(db, model.Project, access) else: # Administrator-owned network creator = None if access == "": access = None else: access = _must_find(db, model.Project, access) # Allocate net_id, if requested if net_id == "": driver_name = cfg.get('general', 'driver') driver = importlib.import_module('haas.drivers.' + driver_name) net_id = driver.get_new_network_id(db) if net_id is None: raise AllocationError('No more networks') allocated = True else: allocated = False network = model.Network(creator, access, allocated, net_id, network) db.add(network) db.commit()
def list_headnode_images(): """Show headnode images listed in config file. Returns a JSON array of strings representing a list of headnode images. Example: '["headnode1.img", "headnode2.img", "headnode3.img"]' """ valid_imgs = cfg.get('headnode', 'base_imgs') valid_imgs = sorted([img.strip() for img in valid_imgs.split(',')]) return json.dumps(valid_imgs)
def get_switch_vlans(vlan_list): switches = json.loads(cfg.get('driver complex_vlan', 'switch')) returnee = {} for vlan in vlan_list: returnee[vlan] = [] for switch in switches: driver = importlib.import_module('haas.drivers.switches.' + switch['switch']) submap = driver.get_switch_vlans(switch, vlan_list) for vlan in submap: for port in submap[vlan]: returnee[vlan].append(switch['name'] + "::" + port) # Remove the trunk port from the vlan_lists trunk_ports = json.loads(cfg.get('driver complex_vlan', 'trunk_ports')) for vlan in returnee: for trunk_port in trunk_ports: if trunk_port in returnee[vlan]: returnee[vlan].remove(trunk_port) return returnee
def apply_networking(net_map): switches = json.loads(cfg.get('driver complex_vlan', 'switch')) for switch in switches: submap = {} name = switch["name"] driver = importlib.import_module('haas.drivers.switches.' + switch["switch"]) for net_entry in net_map: switch_id, port_id = net_entry.split("::") if switch_id == name: submap[port_id] = net_map[net_entry] driver.apply_networking(submap, switch)
def network_create(network, creator, access, net_id): """Create a network. If the network with that name already exists, a DuplicateError will be raised. If the combination of creator, 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 creator for an administrator-owned network. Pass '' as access for a publicly accessible network. Pass '' as net_id if you wish to use the HaaS's network-id allocation pool. Details of the various combinations of network attributes are in docs/networks.md """ db = model.Session() _assert_absent(db, model.Network, network) # Check legality of arguments, and find correct 'access' and 'creator' if creator != "admin": # Project-owned network if access != creator: raise BadArgumentError("Project-created networks must be accessed only by that project.") if net_id != "": raise BadArgumentError("Project-created networks must use network ID allocation") creator = _must_find(db, model.Project, creator) access = _must_find(db, model.Project, access) else: # Administrator-owned network creator = None if access == "": access = None else: access = _must_find(db, model.Project, access) # Allocate net_id, if requested if net_id == "": driver_name = cfg.get('general', 'driver') driver = importlib.import_module('haas.drivers.' + driver_name) net_id = driver.get_new_network_id(db) if net_id is None: raise AllocationError('No more networks') allocated = True else: allocated = False network = model.Network(creator, access, allocated, net_id, network) db.add(network) db.commit()
def add_nic(self, vlan_id): trunk_nic = cfg.get('headnode', 'trunk_nic') bridge = 'br-vlan%d' % vlan_id vlan_nic = '%s.%d' % (trunk_nic, vlan_id) vlan_id = str(vlan_id) cmd(['brctl', 'addbr', bridge]) cmd(['vconfig', 'add', trunk_nic, vlan_id]) cmd(['brctl', 'addif', bridge, vlan_nic]) cmd(['ifconfig', bridge, 'up', 'promisc']) cmd(['ifconfig', vlan_nic, 'up', 'promisc']) cmd(['virsh', 'attach-interface', self.name, 'bridge', bridge, '--config']) self.nics.append(vlan_id)
def delete(self): """Delete the vm, including associated storage""" trunk_nic = cfg.get('headnode', 'trunk_nic') cmd(['virsh', 'undefine', self.name, '--remove-all-storage']) for nic in self.nics: nic = str(nic) bridge = 'br-vlan%s' % nic vlan_nic = '%s.%d' % (trunk_nic, nic) cmd(['ifconfig', bridge, 'down']) cmd(['ifconfig', vlan_nic, 'down']) cmd(['brctl', 'delif', bridge, vlan_nic]) cmd(['vconfig', 'rem', vlan_nic]) cmd(['brctl', 'delbr', bridge])
def init_db(create=False, uri=None): """Start up the DB connection. If `create` is True, this will generate the schema for the database. `uri` is the uri to use for the databse. If it is None, the uri from the config file will be used. """ if uri == None: uri = cfg.get('database', 'uri') # We have to import this prior to doing create_all, so that any tables # defined by the driver will make it into the schema. driver_name = cfg.get('general', 'driver') driver = importlib.import_module('haas.drivers.' + driver_name) engine = create_engine(uri) if create: Base.metadata.create_all(engine) Session.configure(bind=engine) driver.init_db(create=create)
def get_vlan_list(): """Return a list of vlans in the module's config section. This is for use by the ``create_bridges`` script. """ vlan_str = cfg.get(__name__, 'vlans') returnee = [] for r in vlan_str.split(","): r = r.strip().split("-") if len(r) == 1: returnee.append(int(r[0])) else: returnee += range(int(r[0]), int(r[1])+1) return returnee
def network_delete(network): """Delete network. If the network does not exist, a NotFoundError will be raised. """ db = model.Session() network = _must_find(db, model.Network, network) if cfg.getboolean('recursive', 'rHaaS'): bHaaS_out = check_output([ 'haas', 'network_delete', network.label + '_' + network.creator.label ], stderr=STDOUT, shell=False) error_checker(bHaaS_out) else: if network.nics: raise BlockedError("Network still connected to nodes") if network.hnics: raise BlockedError("Network still connected to headnodes") if network.scheduled_nics: raise BlockedError( "Network scheduled to become connected to nodes.") if network.allocated: driver_name = cfg.get('general', 'driver') driver = importlib.import_module('haas.drivers.' + driver_name) driver.free_network_id(db, network.network_id) db.delete(network) if cfg.getboolean('recursive', 'rHaaS'): b_project = cfg.get('recursive', 'project') network_name = network.label + b_project cli.network_delete(network_name) db.commit()
def setup(*args, **kwargs): if not cfg.has_section(__name__): logger.error('No section for [%s] in haas.cfg; authentication will ' 'not work without this. Please add this section and try ' 'again.', __name__) sys.exit(1) keystone_cfg = {} for key in cfg.options(__name__): keystone_cfg[key] = cfg.get(__name__, key) # Great job with the API design Openstack! </sarcasm> factory = filter_factory(keystone_cfg) app.wsgi_app = factory(app.wsgi_app) auth.set_auth_backend(KeystoneAuthBackend())
def deploy_group(group_name): """Deploy vlans to the switch, based on matching NIC label """ active_switch_str = cfg.get('general', 'active_switch') active_switch = sys.modules['haas.drivers.' + active_switch_str] # get group and vm info group = get_entity_by_cond(Group, 'group_name=="%s"' % group_name) vm_name = group.vm.vm_name vm_node = haas.headnode.HeadNode(vm_name) add_nics_to_vm(group, vm_node) vm_node.start() # deploy multiple vlans for vlan in group.vlans: deploy_vlan(group.nodes, vlan.vlan_id, vlan.nic_name, active_switch)
def setup(*args, **kwargs): if not cfg.has_section(__name__): logger.error( 'No section for [%s] in haas.cfg; authentication will ' 'not work without this. Please add this section and try ' 'again.', __name__) sys.exit(1) keystone_cfg = {} for key in cfg.options(__name__): keystone_cfg[key] = cfg.get(__name__, key) # Great job with the API design Openstack! </sarcasm> factory = filter_factory(keystone_cfg) app.wsgi_app = factory(app.wsgi_app) auth.set_auth_backend(KeystoneAuthBackend())
def deploy_group(group_name): """Deploy vlans to the switch, based on matching NIC label """ active_switch_str = cfg.get('general', 'active_switch') active_switch = sys.modules['haas.drivers.' + active_switch_str] # get group and vm info group = get_entity_by_cond(Group,'group_name=="%s"'%group_name) vm_name = group.vm.vm_name vm_node = haas.headnode.HeadNode(vm_name) add_nics_to_vm(group, vm_node) vm_node.start() # deploy multiple vlans for vlan in group.vlans: deploy_vlan(group.nodes, vlan.vlan_id, vlan.nic_name, active_switch)
def node_delete(node): """Delete node. If the node does not exist, a NotFoundError will be raised. """ db = model.Session() node = _must_find(db, model.Node, node) node.stop_console() node.delete_console() db.delete(node) if cfg.getboolean('recursive', 'rHaaS'): b_project = cfg.get('recursive','project') bHaaS_out = check_output(['haas','project_detach_node', b_project, node.label],stderr=STDOUT, shell=False) error_checker(bHaaS_out) db.commit()
def allocate_nodes(): layout_json_data = open('site-layout.json') layout = json.load(layout_json_data) layout_json_data.close() netmap = {} for node in layout['nodes']: api.node_register(node['name'], node['ipmi']['host'], node['ipmi']['user'], node['ipmi']['pass']) for nic in node['nics']: api.node_register_nic(node['name'], nic['name'], nic['mac']) api.port_register(nic['port']) api.port_connect_nic(nic['port'], node['name'], nic['name']) netmap[nic['port']] = None # Now ensure that all of these ports are turned off driver_name = cfg.get('general', 'driver') driver = importlib.import_module('haas.drivers.' + driver_name) driver.apply_networking(netmap)
def init_db(create=False, uri=None): """Start up the DB connection. If `create` is True, this will generate the schema for the database, and perform initial population of tables. `uri` is the uri to use for the databse. If it is None, the uri from the config file will be used. """ if uri == None: uri = cfg.get('database', 'uri') engine = create_engine(uri) if create: Base.metadata.create_all(engine) Session.configure(bind=engine) if create: get_network_allocator().populate(Session())
def node_delete(node): """Delete node. If the node does not exist, a NotFoundError will be raised. """ db = model.Session() node = _must_find(db, model.Node, node) node.stop_console() node.delete_console() db.delete(node) if cfg.getboolean('recursive', 'rHaaS'): b_project = cfg.get('recursive', 'project') bHaaS_out = check_output( ['haas', 'project_detach_node', b_project, node.label], stderr=STDOUT, shell=False) error_checker(bHaaS_out) db.commit()
def network_delete(network): """Delete network. If the network does not exist, a NotFoundError will be raised. """ db = model.Session() network = _must_find(db, model.Network, network) if network.nics: raise BlockedError("Network still connected to nodes") if network.hnics: raise BlockedError("Network still connected to headnodes") if network.scheduled_nics: raise BlockedError("Network scheduled to become connected to nodes.") if network.allocated: driver_name = cfg.get('general', 'driver') driver = importlib.import_module('haas.drivers.' + driver_name) driver.free_network_id(db, network.network_id) db.delete(network) db.commit()
def network_create(network, creator, access, net_id): """Create a network. If the network with that name already exists, a DuplicateError will be raised. If the combination of creator, 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 creator for an administrator-owned network. Pass '' as access for a publicly accessible network. Pass '' as net_id if you wish to use the HaaS's network-id allocation pool. Details of the various combinations of network attributes are in docs/networks.md """ db = model.Session() _assert_absent(db, model.Network, network) # Check legality of arguments, and find correct 'access' and 'creator' if creator != "admin": # Project-owned network if access != creator: raise BadArgumentError("Project-created networks must be accessed only by that project.") if net_id != "": raise BadArgumentError("Project-created networks must use network ID allocation") creator = _must_find(db, model.Project, creator) access = _must_find(db, model.Project, access) else: # Administrator-owned network creator = None if access == "": access = None else: access = _must_find(db, model.Project, access) if cfg.getboolean('recursive','rHaaS'): #TODO - work out whether there is such a thing as an admin-created network in rHaaS # if so, how do we handle this case at bHaaS project = creator.label b_project = cfg.get('recursive','project') allocated = True; #rHaaS always has allocated netIDs net_id = "dummy"; #if creator.label == "admin": # b_project = cfg.get('recursive','project') #else: # project = creator.label # print project bHaaS_out = check_output(['haas','network_create', network+'_'+project, b_project, #how to handle case of admin in rHaaS? b_project, #access and creator must be the same? ""], stderr=STDOUT, shell=False) error_checker(bHaaS_out) #can you get the assigned netID here? for now just dummy it out? network = model.Network(creator, access, allocated, net_id, network) else: # Allocate net_id, if requested if net_id == "": driver_name = cfg.get('general', 'driver') driver = importlib.import_module('haas.drivers.' + driver_name) net_id = driver.get_new_network_id(db) if net_id is None: raise AllocationError('No more networks') allocated = True else: allocated = False network = model.Network(creator, access, allocated, net_id, network) db.add(network) if cfg.getboolean('recursive', 'rHaaS'): b_project = cfg.get('recursive', 'project') network_name = network.label + b_project net_id = '' cli.network_create(network_name, b_project, b_project, net_id) db.commit()
def configure(): config_testsuite() if not cfg.get('database', 'uri').startswith('postgresql:'): pytest.skip('Database migrations are only supported for postgresql.') init_db()
def object_url(*args): url = cfg.get('client', 'endpoint') for arg in args: url += '/' + urllib.quote(arg,'') return url
def apply_networking(net_map): config = json.loads(cfg.get('driver simple_vlan', 'switch')) driver = importlib.import_module('haas.drivers.switches.' + config["switch"]) driver.apply_networking(net_map, config)
def network_create(network, creator, access, net_id): """Create a network. If the network with that name already exists, a DuplicateError will be raised. If the combination of creator, 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 creator for an administrator-owned network. Pass '' as access for a publicly accessible network. Pass '' as net_id if you wish to use the HaaS's network-id allocation pool. Details of the various combinations of network attributes are in docs/networks.md """ db = model.Session() _assert_absent(db, model.Network, network) # Check legality of arguments, and find correct 'access' and 'creator' if creator != "admin": # Project-owned network if access != creator: raise BadArgumentError( "Project-created networks must be accessed only by that project." ) if net_id != "": raise BadArgumentError( "Project-created networks must use network ID allocation") creator = _must_find(db, model.Project, creator) access = _must_find(db, model.Project, access) else: # Administrator-owned network creator = None if access == "": access = None else: access = _must_find(db, model.Project, access) if cfg.getboolean('recursive', 'rHaaS'): #TODO - work out whether there is such a thing as an admin-created network in rHaaS # if so, how do we handle this case at bHaaS project = creator.label b_project = cfg.get('recursive', 'project') allocated = True #rHaaS always has allocated netIDs net_id = "dummy" #if creator.label == "admin": # b_project = cfg.get('recursive','project') #else: # project = creator.label # print project bHaaS_out = check_output( [ 'haas', 'network_create', network + '_' + project, b_project, #how to handle case of admin in rHaaS? b_project, #access and creator must be the same? "" ], stderr=STDOUT, shell=False) error_checker( bHaaS_out ) #can you get the assigned netID here? for now just dummy it out? network = model.Network(creator, access, allocated, net_id, network) else: # Allocate net_id, if requested if net_id == "": driver_name = cfg.get('general', 'driver') driver = importlib.import_module('haas.drivers.' + driver_name) net_id = driver.get_new_network_id(db) if net_id is None: raise AllocationError('No more networks') allocated = True else: allocated = False network = model.Network(creator, access, allocated, net_id, network) db.add(network) if cfg.getboolean('recursive', 'rHaaS'): b_project = cfg.get('recursive', 'project') network_name = network.label + b_project net_id = '' cli.network_create(network_name, b_project, b_project, net_id) db.commit()