def _check_address_count(self, interface_id, host_id): interface = pecan.request.dbapi.iinterface_get(interface_id) sdn_enabled = utils.get_sdn_enabled() if interface[ 'ifclass'] == constants.INTERFACE_CLASS_DATA and not sdn_enabled: # Is permitted to add multiple addresses only # if SDN L3 mode is not enabled. return # There can only be one 'data' interface with an IP address # where SDN is enabled if (sdn_enabled): iface_list = pecan.request.dbapi.iinterface_get_all(host_id) for iface in iface_list: uuid = iface['uuid'] # skip the one we came in with if uuid == interface_id: continue if iface['ifclass'] == constants.INTERFACE_CLASS_DATA: addresses = ( pecan.request.dbapi.addresses_get_by_interface(uuid)) if len(addresses) != 0: raise exception.AddressLimitedToOneWithSDN( iftype=constants.INTERFACE_CLASS_DATA)
def post(self, sdn_controller): """Perform semantic checks and create a new SDN Controller.""" try: # Ensure that SDN is enabled before proceeding if not utils.get_sdn_enabled(): raise wsme.exc.ClientSideError(exception.SDNNotEnabled.message) # Ensure that compulsory parameters are there # This is merely sanity since the args parse layer # will also ensure that they're provided ip_address = sdn_controller.ip_address port = sdn_controller.port transport = sdn_controller.transport if not (len(ip_address) and port and len(transport)): raise wsme.exc.ClientSideError( exception.SDNControllerRequiredParamsMissing.message) self._verify_sdn_controller_af(ip_address) new_controller = pecan.request.dbapi.sdn_controller_create( sdn_controller.as_dict()) except exception.SysinvException as e: LOG.exception(e) raise wsme.exc.ClientSideError(_("Invalid data")) try: pecan.request.rpcapi.update_sdn_controller_config( pecan.request.context) except Exception as e: with excutils.save_and_reraise_exception(): LOG.exception(e) return sdn_controller.convert_with_links(new_controller)