# Exceptions
import keystoneclient.exceptions as KeystoneExceptions
+import neutronclient.common.exceptions as NeutronException
class ValidationError(Exception):
self.cinder_drv = ci_drv.CinderDriver(self.sess_drv,
region_name = region,
logger = self.log)
- except Exception as e:
+ except Exception:
self.cinder_drv = None
self.ceilo_drv = ce_drv.CeilometerDriver(self.sess_drv,
return self._cache['cinder']
def build_resource_cache(self):
- self.build_network_resource_cache()
+ try:
+ self.build_network_resource_cache()
+ except KeyError:
+ raise
self.build_nova_resource_cache()
self.build_cinder_resource_cache()
self.build_glance_resource_cache()
self.log.info("Discovering management network %s", self._mgmt_network)
network_list = self._cache_populate(self.neutron_drv.network_get,
None,
- **{'network_name':self._mgmt_network})
+ **{'network_name': self._mgmt_network})
if network_list:
self.neutron_cache['mgmt_net'] = network_list['id']
else:
- raise KeyError("Error")
+ msg = "Could not find management network %s" % self._mgmt_network
+ self.log.error(msg)
+ raise KeyError(msg)
def _build_glance_image_list(self):
def _build_cinder_volume_list(self):
self.log.info("Discovering volumes")
- vollist = self.cinder_volume_list()
self.cinder_cache['volumes'] = self._cache_populate(self.cinder_volume_list,
list())
return self.cinder_cache['volumes']
def build_network_resource_cache(self):
self.log.info("Building network resource cache")
- self._get_neutron_mgmt_network()
+ try:
+ self._get_neutron_mgmt_network()
+ except KeyError:
+ raise
self._build_neutron_security_group_list()
self._build_neutron_subnet_prefix_list()
self.sess_drv.invalidate_auth_token()
self.sess_drv.auth_token
self.build_resource_cache()
+ except KeystoneExceptions.Unauthorized as e:
+ self.log.error("Invalid credentials ")
+ raise ValidationError("Invalid Credentials: "+ str(e))
except KeystoneExceptions.AuthorizationFailure as e:
self.log.error("Unable to authenticate or validate the existing credentials. Exception: %s", str(e))
raise ValidationError("Invalid Credentials: "+ str(e))
+ except NeutronException.NotFound as e:
+ self.log.error("Given management network could not be found for Openstack account ")
+ raise ValidationError("Neutron network not found "+ str(e))
except Exception as e:
self.log.error("Could not connect to Openstack. Exception: %s", str(e))
raise ValidationError("Connection Error: "+ str(e))
-
+
def glance_image_create(self, **kwargs):
- if not 'disk_format' in kwargs:
+ if 'disk_format' not in kwargs:
kwargs['disk_format'] = 'qcow2'
- if not 'container_format' in kwargs:
+ if 'container_format' not in kwargs:
kwargs['container_format'] = 'bare'
- if not 'min_disk' in kwargs:
+ if 'min_disk' not in kwargs:
kwargs['min_disk'] = 0
- if not 'min_ram' in kwargs:
+ if 'min_ram' not in kwargs:
kwargs['min_ram'] = 0
return self.glance_drv.image_create(**kwargs)
def nova_server_create(self, **kwargs):
if 'security_groups' not in kwargs:
- kwargs['security_groups'] = [ s['name'] for s in self._nova_security_groups ]
+ kwargs['security_groups'] = [s['name'] for s in self._nova_security_groups]
return self.nova_drv.server_create(**kwargs)
def nova_server_add_port(self, server_id, port_id):
def nova_volume_list(self, server_id):
return self.nova_drv.volume_list(server_id)
+ def neutron_extensions_list(self):
+ return self.neutron_drv.extensions_list()
+
def neutron_network_list(self):
return self.neutron_drv.network_list()
def cinder_volume_list(self):
return self.cinder_drv.volume_list()
- def cinder_volume_get(self,vol_id):
+ def cinder_volume_get(self, vol_id):
return self.cinder_drv.volume_get(vol_id)
def cinder_volume_set_metadata(self, volumeid, metadata):
# limitations under the License.
#
-import contextlib
import logging
import os
import subprocess
import rw_status
import rift.cal.rwcal_status as rwcal_status
import rwlogger
-import neutronclient.common.exceptions as NeutronException
-import keystoneclient.exceptions as KeystoneExceptions
from gi.repository import (
PREPARE_VM_CMD = "prepare_vm.py --auth_url {auth_url} --username {username} --password {password} --tenant_name {tenant_name} --region {region} --user_domain {user_domain} --project_domain {project_domain} --mgmt_network {mgmt_network} --server_id {server_id} --port_metadata "
-rwstatus_exception_map = { IndexError: RwTypes.RwStatus.NOTFOUND,
- KeyError: RwTypes.RwStatus.NOTFOUND,
- NotImplementedError: RwTypes.RwStatus.NOT_IMPLEMENTED,}
+rwstatus_exception_map = {IndexError: RwTypes.RwStatus.NOTFOUND,
+ KeyError: RwTypes.RwStatus.NOTFOUND,
+ NotImplementedError: RwTypes.RwStatus.NOT_IMPLEMENTED, }
rwstatus = rw_status.rwstatus_from_exc_map(rwstatus_exception_map)
rwcalstatus = rwcal_status.rwcalstatus_from_exc_map(rwstatus_exception_map)
self.log = logger
try:
self._driver = openstack_drv.OpenstackDriver(logger = self.log, **kwargs)
- except (KeystoneExceptions.Unauthorized, KeystoneExceptions.AuthorizationFailure,
- NeutronException.NotFound) as e:
- raise
except Exception as e:
self.log.error("RwcalOpenstackPlugin: OpenstackDriver init failed. Exception: %s" %(str(e)))
raise
Validation Code and Details String
"""
status = RwcalYang.CloudConnectionStatus()
- drv = self._use_driver(account)
try:
+ drv = self._use_driver(account)
drv.validate_account_creds()
- except KeystoneExceptions.Unauthorized as e:
- self.log.error("Invalid credentials given for VIM account %s", account.name)
- status.status = "failure"
- status.details = "Invalid Credentials: %s" % str(e)
-
- except KeystoneExceptions.AuthorizationFailure as e:
- self.log.error("Bad authentication URL given for VIM account %s. Given auth url: %s",
- account.name, account.openstack.auth_url)
- status.status = "failure"
- status.details = "Invalid auth url: %s" % str(e)
-
- except NeutronException.NotFound as e:
- self.log.error("Given management network %s could not be found for VIM account %s",
- account.openstack.mgmt_network,
- account.name)
- status.status = "failure"
- status.details = "mgmt network does not exist: %s" % str(e)
-
- except openstack_drv.ValidationError as e:
- self.log.error("RwcalOpenstackPlugin: OpenstackDriver credential validation failed. Exception: %s", str(e))
- status.status = "failure"
- status.details = "Invalid Credentials: %s" % str(e)
-
except Exception as e:
- msg = "RwcalOpenstackPlugin: OpenstackDriver connection failed. Exception: %s" %(str(e))
+ msg = "RwcalOpenstackPlugin: Exception: %s" %(str(e))
self.log.error(msg)
status.status = "failure"
status.details = msg
kwargs['image_id'] = vminfo.image_id
### If floating_ip is required and we don't have one, better fail before any further allocation
- pool_name = None
floating_ip = False
if vminfo.has_field('allocate_public_address') and vminfo.allocate_public_address:
- if account.openstack.has_field('floating_ip_pool'):
- pool_name = account.openstack.floating_ip_pool
floating_ip = True
if vminfo.has_field('cloud_init') and vminfo.cloud_init.has_field('userdata'):
kwargs['availability_zone'] = None
if vminfo.has_field('server_group'):
- kwargs['scheduler_hints'] = {'group': vminfo.server_group }
+ kwargs['scheduler_hints'] = {'group': vminfo.server_group}
else:
kwargs['scheduler_hints'] = None
if key in vm.user_tags.fields:
setattr(vm.user_tags, key, value)
if 'OS-EXT-SRV-ATTR:host' in vm_info:
- if vm_info['OS-EXT-SRV-ATTR:host'] != None:
+ if vm_info['OS-EXT-SRV-ATTR:host'] is not None:
vm.host_name = vm_info['OS-EXT-SRV-ATTR:host']
if 'OS-EXT-AZ:availability_zone' in vm_info:
- if vm_info['OS-EXT-AZ:availability_zone'] != None:
+ if vm_info['OS-EXT-AZ:availability_zone'] is not None:
vm.availability_zone = vm_info['OS-EXT-AZ:availability_zone']
return vm
network = RwcalYang.NetworkInfoItem()
network.network_name = network_info['name']
network.network_id = network_info['id']
- if ('provider:network_type' in network_info) and (network_info['provider:network_type'] != None):
+ if ('provider:network_type' in network_info) and (network_info['provider:network_type'] is not None):
network.provider_network.overlay_type = network_info['provider:network_type'].upper()
if ('provider:segmentation_id' in network_info) and (network_info['provider:segmentation_id']):
network.provider_network.segmentation_id = network_info['provider:segmentation_id']
cmd += (" --vol_metadata {}").format(tmp_file.name)
exec_path = 'python3 ' + os.path.dirname(openstack_drv.__file__)
- exec_cmd = exec_path+'/'+cmd
+ exec_cmd = exec_path + '/' + cmd
self.log.info("Running command: %s" %(exec_cmd))
subprocess.call(exec_cmd, shell=True)
(member_vnfd.member_vnf_index_ref == const_vnfd.member_vnf_index):
group_info = self.resolve_placement_group_cloud_construct(group)
if group_info is None:
- self._log.error("Could not resolve cloud-construct for placement group: %s", group.name)
+ self._log.info("Could not resolve cloud-construct for placement group: %s", group.name)
### raise PlacementGroupError("Could not resolve cloud-construct for placement group: {}".format(group.name))
else:
self._log.info("Successfully resolved cloud construct for placement group: %s for VNF: %s (Member Index: %s)",
# limitations under the License.
#
-import contextlib
import logging
import gi
gi.require_version('RwSdn', '1.0')
-gi.require_version('RwCal', '1.0')
-gi.require_version('RwcalYang', '1.0')
+import rift.rwcal.openstack as openstack_drv
from rift.rwcal.openstack import session as sess_drv
from rift.rwcal.openstack import keystone as ks_drv
from rift.rwcal.openstack import neutron as nt_drv
from gi.repository import (
GObject,
- RwCal,
- RwSdn, # Vala package
+ RwSdn, # Vala package
RwsdnalYang,
- RwTypes,
- RwcalYang)
+ RwTypes)
-rwstatus_exception_map = { IndexError: RwTypes.RwStatus.NOTFOUND,
+rwstatus_exception_map = {IndexError: RwTypes.RwStatus.NOTFOUND,
KeyError: RwTypes.RwStatus.NOTFOUND,
- NotImplementedError: RwTypes.RwStatus.NOT_IMPLEMENTED,}
+ NotImplementedError: RwTypes.RwStatus.NOT_IMPLEMENTED, }
rwstatus = rw_status.rwstatus_from_exc_map(rwstatus_exception_map)
rwcalstatus = rwcal_status.rwcalstatus_from_exc_map(rwstatus_exception_map)
project_domain_name = kwargs['project_domain'] if 'project_domain' in kwargs else None,
user_domain_name = kwargs['user_domain'] if 'user_domain' in kwargs else None,)
+ self.auth_url = kwargs['auth_url']
cert_validate = kwargs['cert_validate'] if 'cert_validate' in kwargs else False
region = kwargs['region_name'] if 'region_name' in kwargs else False
logger = self.log)
def validate_account_creds(self):
+ status = RwsdnalYang.SdnConnectionStatus()
try:
self.sess_drv.invalidate_auth_token()
self.sess_drv.auth_token
+ except KeystoneExceptions.Unauthorized as e:
+ self.log.error("Invalid credentials given for SDN account ")
+ status.status = "failure"
+ status.details = "Invalid Credentials: %s" % str(e)
+
except KeystoneExceptions.AuthorizationFailure as e:
- self.log.error("Unable to authenticate or validate the existing credentials. Exception: %s", str(e))
- raise ValidationError("Invalid Credentials: "+ str(e))
+ self.log.error("Bad authentication URL given for SDN account. Given auth url: %s",
+ self.auth_url)
+ status.status = "failure"
+ status.details = "Invalid auth url: %s" % str(e)
+
+ except NeutronException.NotFound as e:
+ status.status = "failure"
+ status.details = "Neutron exception %s" % str(e)
+
+ except openstack_drv.ValidationError as e:
+ self.log.error("RwcalOpenstackPlugin: OpenstackDriver credential validation failed. Exception: %s", str(e))
+ status.status = "failure"
+ status.details = "Invalid Credentials: %s" % str(e)
+
except Exception as e:
- self.log.error("Could not connect to Openstack. Exception: %s", str(e))
- raise ValidationError("Connection Error: "+ str(e))
+ msg = "RwsdnOpenstackPlugin: OpenstackDriver connection failed. Exception: %s" %(str(e))
+ self.log.error(msg)
+ status.status = "failure"
+ status.details = msg
+
+ else:
+ status.status = "success"
+ status.details = "Connection was successful"
+
+ return status
- def delete_port_chain(self,port_chain_id):
+ def delete_port_chain(self, port_chain_id):
"Delete port chain"
try:
result = self.portchain_drv.get_port_chain(port_chain_id)
port_pairs.extend(port_pair_group["port_pair_group"]["port_pairs"])
self.portchain_drv.delete_port_pair_group(port_pair_group_id)
- self.log.debug("Port pairs during delete is %s",port_pairs)
+ self.log.debug("Port pairs during delete is %s", port_pairs)
for port_pair_id in port_pairs:
self.portchain_drv.delete_port_pair(port_pair_id)
pass
except Exception as e:
- self.log.error("Error while delete port chain with id %s, exception %s", port_chain_id,str(e))
+ self.log.error("Error while delete port chain with id %s, exception %s", port_chain_id, str(e))
- def update_port_chain(self,port_chain_id,flow_classifier_list):
+ def update_port_chain(self, port_chain_id, flow_classifier_list):
result = self.portchain_drv.get_port_chain(port_chain_id)
result.raise_for_status()
port_chain = result.json()['port_chain']
if port_chain and port_chain['flow_classifiers']:
new_flow_classifier_list.extend(port_chain['flow_classifiers'])
new_flow_classifier_list.extend(flow_classifier_list)
- port_chain_id = self.portchain_drv.update_port_chain(port_chain['id'],flow_classifiers=new_flow_classifier_list)
+ port_chain_id = self.portchain_drv.update_port_chain(port_chain['id'], flow_classifiers=new_flow_classifier_list)
return port_chain_id
- def create_flow_classifer(self,classifier_name,classifier_dict):
+ def create_flow_classifer(self, classifier_name, classifier_dict):
"Create flow classifier"
- flow_classifier_id = self.portchain_drv.create_flow_classifier(classifier_name,classifier_dict)
+ flow_classifier_id = self.portchain_drv.create_flow_classifier(classifier_name, classifier_dict)
return flow_classifier_id
- def delete_flow_classifier(self,classifier_id):
+ def delete_flow_classifier(self, classifier_id):
"Create flow classifier"
try:
self.portchain_drv.delete_flow_classifier(classifier_id)
except Exception as e:
- self.log.error("Error while deleting flow classifier with id %s, exception %s", classifier_id,str(e))
+ self.log.error("Error while deleting flow classifier with id %s, exception %s", classifier_id, str(e))
def get_port_chain_list(self):
result = self.portchain_drv.get_port_chain_list()
class SdnOpenstackPlugin(GObject.Object, RwSdn.Topology):
instance_num = 1
+
def __init__(self):
GObject.Object.__init__(self)
self.log = logging.getLogger('rwsdn.openstack.%s' % SdnOpenstackPlugin.instance_num)
Validation Code and Details String
"""
status = RwsdnalYang.SdnConnectionStatus()
- drv = self._use_driver(account)
try:
+ drv = self._use_driver(account)
drv.validate_account_creds()
except openstack_drv.ValidationError as e:
return status
@rwstatus(ret_on_failure=[""])
- def do_create_vnffg_chain(self, account,vnffg):
+ def do_create_vnffg_chain(self, account, vnffg):
"""
Creates Service Function chain in ODL
@param account - a SDN account
"""
- self.log.debug('Received Create VNFFG chain for account {}, chain {}'.format(account,vnffg))
+ self.log.debug('Received Create VNFFG chain for account {}, chain {}'.format(account, vnffg))
drv = self._use_driver(account)
port_list = list()
vnf_chain_list = sorted(vnffg.vnf_chain_path, key = lambda x: x.order)
for path in vnf_chain_list:
if prev_vm_id and path.vnfr_ids[0].vdu_list[0].vm_id == prev_vm_id:
prev_entry = port_list.pop()
- port_list.append((prev_entry[0],path.vnfr_ids[0].vdu_list[0].port_id))
+ port_list.append((prev_entry[0], path.vnfr_ids[0].vdu_list[0].port_id))
prev_vm_id = None
else:
prev_vm_id = path.vnfr_ids[0].vdu_list[0].vm_id
- port_list.append((path.vnfr_ids[0].vdu_list[0].port_id,path.vnfr_ids[0].vdu_list[0].port_id))
- vnffg_id = drv.create_port_chain(vnffg.name,port_list)
+ port_list.append((path.vnfr_ids[0].vdu_list[0].port_id, path.vnfr_ids[0].vdu_list[0].port_id))
+ vnffg_id = drv.create_port_chain(vnffg.name, port_list)
return vnffg_id
@rwstatus
- def do_terminate_vnffg_chain(self, account,vnffg_id):
+ def do_terminate_vnffg_chain(self, account, vnffg_id):
"""
Terminate Service Function chain in ODL
@param account - a SDN account
"""
- self.log.debug('Received Create VNFFG classifier for account {}, classifier {}'.format(account,vnffg_classifier))
- protocol_map = {1:'ICMP',6:'TCP',17:'UDP'}
+ self.log.debug('Received Create VNFFG classifier for account {}, classifier {}'.format(account, vnffg_classifier))
+ protocol_map = {1: 'ICMP', 6: 'TCP', 17: 'UDP'}
flow_classifier_list = list()
drv = self._use_driver(account)
for rule in vnffg_classifier.match_attributes:
flow_dict = {}
for field, value in rule.as_dict().items():
if field == 'ip_proto':
- flow_dict['protocol'] = protocol_map.get(value,None)
+ flow_dict['protocol'] = protocol_map.get(value, None)
elif field == 'source_ip_address':
flow_dict['source_ip_prefix'] = value
elif field == 'destination_ip_address':
flow_dict['logical_source_port'] = vnffg_classifier.port_id
flow_classifier_id = drv.create_flow_classifer(classifier_name, flow_dict)
flow_classifier_list.append(flow_classifier_id)
- drv.update_port_chain(vnffg_classifier.rsp_id,flow_classifier_list)
+ drv.update_port_chain(vnffg_classifier.rsp_id, flow_classifier_list)
return flow_classifier_list
@rwstatus(ret_on_failure=[None])