+ self.logger.debug("get_hosts " + error_text)
+ return error_value, error_text
+
+ def new_classification(self, name, ctype, definition):
+ self.logger.debug(
+ 'Adding a new (Traffic) Classification to VIM, named %s', name)
+ try:
+ new_class = None
+ self._reload_connection()
+ if ctype not in supportedClassificationTypes:
+ raise vimconn.vimconnNotSupportedException(
+ 'OpenStack VIM connector doesn\'t support provided '
+ 'Classification Type {}, supported ones are: '
+ '{}'.format(ctype, supportedClassificationTypes))
+ if not self._validate_classification(ctype, definition):
+ raise vimconn.vimconnException(
+ 'Incorrect Classification definition '
+ 'for the type specified.')
+ classification_dict = definition
+ classification_dict['name'] = name
+
+ new_class = self.neutron.create_sfc_flow_classifier(
+ {'flow_classifier': classification_dict})
+ return new_class['flow_classifier']['id']
+ except (neExceptions.ConnectionFailed, ksExceptions.ClientException,
+ neExceptions.NeutronException, ConnectionError) as e:
+ self.logger.error(
+ 'Creation of Classification failed.')
+ self._format_exception(e)
+
+ def get_classification(self, class_id):
+ self.logger.debug(" Getting Classification %s from VIM", class_id)
+ filter_dict = {"id": class_id}
+ class_list = self.get_classification_list(filter_dict)
+ if len(class_list) == 0:
+ raise vimconn.vimconnNotFoundException(
+ "Classification '{}' not found".format(class_id))
+ elif len(class_list) > 1:
+ raise vimconn.vimconnConflictException(
+ "Found more than one Classification with this criteria")
+ classification = class_list[0]
+ return classification
+
+ def get_classification_list(self, filter_dict={}):
+ self.logger.debug("Getting Classifications from VIM filter: '%s'",
+ str(filter_dict))
+ try:
+ filter_dict_os = filter_dict.copy()
+ self._reload_connection()
+ if self.api_version3 and "tenant_id" in filter_dict_os:
+ filter_dict_os['project_id'] = filter_dict_os.pop('tenant_id')
+ classification_dict = self.neutron.list_sfc_flow_classifiers(
+ **filter_dict_os)
+ classification_list = classification_dict["flow_classifiers"]
+ self.__classification_os2mano(classification_list)
+ return classification_list
+ except (neExceptions.ConnectionFailed, ksExceptions.ClientException,
+ neExceptions.NeutronException, ConnectionError) as e:
+ self._format_exception(e)
+
+ def delete_classification(self, class_id):
+ self.logger.debug("Deleting Classification '%s' from VIM", class_id)
+ try:
+ self._reload_connection()
+ self.neutron.delete_sfc_flow_classifier(class_id)
+ return class_id
+ except (neExceptions.ConnectionFailed, neExceptions.NeutronException,
+ ksExceptions.ClientException, neExceptions.NeutronException,
+ ConnectionError) as e:
+ self._format_exception(e)
+
+ def new_sfi(self, name, ingress_ports, egress_ports, sfc_encap=True):
+ self.logger.debug(
+ "Adding a new Service Function Instance to VIM, named '%s'", name)
+ try:
+ new_sfi = None
+ self._reload_connection()
+ correlation = None
+ if sfc_encap:
+ correlation = 'nsh'
+ if len(ingress_ports) != 1:
+ raise vimconn.vimconnNotSupportedException(
+ "OpenStack VIM connector can only have "
+ "1 ingress port per SFI")
+ if len(egress_ports) != 1:
+ raise vimconn.vimconnNotSupportedException(
+ "OpenStack VIM connector can only have "
+ "1 egress port per SFI")
+ sfi_dict = {'name': name,
+ 'ingress': ingress_ports[0],
+ 'egress': egress_ports[0],
+ 'service_function_parameters': {
+ 'correlation': correlation}}
+ new_sfi = self.neutron.create_sfc_port_pair({'port_pair': sfi_dict})
+ return new_sfi['port_pair']['id']
+ except (neExceptions.ConnectionFailed, ksExceptions.ClientException,
+ neExceptions.NeutronException, ConnectionError) as e:
+ if new_sfi:
+ try:
+ self.neutron.delete_sfc_port_pair(
+ new_sfi['port_pair']['id'])
+ except Exception:
+ self.logger.error(
+ 'Creation of Service Function Instance failed, with '
+ 'subsequent deletion failure as well.')
+ self._format_exception(e)
+
+ def get_sfi(self, sfi_id):
+ self.logger.debug(
+ 'Getting Service Function Instance %s from VIM', sfi_id)
+ filter_dict = {"id": sfi_id}
+ sfi_list = self.get_sfi_list(filter_dict)
+ if len(sfi_list) == 0:
+ raise vimconn.vimconnNotFoundException(
+ "Service Function Instance '{}' not found".format(sfi_id))
+ elif len(sfi_list) > 1:
+ raise vimconn.vimconnConflictException(
+ 'Found more than one Service Function Instance '
+ 'with this criteria')
+ sfi = sfi_list[0]
+ return sfi
+
+ def get_sfi_list(self, filter_dict={}):
+ self.logger.debug("Getting Service Function Instances from "
+ "VIM filter: '%s'", str(filter_dict))
+ try:
+ self._reload_connection()
+ filter_dict_os = filter_dict.copy()
+ if self.api_version3 and "tenant_id" in filter_dict_os:
+ filter_dict_os['project_id'] = filter_dict_os.pop('tenant_id')
+ sfi_dict = self.neutron.list_sfc_port_pairs(**filter_dict_os)
+ sfi_list = sfi_dict["port_pairs"]
+ self.__sfi_os2mano(sfi_list)
+ return sfi_list
+ except (neExceptions.ConnectionFailed, ksExceptions.ClientException,
+ neExceptions.NeutronException, ConnectionError) as e:
+ self._format_exception(e)
+
+ def delete_sfi(self, sfi_id):
+ self.logger.debug("Deleting Service Function Instance '%s' "
+ "from VIM", sfi_id)
+ try:
+ self._reload_connection()
+ self.neutron.delete_sfc_port_pair(sfi_id)
+ return sfi_id
+ except (neExceptions.ConnectionFailed, neExceptions.NeutronException,
+ ksExceptions.ClientException, neExceptions.NeutronException,
+ ConnectionError) as e:
+ self._format_exception(e)
+
+ def new_sf(self, name, sfis, sfc_encap=True):
+ self.logger.debug("Adding a new Service Function to VIM, "
+ "named '%s'", name)
+ try:
+ new_sf = None
+ self._reload_connection()
+ # correlation = None
+ # if sfc_encap:
+ # correlation = 'nsh'
+ for instance in sfis:
+ sfi = self.get_sfi(instance)
+ if sfi.get('sfc_encap') != sfc_encap:
+ raise vimconn.vimconnNotSupportedException(
+ "OpenStack VIM connector requires all SFIs of the "
+ "same SF to share the same SFC Encapsulation")
+ sf_dict = {'name': name,
+ 'port_pairs': sfis}
+ new_sf = self.neutron.create_sfc_port_pair_group({
+ 'port_pair_group': sf_dict})
+ return new_sf['port_pair_group']['id']
+ except (neExceptions.ConnectionFailed, ksExceptions.ClientException,
+ neExceptions.NeutronException, ConnectionError) as e:
+ if new_sf:
+ try:
+ self.neutron.delete_sfc_port_pair_group(
+ new_sf['port_pair_group']['id'])
+ except Exception:
+ self.logger.error(
+ 'Creation of Service Function failed, with '
+ 'subsequent deletion failure as well.')
+ self._format_exception(e)