def load_json_from_file(name, json_file, json_str, default_value): if json_file: json_file_abspath = cfg.CONF.find_file(json_file) if not json_file_abspath: LOG.error(_LE('Failed to load %(name)s_file' '"%(json_file)s": file not found'), {'name': name, 'json_file': json_file}) raise cfg.Error(_('NECNWA option parse error')) try: with open(json_file_abspath) as f: return jsonutils.loads(f.read()) except Exception as e: LOG.error(_LE('Failed to load %(name)s_file ' '"%(json_file)s": %(reason)s'), {'reason': e, 'name': name, 'json_file': json_file}) raise cfg.Error(_('NECNWA option parse error')) elif json_str: try: return jsonutils.loads(json_str) except Exception as e: LOG.error(_LE('NECNWA option error during loading %(name)s ' '(%(data)s): %(reason)s'), {'reason': e, 'name': name, 'data': json_str}) raise cfg.Error(_('NECNWA option parse error')) else: LOG.warning(_LW('%(name)s is not configured. ' 'Make sure to set [NWA] %(name)s_file ' 'in NWA plugin configuration file. ' 'Using %(default)s as default value.'), {'name': name, 'default': default_value}) return default_value
def rest_api(self, method, url, body=None): if isinstance(body, dict): body = jsonutils.dumps(body, indent=4, sort_keys=True) LOG.debug( "NWA %(method)s %(host)s:%(port)s%(url)s body=%(body)s", { 'method': method, 'host': self.host, 'port': self.port, 'url': url, 'body': body }) status_code = -1 try: res = self._send_receive(method, url, body) except requests.exceptions.RequestException as e: msg = _("NWA Failed to connect %(host)s:%(port)s: %(reason)s") msg_params = {'host': self.host, 'port': self.port, 'reason': e} LOG.error(msg, msg_params) raise nwa_exc.NwaException(status_code, msg % msg_params, e) data = res.text LOG.debug("NWA returns: httpStatus=%(status)s body=%(data)s", { 'status': res.status_code, 'data': data }) try: data = jsonutils.loads(data) except (ValueError, TypeError): pass status_code = int(res.status_code) if 200 <= status_code and status_code <= 209: return (status_code, data) else: msg = _("NWA failed: %(method)s %(host)s:%(port)s%(url)s " "(HTTP/1.1 %(status_code)s %(reason)s) body=%(data)s") msg_params = { 'method': method, 'host': self.host, 'port': self.port, 'url': url, 'status_code': res.status_code, 'reason': res.reason, 'data': data } LOG.warning(msg, msg_params) raise nwa_exc.NwaException(status_code, msg % msg_params)
def load_json_from_file(name, json_file, json_str, default_value): if json_file: json_file_abspath = cfg.CONF.find_file(json_file) if not json_file_abspath: LOG.error( _LE('Failed to load %(name)s_file' '"%(json_file)s": file not found'), { 'name': name, 'json_file': json_file }) raise cfg.Error(_('NECNWA option parse error')) try: with open(json_file_abspath) as f: return jsonutils.loads(f.read()) except Exception as e: LOG.error( _LE('Failed to load %(name)s_file ' '"%(json_file)s": %(reason)s'), { 'reason': e, 'name': name, 'json_file': json_file }) raise cfg.Error(_('NECNWA option parse error')) elif json_str: try: return jsonutils.loads(json_str) except Exception as e: LOG.error( _LE('NECNWA option error during loading %(name)s ' '(%(data)s): %(reason)s'), { 'reason': e, 'name': name, 'data': json_str }) raise cfg.Error(_('NECNWA option parse error')) else: LOG.warning( _LW('%(name)s is not configured. ' 'Make sure to set [NWA] %(name)s_file ' 'in NWA plugin configuration file. ' 'Using %(default)s as default value.'), { 'name': name, 'default': default_value }) return default_value
def rest_api(self, method, url, body=None): if isinstance(body, dict): body = jsonutils.dumps(body, indent=4, sort_keys=True) LOG.debug("NWA %(method)s %(host)s:%(port)s%(url)s body=%(body)s", {'method': method, 'host': self.host, 'port': self.port, 'url': url, 'body': body}) status_code = -1 try: res = self._send_receive(method, url, body) except requests.exceptions.RequestException as e: msg = _("NWA Failed to connect %(host)s:%(port)s: %(reason)s") msg_params = {'host': self.host, 'port': self.port, 'reason': e} LOG.error(msg, msg_params) raise nwa_exc.NwaException(status_code, msg % msg_params, e) data = res.text LOG.debug("NWA returns: httpStatus=%(status)s body=%(data)s", {'status': res.status_code, 'data': data}) try: data = jsonutils.loads(data) except (ValueError, TypeError): pass status_code = int(res.status_code) if 200 <= status_code and status_code <= 209: return (status_code, data) else: msg = _("NWA failed: %(method)s %(host)s:%(port)s%(url)s " "(HTTP/1.1 %(status_code)s %(reason)s) body=%(data)s") msg_params = {'method': method, 'host': self.host, 'port': self.port, 'url': url, 'status_code': res.status_code, 'reason': res.reason, 'data': data} LOG.warning(msg, msg_params) raise nwa_exc.NwaException(status_code, msg % msg_params)
class ResourceGroupNameNotFound(n_exc.NotFound): message = _("ResourceGroupName %(device_owner)s could not be found")
class TenantNotFound(n_exc.NeutronException): message = _('NWA Tenant %(tenant_id)s not found')
class NWAUtilsError(n_exc.NeutronException): message = _('NWAUtils Error %(msg)s')
class NWAClientError(n_exc.NeutronException): message = _('NWAClient Error %(msg)s')
# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from neutron.agent.common import config from oslo_config import cfg from networking_nec._i18n import _ agent_opts = [ cfg.IntOpt('polling_interval', default=2, help=_("The number of seconds the agent will wait between " "polling for local device changes.")), ] cfg.CONF.register_opts(agent_opts, "AGENT") config.register_agent_state_opts_helper(cfg.CONF) # nwa.ini NWA_opts = [ cfg.StrOpt('server_url', help=_("URL for NWA REST API.")), cfg.StrOpt('access_key_id', help=_("Access ID for NWA REST API.")), cfg.StrOpt('secret_access_key', help=_("Secret key for NWA REST API.")), cfg.StrOpt('resource_group_name', help=_("Resouce Group Name specified at creating tenant NW.")), cfg.StrOpt('region_name', help=_("RegionName for DC."), default='RegionOne'),
# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from neutron.agent.common import config from oslo_config import cfg from networking_nec._i18n import _ agent_opts = [ cfg.IntOpt('polling_interval', default=2, help=_("The number of seconds the agent will wait between " "polling for local device changes.")), ] cfg.CONF.register_opts(agent_opts, "AGENT") config.register_agent_state_opts_helper(cfg.CONF) # nwa.ini NWA_opts = [ cfg.StrOpt('server_url', help=_("URL for NWA REST API.")), cfg.StrOpt('access_key_id', help=_("Access ID for NWA REST API.")), cfg.StrOpt('secret_access_key', help=_("Secret key for NWA REST API.")), cfg.StrOpt('resource_group_name', help=_(