def create_subnet(self, context, subnet): """Create subnet core Quantum API.""" LOG.debug(_("QuantumPluginPLUMgrid Status: create_subnet() called")) with context.session.begin(subtransactions=True): # Plugin DB - Subnet Create subnet = super(QuantumPluginPLUMgridV2, self).create_subnet(context, subnet) subnet_details = self._get_subnet(context, subnet["id"]) net_id = subnet_details["network_id"] tenant_id = subnet_details["tenant_id"] try: nos_url = self.snippets.BASE_NOS_URL + net_id headers = {} body_data = self.snippets.create_network_body_data( tenant_id, self.topology_name) self.rest_conn.nos_rest_conn(nos_url, 'PUT', body_data, headers) except Exception: err_message = _("PLUMgrid NOS communication failed: ") LOG.Exception(err_message) raise plum_excep.PLUMgridException(err_message) return subnet
def create_network(self, context, network): """Create network core Quantum API.""" LOG.debug(_('QuantumPluginPLUMgrid Status: create_network() called')) # Plugin DB - Network Create and validation tenant_id = self._get_tenant_id_for_create(context, network["network"]) self._network_admin_state(network) with context.session.begin(subtransactions=True): net = super(QuantumPluginPLUMgridV2, self).create_network(context, network) try: LOG.debug( _('QuantumPluginPLUMgrid Status: %(tenant_id)s, ' '%(network)s, %(network_id)s'), dict( tenant_id=tenant_id, network=network["network"], network_id=net["id"], )) nos_url = self.snippets.BASE_NOS_URL + net["id"] headers = {} body_data = self.snippets.create_domain_body_data(tenant_id) self.rest_conn.nos_rest_conn(nos_url, 'PUT', body_data, headers) except Exception: err_message = _("PLUMgrid NOS communication failed") LOG.Exception(err_message) raise plum_excep.PLUMgridException(err_message) # return created network return net
def update_subnet(self, context, subnet_id, subnet): """Update subnet core Quantum API.""" LOG.debug(_("update_subnet() called")) #Collecting subnet info initial_subnet = self._get_subnet(context, subnet_id) net_id = initial_subnet["network_id"] tenant_id = initial_subnet["tenant_id"] with context.session.begin(subtransactions=True): # Plugin DB - Subnet Update new_subnet = super(QuantumPluginPLUMgridV2, self).update_subnet(context, subnet_id, subnet) try: # PLUMgrid Server does not support updating resources yet headers = {} body_data = {} self._cleaning_nos_subnet_structure(body_data, headers, net_id) nos_url = self.snippets.BASE_NOS_URL + net_id body_data = self.snippets.create_network_body_data( tenant_id, self.topology_name) self.rest_conn.nos_rest_conn(nos_url, 'PUT', body_data, headers) except Exception: err_message = _("PLUMgrid NOS communication failed: ") LOG.Exception(err_message) raise plum_excep.PLUMgridException(err_message) return new_subnet
def update_network(self, context, net_id, network): """Update network core Quantum API.""" LOG.debug(_("QuantumPluginPLUMgridV2.update_network() called")) self._network_admin_state(network) tenant_id = self._get_tenant_id_for_create(context, network["network"]) with context.session.begin(subtransactions=True): # Plugin DB - Network Update new_network = super(QuantumPluginPLUMgridV2, self).update_network(context, net_id, network) try: # PLUMgrid Server does not support updating resources yet nos_url = self.snippets.BASE_NOS_URL + net_id headers = {} body_data = {} self.rest_conn.nos_rest_conn(nos_url, 'DELETE', body_data, headers) nos_url = self.snippets.BASE_NOS_URL + new_network["id"] body_data = self.snippets.create_domain_body_data(tenant_id) self.rest_conn.nos_rest_conn(nos_url, 'PUT', body_data, headers) except Exception: err_message = _("PLUMgrid NOS communication failed") LOG.Exception(err_message) raise plum_excep.PLUMgridException(err_message) # return updated network return new_network
def nos_rest_conn(self, nos_url, action, data, headers): self.nos_url = nos_url body_data = json.dumps(data) if not headers: headers = {} headers['Content-type'] = 'application/json' headers['Accept'] = 'application/json' LOG.debug(_("PLUMgrid_NOS_Server: %(server)s %(port)s %(action)s"), dict(server=self.server, port=self.port, action=action)) conn = httplib.HTTPConnection(self.server, self.port, timeout=self.timeout) if conn is None: LOG.error(_('PLUMgrid_NOS_Server: Could not establish HTTP ' 'connection')) return try: LOG.debug(_("PLUMgrid_NOS_Server Sending Data: %(nos_url)s " "%(body_data)s %(headers)s"), dict( nos_url=nos_url, body_data=body_data, headers=headers, )) conn.request(action, nos_url, body_data, headers) resp = conn.getresponse() resp_str = resp.read() LOG.debug(_("PLUMgrid_NOS_Server Connection Data: %(resp)s, " "%(resp_str)s"), dict(resp=resp, resp_str=resp_str)) if resp.status is httplib.OK: try: respdata = json.loads(resp_str) LOG.debug(_("PLUMgrid_NOS_Server Connection RESP: %s"), respdata) pass except ValueError: err_message = _("PLUMgrid HTTP Connection Failed: ") LOG.Exception(err_message) raise plum_excep.PLUMgridException(err_message) ret = (resp.status, resp.reason, resp_str) except urllib2.HTTPError: LOG.error(_('PLUMgrid_NOS_Server: %(action)s failure, %(e)r')) ret = 0, None, None, None conn.close() LOG.debug(_("PLUMgrid_NOS_Server: status=%(status)d, " "reason=%(reason)r, ret=%(ret)s"), {'status': ret[0], 'reason': ret[1], 'ret': ret[2]}) return ret
def _network_admin_state(self, network): try: if network["network"].get("admin_state_up"): network_name = network["network"]["name"] if network["network"]["admin_state_up"] is False: LOG.warning( _("Network with admin_state_up=False are not " "supported yet by this plugin. Ignoring " "setting for network %s"), network_name) except Exception: err_message = _("Network Admin State Validation Falied: ") LOG.Exception(err_message) raise plum_excep.PLUMgridException(err_message) return network
def nos_rest_conn(self, nos_url, action, data, headers): self.nos_url = nos_url body_data = json.dumps(data) if not headers: headers = {} headers['Content-type'] = 'application/json' headers['Accept'] = 'application/json' LOG.debug(_("PLUMgrid_NOS_Server: %s %s %s"), self.server, self.port, action) conn = httplib.HTTPConnection(self.server, self.port, timeout=self.timeout) if conn is None: LOG.error(_('PLUMgrid_NOS_Server: Could not establish HTTP ' 'connection')) return try: LOG.debug(_("PLUMgrid_NOS_Server Sending Data: %s %s %s"), nos_url, body_data, headers) conn.request(action, nos_url, body_data, headers) resp = conn.getresponse() resp_str = resp.read() LOG.debug(_("PLUMgrid_NOS_Server Connection Data: %s, %s"), resp, resp_str) if resp.status is httplib.OK: try: respdata = json.loads(resp_str) LOG.debug(_("PLUMgrid_NOS_Server Connection RESP: %s"), respdata) pass except ValueError: err_message = _("PLUMgrid HTTP Connection Failed: ") LOG.Exception(err_message) raise plum_excep.PLUMgridException(err_message) ret = (resp.status, resp.reason, resp_str) except urllib2.HTTPError, e: LOG.error(_('PLUMgrid_NOS_Server: %(action)s failure, %(e)r')) ret = 0, None, None, None
def delete_network(self, context, net_id): """Delete network core Quantum API.""" LOG.debug(_("QuantumPluginPLUMgrid Status: delete_network() called")) super(QuantumPluginPLUMgridV2, self).get_network(context, net_id) with context.session.begin(subtransactions=True): # Plugin DB - Network Delete super(QuantumPluginPLUMgridV2, self).delete_network(context, net_id) try: nos_url = self.snippets.BASE_NOS_URL + net_id headers = {} body_data = {} self.rest_conn.nos_rest_conn(nos_url, 'DELETE', body_data, headers) except Exception: err_message = _("PLUMgrid NOS communication failed") LOG.Exception(err_message) raise plum_excep.PLUMgridException(err_message)
def delete_subnet(self, context, subnet_id): """Delete subnet core Quantum API.""" LOG.debug(_("QuantumPluginPLUMgrid Status: delete_subnet() called")) #Collecting subnet info subnet_details = self._get_subnet(context, subnet_id) with context.session.begin(subtransactions=True): # Plugin DB - Subnet Delete del_subnet = super(QuantumPluginPLUMgridV2, self).delete_subnet(context, subnet_id) try: headers = {} body_data = {} net_id = subnet_details["network_id"] self._cleaning_nos_subnet_structure(body_data, headers, net_id) except Exception: err_message = _("PLUMgrid NOS communication failed: ") LOG.Exception(err_message) raise plum_excep.PLUMgridException(err_message) return del_subnet