def apply_connectivity_changes(self, request):
        """ Handle apply connectivity changes request json, trigger add or remove vlan methods,
        get responce from them and create json response

        :param request: json with all required action to configure or remove vlans from certain port
        :return Serialized DriverResponseRoot to json
        :rtype json
        """

        if request is None or request == "":
            raise Exception(self.__class__.__name__, "request is None or empty")

        holder = JsonRequestDeserializer(jsonpickle.decode(request))

        if not holder or not hasattr(holder, "driverRequest"):
            raise Exception(self.__class__.__name__, "Deserialized request is None or empty")

        driver_response = DriverResponse()
        add_vlan_thread_list = []
        remove_vlan_thread_list = []
        driver_response_root = DriverResponseRoot()

        for action in holder.driverRequest.actions:
            self._logger.info("Action: ", action.__dict__)
            self._validate_request_action(action)

            action_id = action.actionId
            full_name = action.actionTarget.fullName
            port_mode = action.connectionParams.mode.lower()

            if action.type == "setVlan":
                qnq = False
                ctag = ""
                for attribute in action.connectionParams.vlanServiceAttributes:
                    if attribute.attributeName.lower() == "qnq" and attribute.attributeValue.lower() == "true":
                        qnq = True
                    if attribute.attributeName.lower() == "ctag":
                        ctag = attribute.attributeValue

                for vlan_id in self._get_vlan_list(action.connectionParams.vlanId):
                    add_vlan_thread = Thread(target=self.add_vlan,
                                             name=action_id,
                                             args=(vlan_id, full_name, port_mode, qnq, ctag))
                    add_vlan_thread_list.append(add_vlan_thread)
            elif action.type == "removeVlan":
                for vlan_id in self._get_vlan_list(action.connectionParams.vlanId):
                    remove_vlan_thread = Thread(target=self.remove_vlan,
                                                name=action_id,
                                                args=(vlan_id, full_name, port_mode,))
                    remove_vlan_thread_list.append(remove_vlan_thread)
            else:
                self._logger.warning("Undefined action type determined '{}': {}".format(action.type, action.__dict__))
                continue

        # Start all created remove_vlan_threads
        for thread in remove_vlan_thread_list:
            thread.start()

        # Join all remove_vlan_threads. Main thread will wait completion of all remove_vlan_thread
        for thread in remove_vlan_thread_list:
            thread.join()

        # Start all created add_vlan_threads
        for thread in add_vlan_thread_list:
            thread.start()

        # Join all add_vlan_threads. Main thread will wait completion of all add_vlan_thread
        for thread in add_vlan_thread_list:
            thread.join()

        request_result = []
        for action in holder.driverRequest.actions:
            result_statuses, message = zip(*self.result.get(action.actionId))
            if all(result_statuses):
                action_result = ConnectivitySuccessResponse(action,
                                                            "Add Vlan {vlan} configuration successfully completed"
                                                            .format(vlan=action.connectionParams.vlanId))
            else:
                message_details = "\n\t".join(message)
                action_result = ConnectivityErrorResponse(action, "Add Vlan {vlan} configuration failed."
                                                                  "\nAdd Vlan configuration details:\n{message_details}"
                                                          .format(vlan=action.connectionParams.vlanId,
                                                                  message_details=message_details))
            request_result.append(action_result)

        driver_response.actionResults = request_result
        driver_response_root.driverResponse = driver_response
        return serialize_to_json(driver_response_root)
def apply_connectivity_changes ( self , request ) : if request is None or request == "" : raise Exception ( self . __class__ . __name__ , "request is None or empty" ) holder = JsonRequestDeserializer ( jsonpickle . decode ( request ) ) if not holder or not hasattr ( holder , "driverRequest" ) : raise Exception ( self . __class__ . __name__ , "Deserialized request is None or empty" ) driver_response = DriverResponse ( ) add_vlan_thread_list = [ ] remove_vlan_thread_list = [ ] driver_response_root = DriverResponseRoot ( ) for action in holder . driverRequest . actions : self . _logger . info ( "Action: " , action . __dict__ ) self . _validate_request_action ( action ) action_id = action . actionId full_name = action . actionTarget . fullName port_mode = action . connectionParams . mode . lower ( ) if action . type == "setVlan" : qnq = False ctag = "" for attribute in action . connectionParams . vlanServiceAttributes : if attribute . attributeName . lower ( ) == "qnq" and attribute . attributeValue . lower ( ) == "true" : qnq = True if attribute . attributeName . lower ( ) == "ctag" : ctag = attribute . attributeValue for vlan_id in self . _get_vlan_list ( action . connectionParams . vlanId ) : add_vlan_thread = Thread ( target = self . add_vlan , name = action_id , args = ( vlan_id , full_name , port_mode , qnq , ctag ) ) add_vlan_thread_list . append ( add_vlan_thread ) elif action . type == "removeVlan" : for vlan_id in self . _get_vlan_list ( action . connectionParams . vlanId ) : remove_vlan_thread = Thread ( target = self . remove_vlan , name = action_id , args = ( vlan_id , full_name , port_mode , ) ) remove_vlan_thread_list . append ( remove_vlan_thread ) else : self . _logger . warning ( "Undefined action type determined '{}': {}" . format ( action . type , action . __dict__ ) ) continue for thread in remove_vlan_thread_list : thread . start ( ) for thread in remove_vlan_thread_list : thread . join ( ) for thread in add_vlan_thread_list : thread . start ( ) for thread in add_vlan_thread_list : thread . join ( ) request_result = [ ] for action in holder . driverRequest . actions : result_statuses , message = zip ( * self . result . get ( action . actionId ) ) if all ( result_statuses ) : action_result = ConnectivitySuccessResponse ( action , "Add Vlan {vlan} configuration successfully completed" . format ( vlan = action . connectionParams . vlanId ) ) else : message_details = "\n\t" . join ( message ) action_result = ConnectivityErrorResponse ( action , "Add Vlan {vlan} configuration failed." "\nAdd Vlan configuration details:\n{message_details}" . format ( vlan = action . connectionParams . vlanId , message_details = message_details ) ) request_result . append ( action_result ) driver_response . actionResults = request_result driver_response_root . driverResponse = driver_response return serialize_to_json ( driver_response_root )
Handle apply connectivity changes request json, trigger add or remove vlan methods,
        get responce from them and create json response

        :param request: json with all required action to configure or remove vlans from certain port
        :return Serialized DriverResponseRoot to json
        :rtype json