def get_interfaces_cfg(self):
        """ Return the configuration for the interfaces on the VRouter5600
        
        :return: A tuple: Status, configuration of the interfaces
        :rtype: instance of the `Result` class (containing configuration data)
        
        - STATUS.CONN_ERROR: If the controller did not respond.
        - STATUS.CTRL_INTERNAL_ERROR: If the controller responded but did not
                                      provide any status.
        - STATUS.OK:  Success. Result is valid.
        - STATUS.HTTP_ERROR: If the controller responded with an error
                             status code.
        
        """
        status = OperStatus()
        cfg = None
        templateModelRef = "vyatta-interfaces:interfaces"
        modelref = templateModelRef
        ctrl = self.ctrl
        url = ctrl.get_ext_mount_config_url(self.name)
        url += modelref

        resp = ctrl.http_get_request(url, data=None, headers=None)
        if (resp == None):
            status.set_status(STATUS.CONN_ERROR)
        elif (resp.content == None):
            status.set_status(STATUS.CTRL_INTERNAL_ERROR)
        elif (resp.status_code == 200):
            cfg = resp.content
            status.set_status(STATUS.OK)
        else:
            status.set_status(STATUS.HTTP_ERROR, resp)

        return Result(status, cfg)
    def set_vpn_cfg(self, vpn):
        """ Create/update VPN configuration
        
        :param vpn: instance of the 'Vpn' class
        :return: A tuple: Status, None
        :rtype: instance of the `Result` class
        
        - STATUS.CONN_ERROR: If the controller did not respond.
        - STATUS.CTRL_INTERNAL_ERROR: If the controller responded but did not
                                      provide any status.
        - STATUS.OK: Success. Result is valid.
        - STATUS.HTTP_ERROR: If the controller responded with an error
                             status code.
        
        """
        assert (isinstance(vpn, Vpn))
        status = OperStatus()
        ctrl = self.ctrl
        headers = {'content-type': 'application/yang.data+json'}
        url = ctrl.get_ext_mount_config_url(self.name)

        obj = vpn
        payload = obj.get_payload()
        resp = ctrl.http_post_request(url, payload, headers)
        if (resp == None):
            status.set_status(STATUS.CONN_ERROR)
        elif (resp.content == None):
            status.set_status(STATUS.CTRL_INTERNAL_ERROR)
        elif (resp.status_code == 200 or resp.status_code == 204):
            status.set_status(STATUS.OK)
        else:
            status.set_status(STATUS.HTTP_ERROR, resp)

        return Result(status, None)
    def get_loopback_interface_cfg(self, ifName):
        """ Return the configuration for a single loopback interface
            on the VRouter5600
        
        :param string ifName: The interface name of the interface for which
                              configuration should be returned
        :return: A tuple: Status, configuration of dataplane interface
        :rtype: instance of the `Result` class (containing configuration data)
        
        - STATUS.CONN_ERROR: If the controller did not respond.
        - STATUS.CTRL_INTERNAL_ERROR: If the controller responded but did not
                                      provide any status.
        - STATUS.OK: Success. Result is valid.
        - STATUS.HTTP_ERROR: If the controller responded with an error
                             status code.
        
        """
        status = OperStatus()
        templateModelRef = "vyatta-interfaces:interfaces/vyatta-interfaces-loopback:loopback/{}"
        modelref = templateModelRef.format(ifName)
        ctrl = self.ctrl
        url = ctrl.get_ext_mount_config_url(self.name)
        url += modelref

        resp = ctrl.http_get_request(url, data=None, headers=None)
        if (resp == None):
            status.set_status(STATUS.CONN_ERROR)
        elif (resp.content == None):
            status.set_status(STATUS.CTRL_INTERNAL_ERROR)
        elif (resp.status_code == 200):
            status.set_status(STATUS.OK)
        else:
            status.set_status(STATUS.HTTP_ERROR, resp)

        return Result(status, resp)
Ejemplo n.º 4
0
 def get_firewall_instance_cfg(self, instance):
     """Return configuration for a specific firewall on the VRouter5600.
      :param instance of the 'Firewall' class
     :return: A tuple: Status, JSON for firewall configuration.
     :rtype: instance of the `Result` class (containing configuration data)
      - STATUS.CONN_ERROR: If the controller did not respond.
     - STATUS.CTRL_INTERNAL_ERROR: If the controller responded but did not
                                   provide any status.
     - STATUS.OK:  Success. Result is valid.
     - STATUS.HTTP_ERROR: If the controller responded with an error
                          status code.
     """
     status = OperStatus()
     cfg = None
     templateModelRef = "vyatta-security:" + \
         "security/vyatta-security-firewall:firewall/name/{}"
     modelref = templateModelRef.format(instance)
     ctrl = self.ctrl
     myname = self.name
     url = ctrl.get_ext_mount_config_url(myname)
     url += modelref
     resp = ctrl.http_get_request(url, data=None, headers=None)
     if (resp is None):
         status.set_status(STATUS.CONN_ERROR)
     elif (resp.content is None):
         status.set_status(STATUS.CTRL_INTERNAL_ERROR)
     elif (resp.status_code == 200):
         cfg = resp.content
         status.set_status(STATUS.OK)
     else:
         status.set_status(STATUS.HTTP_ERROR, resp)
     return Result(status, cfg)
Ejemplo n.º 5
0
 def delete_dataplane_interface_firewall(self, ifName):
     """ Delete both inbound and outbound firewalls for a
         dataplane interface on the VRouter5600.
      :param string ifName: The dataplane interface to attach a firewall.
     :return: A tuple:  Status, Response from VRouter5600.
     :rtype: instance of the `Result` class
      - STATUS.CONN_ERROR: If the controller did not respond.
     - STATUS.CTRL_INTERNAL_ERROR: If the controller responded but did
                                   not provide any status.
     - STATUS.OK: Success. Result is valid.
     - STATUS.HTTP_ERROR: If the controller responded with an error
                          status code.
      """
     status = OperStatus()
     templateModelRef = "vyatta-interfaces:" + \
         "interfaces/vyatta-interfaces-dataplane:" + \
         "dataplane/{}/vyatta-security-firewall:firewall/"
     modelref = templateModelRef.format(ifName)
     myname = self.name
     ctrl = self.ctrl
     url = ctrl.get_ext_mount_config_url(myname)
     resp = ctrl.http_delete_request(url + modelref,
                                     data=None,
                                     headers=None)
     if (resp is None):
         status.set_status(STATUS.CONN_ERROR)
     elif (resp.content is None):
         status.set_status(STATUS.CTRL_INTERNAL_ERROR)
     elif (resp.status_code == 200):
         status.set_status(STATUS.OK)
     else:
         status.set_status(STATUS.HTTP_ERROR, resp)
     return Result(status, None)
Ejemplo n.º 6
0
    def delete_firewall_instance(self, fwInstance):
        """Delete a firewall from the VRouter5600.
         :param fwInstance: Firewall :class:
        :return: A tuple: Status, None.
        :rtype: instance of the `Result` class
         - STATUS.CONN_ERROR: If the controller did not respond.
        - STATUS.CTRL_INTERNAL_ERROR: If the controller responded but did not
                                     provide any status.
        - STATUS.OK: Success. Result is valid.
        - STATUS.HTTP_ERROR:  if the controller responded with an error status
        .  code.
         """
        assert isinstance(fwInstance, Firewall)
        status = OperStatus()
        ctrl = self.ctrl
        myname = self.name
        url = ctrl.get_ext_mount_config_url(myname)
        ext = fwInstance.get_url_extension()
        url += ext
        resp = ctrl.http_delete_request(url, data=None, headers=None)
        if (resp is None):
            status.set_status(STATUS.CONN_ERROR)
        elif (resp.content is None):
            status.set_status(STATUS.CTRL_INTERNAL_ERROR)
        elif (resp.status_code == 200):
            status.set_status(STATUS.OK)
        else:
            status.set_status(STATUS.HTTP_ERROR, resp)

        return Result(status, None)
    def create_firewall_instance(self, fwInstance):
        """Create a firewall on the VRouter5600.
        
        :param fwInstance: instance of the 'Firewall' class
        :return: A tuple:  Status, None.
        :rtype: instance of the `Result` class
        
        - STATUS.CONN_ERROR: If the controller did not respond.
        - STATUS.CTRL_INTERNAL_ERROR: If the controller responded but did not
                                      provide any status.
        - STATUS.OK:  Success. Result is valid.
        - STATUS.HTTP_ERROR: If the controller responded with an error
                             status code.
        
        """
        status = OperStatus()
        ctrl = self.ctrl
        myname = self.name
        url = ctrl.get_ext_mount_config_url(myname)
        headers = {'content-type': 'application/yang.data+json'}
        payload = fwInstance.get_payload()

        resp = ctrl.http_post_request(url, payload, headers)
        if (resp == None):
            status.set_status(STATUS.CONN_ERROR)
        elif (resp.content == None):
            status.set_status(STATUS.CTRL_INTERNAL_ERROR)
        elif (resp.status_code == 200 or resp.status_code == 204):
            status.set_status(STATUS.OK)
        else:
            status.set_status(STATUS.HTTP_ERROR, resp)

        return Result(status, None)
Ejemplo n.º 8
0
 def get_cfg(self):
     """Return configuration of the VRouter5600.
      :return: A tuple: Status, JSON for configuration.
     :rtype: instance of the `Result` class (containing configuration data)
     - STATUS.CONN_ERROR: If the controller did not respond.
     - STATUS.CTRL_INTERNAL_ERROR: If the controller responded but did not
     .                             provide any status.
     - STATUS.OK: Success. Result is valid.
     - STATUS.HTTP_ERROR: If the controller responded with an error
     .                    status code.
      """
     status = OperStatus()
     cfg = None
     ctrl = self.ctrl
     myname = self.name
     url = ctrl.get_ext_mount_config_url(myname)
     resp = ctrl.http_get_request(url, data=None, headers=None)
     if (resp is None):
         status.set_status(STATUS.CONN_ERROR)
     elif (resp.content is None):
         status.set_status(STATUS.CTRL_INTERNAL_ERROR)
     elif (resp.status_code == 200):
         cfg = resp.content
         status.set_status(STATUS.OK)
     else:
         status.set_status(STATUS.HTTP_ERROR, resp)
     return Result(status, cfg)
Ejemplo n.º 9
0
def get_interfaces_cfg(self):
        """ Return the configuration for the interfaces on the VRouter5600
        :return: A tuple: Status, configuration of the interfaces
        :rtype: instance of the `Result` class (containing configuration data)
        - STATUS.CONN_ERROR: If the controller did not respond.
        - STATUS.CTRL_INTERNAL_ERROR: If the controller responded but did not
                                      provide any status.
        - STATUS.OK:  Success. Result is valid.
        - STATUS.HTTP_ERROR: If the controller responded with an error
                             status code.
        """
        status = OperStatus()
        cfg = None
        templateModelRef = "brocade-interface:interface"
        modelref = templateModelRef
        ctrl = self.ctrl
        url = ctrl.get_ext_mount_config_url(self.name)
        url += modelref
        resp = ctrl.http_get_request(url, data=None, headers=None)
        if(resp is None):
            status.set_status(STATUS.CONN_ERROR)
        elif(resp.content is None):
            status.set_status(STATUS.CTRL_INTERNAL_ERROR)
        elif (resp.status_code == 200):
            cfg = resp.content
            status.set_status(STATUS.OK)
        else:
            status.set_status(STATUS.HTTP_ERROR, resp)
        return Result(status, cfg)
Ejemplo n.º 10
0
    def delete_firewall_instance(self, fwInstance):
        """Delete a firewall from the VRouter5600.
         :param fwInstance: Firewall :class:
        :return: A tuple: Status, None.
        :rtype: instance of the `Result` class
         - STATUS.CONN_ERROR: If the controller did not respond.
        - STATUS.CTRL_INTERNAL_ERROR: If the controller responded but did not
                                     provide any status.
        - STATUS.OK: Success. Result is valid.
        - STATUS.HTTP_ERROR:  if the controller responded with an error status
        .  code.
         """
        assert isinstance(fwInstance, Firewall)
        status = OperStatus()
        ctrl = self.ctrl
        myname = self.name
        url = ctrl.get_ext_mount_config_url(myname)
        ext = fwInstance.get_url_extension()
        url += ext
        resp = ctrl.http_delete_request(url, data=None, headers=None)
        if(resp is None):
            status.set_status(STATUS.CONN_ERROR)
        elif(resp.content is None):
            status.set_status(STATUS.CTRL_INTERNAL_ERROR)
        elif (resp.status_code == 200):
            status.set_status(STATUS.OK)
        else:
            status.set_status(STATUS.HTTP_ERROR, resp)

        return Result(status, None)
Ejemplo n.º 11
0
 def delete_dataplane_interface_firewall(self, ifName):
     """ Delete both inbound and outbound firewalls for a
         dataplane interface on the VRouter5600.
     
     :param string ifName: The dataplane interface to attach a firewall.
     :return: A tuple:  Status, Response from VRouter5600.
     :rtype: instance of the `Result` class
     
     - STATUS.CONN_ERROR: If the controller did not respond.
     - STATUS.CTRL_INTERNAL_ERROR: If the controller responded but did
                                   not provide any status.
     - STATUS.OK: Success. Result is valid.
     - STATUS.HTTP_ERROR: If the controller responded with an error
                          status code.
     
     """
     status = OperStatus()
     templateModelRef = "vyatta-interfaces:interfaces/vyatta-interfaces-dataplane:dataplane/{}/vyatta-security-firewall:firewall/"
     modelref = templateModelRef.format(ifName)
     myname = self.name
     ctrl = self.ctrl
     url = ctrl.get_ext_mount_config_url(myname)
     
     resp = ctrl.http_delete_request(url + modelref, data=None, headers=None)
     if(resp == None):
         status.set_status(STATUS.CONN_ERROR)
     elif(resp.content == None):
         status.set_status(STATUS.CTRL_INTERNAL_ERROR)
     elif (resp.status_code == 200):
         status.set_status(STATUS.OK)
     else:
         status.set_status(STATUS.HTTP_ERROR, resp)
     
     return Result(status, None)
Ejemplo n.º 12
0
 def get_firewall_instance_cfg(self, instance):
     """Return configuration for a specific firewall on the VRouter5600.
      :param instance of the 'Firewall' class
     :return: A tuple: Status, JSON for firewall configuration.
     :rtype: instance of the `Result` class (containing configuration data)
      - STATUS.CONN_ERROR: If the controller did not respond.
     - STATUS.CTRL_INTERNAL_ERROR: If the controller responded but did not
                                   provide any status.
     - STATUS.OK:  Success. Result is valid.
     - STATUS.HTTP_ERROR: If the controller responded with an error
                          status code.
     """
     status = OperStatus()
     cfg = None
     templateModelRef = "vyatta-security:" + \
         "security/vyatta-security-firewall:firewall/name/{}"
     modelref = templateModelRef.format(instance)
     ctrl = self.ctrl
     myname = self.name
     url = ctrl.get_ext_mount_config_url(myname)
     url += modelref
     resp = ctrl.http_get_request(url, data=None, headers=None)
     if(resp is None):
         status.set_status(STATUS.CONN_ERROR)
     elif(resp.content is None):
         status.set_status(STATUS.CTRL_INTERNAL_ERROR)
     elif (resp.status_code == 200):
         cfg = resp.content
         status.set_status(STATUS.OK)
     else:
         status.set_status(STATUS.HTTP_ERROR, resp)
     return Result(status, cfg)
Ejemplo n.º 13
0
 def get_cfg(self):
     """Return configuration
     :return: A tuple: Status, JSON for configuration.
     :rtype: instance of the `Result` class (containing configuration data)
     - STATUS.CONN_ERROR: If the controller did not respond.
     - STATUS.CTRL_INTERNAL_ERROR: If the controller responded but did not
                                   provide any status.
     - STATUS.OK: Success. Result is valid.
     - STATUS.HTTP_ERROR: If the controller responded with an error
                          status code.
     """
     status = OperStatus()
     cfg = None
     ctrl = self.ctrl
     myname = self.name
     url = ctrl.get_ext_mount_config_url(myname)
     resp = ctrl.http_get_request(url, data=None, headers=None)
     if(resp is None):
         status.set_status(STATUS.CONN_ERROR)
     elif(resp.content is None):
         status.set_status(STATUS.CTRL_INTERNAL_ERROR)
     elif (resp.status_code == 200):
         cfg = resp.content
         status.set_status(STATUS.OK)
     else:
         status.set_status(STATUS.HTTP_ERROR, resp)
     return Result(status, cfg)
Ejemplo n.º 14
0
 def get_loopback_interface_cfg(self, ifName):
     """ Return the configuration for a single loopback interface
         on the VRouter5600
     
     :param string ifName: The interface name of the interface for which
                           configuration should be returned
     :return: A tuple: Status, configuration of dataplane interface
     :rtype: instance of the `Result` class (containing configuration data)
     
     - STATUS.CONN_ERROR: If the controller did not respond.
     - STATUS.CTRL_INTERNAL_ERROR: If the controller responded but did not
                                   provide any status.
     - STATUS.OK: Success. Result is valid.
     - STATUS.HTTP_ERROR: If the controller responded with an error
                          status code.
     
     """
     status = OperStatus()
     templateModelRef = "vyatta-interfaces:interfaces/vyatta-interfaces-loopback:loopback/{}"
     modelref = templateModelRef.format(ifName)
     ctrl = self.ctrl
     url = ctrl.get_ext_mount_config_url(self.name)
     url += modelref
     
     resp = ctrl.http_get_request(url, data=None, headers=None)
     if(resp == None):
         status.set_status(STATUS.CONN_ERROR)
     elif(resp.content == None):
         status.set_status(STATUS.CTRL_INTERNAL_ERROR)
     elif (resp.status_code == 200):
         status.set_status(STATUS.OK)
     else:
         status.set_status(STATUS.HTTP_ERROR, resp)
     
     return Result(status, resp)
Ejemplo n.º 15
0
 def set_vpn_cfg(self, vpn):
     """ Create/update VPN configuration
     
     :param vpn: instance of the 'Vpn' class
     :return: A tuple: Status, None
     :rtype: instance of the `Result` class
     
     - STATUS.CONN_ERROR: If the controller did not respond.
     - STATUS.CTRL_INTERNAL_ERROR: If the controller responded but did not
                                   provide any status.
     - STATUS.OK: Success. Result is valid.
     - STATUS.HTTP_ERROR: If the controller responded with an error
                          status code.
     
     """
     assert(isinstance(vpn, Vpn))
     status = OperStatus()
     ctrl = self.ctrl
     headers = {'content-type': 'application/yang.data+json'}
     url = ctrl.get_ext_mount_config_url(self.name)
     
     obj = vpn
     payload = obj.get_payload()
     resp = ctrl.http_post_request(url, payload, headers)
     if(resp == None):
         status.set_status(STATUS.CONN_ERROR)
     elif(resp.content == None):
         status.set_status(STATUS.CTRL_INTERNAL_ERROR)
     elif (resp.status_code == 200 or resp.status_code == 204):
         status.set_status(STATUS.OK)
     else:
         status.set_status(STATUS.HTTP_ERROR, resp)
     
     return Result(status, None)
Ejemplo n.º 16
0
 def create_firewall_instance(self, fwInstance):
     """Create a firewall on the VRouter5600.
     
     :param fwInstance: instance of the 'Firewall' class
     :return: A tuple:  Status, None.
     :rtype: instance of the `Result` class
     
     - STATUS.CONN_ERROR: If the controller did not respond.
     - STATUS.CTRL_INTERNAL_ERROR: If the controller responded but did not
                                   provide any status.
     - STATUS.OK:  Success. Result is valid.
     - STATUS.HTTP_ERROR: If the controller responded with an error
                          status code.
     
     """
     status = OperStatus()
     ctrl = self.ctrl
     myname = self.name
     url = ctrl.get_ext_mount_config_url(myname)
     headers = {'content-type': 'application/yang.data+json'}
     payload = fwInstance.get_payload()
     
     resp = ctrl.http_post_request(url, payload, headers)
     if(resp == None):
         status.set_status(STATUS.CONN_ERROR)
     elif(resp.content == None):
         status.set_status(STATUS.CTRL_INTERNAL_ERROR)
     elif (resp.status_code == 200 or resp.status_code == 204):
         status.set_status(STATUS.OK)
     else:
         status.set_status(STATUS.HTTP_ERROR, resp)
     
     return Result(status, None)
Ejemplo n.º 17
0
    def set_dataplane_interface_firewall(self, ifName, inboundFwName,
                                         outboundFwName):
        """ Set a firewall for inbound, outbound or both for a 
            dataplane interface on the VRouter5600.
        
        :param string ifName: The dataplane interface to attache a firewall.
        :param string inboundFwName: None or name of firewall on VRouter5600
                                     to use for traffic inbound towards router.
        :param string outboundFwName: None or name of firewall on VRouter5600
                                     to use for traffic outbound from router.
        :return: A tuple:  Status, None.
        :rtype: instance of the `Result` class
        
        - STATUS.CONN_ERROR:  if the controller did not respond. schema is empty.
        - STATUS.CTRL_INTERNAL_ERROR:  if the controller responded but did not provide any status. schema is empty.
        - STATUS.OK:  Success. result is valid.
        - STATUS.HTTP_ERROR:  if the controller responded with an error status code.
        
        """
        status = OperStatus()
        ctrl = self.ctrl
        headers = {'content-type': 'application/yang.data+json'}
        url = ctrl.get_ext_mount_config_url(self.name)

        obj = DataplaneInterfaceFirewall(ifName)

        if (inboundFwName != None):
            obj.add_in_policy(inboundFwName)

        if (outboundFwName != None):
            obj.add_out_policy(outboundFwName)

        payload = obj.get_payload()
        url += obj.get_url_extension()
        resp = ctrl.http_put_request(url, payload, headers)
        if (resp == None):
            status.set_status(STATUS.CONN_ERROR)
        elif (resp.content == None):
            status.set_status(STATUS.CTRL_INTERNAL_ERROR)
        elif (resp.status_code == 200):
            status.set_status(STATUS.OK)
        else:
            status.set_status(STATUS.HTTP_ERROR, resp)

        return Result(status, None)
Ejemplo n.º 18
0
 def delete_vpn_cfg(self):
     """ Delete VPN configuration """
     status = OperStatus()
     url_ext = "vyatta-security:security/vyatta-security-vpn-ipsec:vpn"
     ctrl = self.ctrl
     myname = self.name
     url = ctrl.get_ext_mount_config_url(myname)
     url += url_ext
     resp = ctrl.http_delete_request(url, data=None, headers=None)
     if (resp is None):
         status.set_status(STATUS.CONN_ERROR)
     elif (resp.content is None):
         status.set_status(STATUS.CTRL_INTERNAL_ERROR)
     elif (resp.status_code == 200):
         status.set_status(STATUS.OK)
     else:
         status.set_status(STATUS.HTTP_ERROR, resp)
     return Result(status, None)
Ejemplo n.º 19
0
    def delete_openvpn_interface_cfg(self, ifName):
        status = OperStatus()
        templateModelRef = "vyatta-interfaces:interfaces/vyatta-interfaces-openvpn:openvpn/{}"
        modelref = templateModelRef.format(ifName)
        ctrl = self.ctrl
        url = ctrl.get_ext_mount_config_url(self.name)
        url += modelref

        resp = ctrl.http_delete_request(url, data=None, headers=None)
        if (resp == None):
            status.set_status(STATUS.CONN_ERROR)
        elif (resp.content == None):
            status.set_status(STATUS.CTRL_INTERNAL_ERROR)
        elif (resp.status_code == 200):
            status.set_status(STATUS.OK)
        else:
            status.set_status(STATUS.HTTP_ERROR, resp)

        return Result(status, resp)
Ejemplo n.º 20
0
 def delete_protocols_cfg(self, model_ref=None):
     status = OperStatus()
     url_ext = "vyatta-protocols:protocols"
     ctrl = self.ctrl
     myname = self.name
     url = ctrl.get_ext_mount_config_url(myname)
     url += url_ext
     if (model_ref is not None):
         url += "/" + model_ref
     resp = ctrl.http_delete_request(url, data=None, headers=None)
     if (resp is None):
         status.set_status(STATUS.CONN_ERROR)
     elif (resp.content is None):
         status.set_status(STATUS.CTRL_INTERNAL_ERROR)
     elif (resp.status_code == 200):
         status.set_status(STATUS.OK)
     else:
         status.set_status(STATUS.HTTP_ERROR, resp)
     return Result(status, None)
Ejemplo n.º 21
0
    def set_protocols_static_route_cfg(self, static_route):
        assert (isinstance(static_route, StaticRoute))
        status = OperStatus()
        ctrl = self.ctrl
        headers = {'content-type': 'application/yang.data+json'}
        url = ctrl.get_ext_mount_config_url(self.name)

        obj = static_route
        payload = obj.get_payload()
        resp = ctrl.http_post_request(url, payload, headers)
        if (resp == None):
            status.set_status(STATUS.CONN_ERROR)
        elif (resp.content == None):
            status.set_status(STATUS.CTRL_INTERNAL_ERROR)
        elif (resp.status_code == 200 or resp.status_code == 204):
            status.set_status(STATUS.OK)
        else:
            status.set_status(STATUS.HTTP_ERROR, resp)

        return Result(status, None)
Ejemplo n.º 22
0
 def set_openvpn_interface_cfg(self, openvpn_interface):
     assert (isinstance(openvpn_interface, OpenVpnInterface))
     status = OperStatus()
     ctrl = self.ctrl
     headers = {'content-type': 'application/yang.data+json'}
     url = ctrl.get_ext_mount_config_url(self.name)
     obj = openvpn_interface
     payload = obj.get_payload()
     ext = openvpn_interface.get_url_extension()
     url += ext
     resp = ctrl.http_put_request(url, payload, headers)
     if (resp is None):
         status.set_status(STATUS.CONN_ERROR)
     elif (resp.content is None):
         status.set_status(STATUS.CTRL_INTERNAL_ERROR)
     elif (resp.status_code == 200 or resp.status_code == 204):
         status.set_status(STATUS.OK)
     else:
         status.set_status(STATUS.HTTP_ERROR, resp)
     return Result(status, None)
Ejemplo n.º 23
0
 def set_dataplane_interface_firewall(self, ifName,
                                      inboundFwName, outboundFwName):
     """ Set a firewall for inbound, outbound or both for a 
         dataplane interface on the VRouter5600.
     
     :param string ifName: The dataplane interface to attache a firewall.
     :param string inboundFwName: None or name of firewall on VRouter5600
                                  to use for traffic inbound towards router.
     :param string outboundFwName: None or name of firewall on VRouter5600
                                  to use for traffic outbound from router.
     :return: A tuple:  Status, None.
     :rtype: instance of the `Result` class
     
     - STATUS.CONN_ERROR:  if the controller did not respond. schema is empty.
     - STATUS.CTRL_INTERNAL_ERROR:  if the controller responded but did not provide any status. schema is empty.
     - STATUS.OK:  Success. result is valid.
     - STATUS.HTTP_ERROR:  if the controller responded with an error status code.
     
     """
     status = OperStatus()
     ctrl = self.ctrl
     headers = {'content-type': 'application/yang.data+json'}
     url = ctrl.get_ext_mount_config_url(self.name)
     
     obj = DataplaneInterfaceFirewall(ifName)
     
     if (inboundFwName != None):
         obj.add_in_policy(inboundFwName)
     
     if (outboundFwName != None):
         obj.add_out_policy(outboundFwName)
     
     payload = obj.get_payload()
     url += obj.get_url_extension()
     resp = ctrl.http_put_request(url, payload, headers)
     if(resp == None):
         status.set_status(STATUS.CONN_ERROR)
     elif(resp.content == None):
         status.set_status(STATUS.CTRL_INTERNAL_ERROR)
     elif (resp.status_code == 200):
         status.set_status(STATUS.OK)
     else:
         status.set_status(STATUS.HTTP_ERROR, resp)
     
     return Result(status, None)
Ejemplo n.º 24
0
 def set_protocols_static_route_cfg(self, static_route):
     assert(isinstance(static_route, StaticRoute))
     status = OperStatus()
     ctrl = self.ctrl
     headers = {'content-type': 'application/yang.data+json'}
     url = ctrl.get_ext_mount_config_url(self.name)
     obj = static_route
     payload = obj.get_payload()
     resp = ctrl.http_post_request(url, payload, headers)
     if(resp is None):
         status.set_status(STATUS.CONN_ERROR)
     elif(resp.content is None):
         status.set_status(STATUS.CTRL_INTERNAL_ERROR)
     elif (resp.status_code == 200 or resp.status_code == 204):
         status.set_status(STATUS.OK)
     else:
         status.set_status(STATUS.HTTP_ERROR, resp)
     return Result(status, None)
Ejemplo n.º 25
0
 def delete_vpn_cfg(self):
     """ Delete VPN configuration """
     status = OperStatus()
     url_ext = "vyatta-security:security/vyatta-security-vpn-ipsec:vpn"
     ctrl = self.ctrl
     myname = self.name
     url = ctrl.get_ext_mount_config_url(myname)
     url += url_ext
     resp = ctrl.http_delete_request(url, data=None, headers=None)
     if(resp is None):
         status.set_status(STATUS.CONN_ERROR)
     elif(resp.content is None):
         status.set_status(STATUS.CTRL_INTERNAL_ERROR)
     elif (resp.status_code == 200):
         status.set_status(STATUS.OK)
     else:
         status.set_status(STATUS.HTTP_ERROR, resp)
     return Result(status, None)
Ejemplo n.º 26
0
 def delete_openvpn_interface_cfg(self, ifName):
     status = OperStatus()
     templateModelRef = "vyatta-interfaces:interfaces/vyatta-interfaces-openvpn:openvpn/{}"
     modelref = templateModelRef.format(ifName)
     ctrl = self.ctrl
     url = ctrl.get_ext_mount_config_url(self.name)
     url += modelref
     
     resp = ctrl.http_delete_request(url, data=None, headers=None)
     if(resp == None):
         status.set_status(STATUS.CONN_ERROR)
     elif(resp.content == None):
         status.set_status(STATUS.CTRL_INTERNAL_ERROR)
     elif (resp.status_code == 200):
         status.set_status(STATUS.OK)
     else:
         status.set_status(STATUS.HTTP_ERROR, resp)
     
     return Result(status, resp)
Ejemplo n.º 27
0
 def delete_protocols_cfg(self, model_ref=None):
     status = OperStatus()
     url_ext = "vyatta-protocols:protocols"
     ctrl = self.ctrl
     myname = self.name
     url = ctrl.get_ext_mount_config_url(myname)
     url += url_ext
     if (model_ref is not None):
         url += "/" + model_ref
     resp = ctrl.http_delete_request(url, data=None, headers=None)
     if(resp is None):
         status.set_status(STATUS.CONN_ERROR)
     elif(resp.content is None):
         status.set_status(STATUS.CTRL_INTERNAL_ERROR)
     elif (resp.status_code == 200):
         status.set_status(STATUS.OK)
     else:
         status.set_status(STATUS.HTTP_ERROR, resp)
     return Result(status, None)
Ejemplo n.º 28
0
 def set_openvpn_interface_cfg(self, openvpn_interface):
     assert(isinstance(openvpn_interface, OpenVpnInterface))
     status = OperStatus()
     ctrl = self.ctrl
     headers = {'content-type': 'application/yang.data+json'}
     url = ctrl.get_ext_mount_config_url(self.name)
     obj = openvpn_interface
     payload = obj.get_payload()
     ext = openvpn_interface.get_url_extension()
     url += ext
     resp = ctrl.http_put_request(url, payload, headers)
     if(resp is None):
         status.set_status(STATUS.CONN_ERROR)
     elif(resp.content is None):
         status.set_status(STATUS.CTRL_INTERNAL_ERROR)
     elif (resp.status_code == 200 or resp.status_code == 204):
         status.set_status(STATUS.OK)
     else:
         status.set_status(STATUS.HTTP_ERROR, resp)
     return Result(status, None)
Ejemplo n.º 29
0
 def get_portprofile(self):
     """
     Return port profiles
     """
     status = OperStatus()
     cfg = None
     templateModelRef = "brocade-port-profile:port-profile-global"
     modelref = templateModelRef
     ctrl = self.ctrl
     url = ctrl.get_ext_mount_config_url(self.name)
     url += modelref
     resp = ctrl.http_get_request(url, data=None, headers=None)
     if(resp is None):
         status.set_status(STATUS.CONN_ERROR)
     elif(resp.content is None):
         status.set_status(STATUS.CTRL_INTERNAL_ERROR)
     elif (resp.status_code == 200):
         cfg = resp.content
         status.set_status(STATUS.OK)
     else:
         status.set_status(STATUS.HTTP_ERROR, resp)
     return Result(status, cfg)   
Ejemplo n.º 30
0
 def get_protocols_cfg(self, model_ref=None):
     status = OperStatus()
     templateModelRef = "vyatta-protocols:protocols"
     cfg = None
     
     ctrl = self.ctrl
     url = ctrl.get_ext_mount_config_url(self.name)
     url += templateModelRef
     if (model_ref != None):
         url += "/" + model_ref
     
     resp = ctrl.http_get_request(url, data=None, headers=None)
     if(resp == None):
         status.set_status(STATUS.CONN_ERROR)
     elif(resp.content == None):
         status.set_status(STATUS.CTRL_INTERNAL_ERROR)
     elif (resp.status_code == 200):
         cfg = resp.content
         status.set_status(STATUS.OK)
     elif (resp.status_code == 404):
         status.set_status(STATUS.DATA_NOT_FOUND, resp)
     else:
         status.set_status(STATUS.HTTP_ERROR, resp)
     
     return Result(status, cfg)
Ejemplo n.º 31
0
 def get_vpn_cfg(self):
     """Return VPN configuration of the VRouter5600.
     
     :return: A tuple: Status, JSON for VPN configuration.
     :rtype: instance of the `Result` class (containing configuration data)
     
     - STATUS.CONN_ERROR: If the controller did not respond.
     - STATUS.CTRL_INTERNAL_ERROR: If the controller responded but did
                                   not provide any status.
     - STATUS.OK: Success. Result is valid.
     - STATUS.HTTP_ERROR: If the controller responded with an error
                          status code.
     
     """
     status = OperStatus()
     url_ext = "vyatta-security:security/vyatta-security-vpn-ipsec:vpn"
     cfg = None
     
     ctrl = self.ctrl
     myname = self.name
     url = ctrl.get_ext_mount_config_url(myname)
     url += url_ext
     
     resp = ctrl.http_get_request(url, data=None, headers=None)
     if(resp == None):
         status.set_status(STATUS.CONN_ERROR)
     elif(resp.content == None):
         status.set_status(STATUS.CTRL_INTERNAL_ERROR)
     elif (resp.status_code == 200):
         cfg = resp.content
         status.set_status(STATUS.OK)
     elif (resp.status_code == 404):
         status.set_status(STATUS.DATA_NOT_FOUND, resp)
     else:
         status.set_status(STATUS.HTTP_ERROR, resp)
     
     return Result(status, cfg)
Ejemplo n.º 32
0
 def get_openvpn_interface_cfg(self, ifName):
     status = OperStatus()
     templateModelRef = "vyatta-interfaces:" + \
         "interfaces/vyatta-interfaces-openvpn:" + \
         "openvpn/{}"
     cfg = None
     modelref = templateModelRef.format(ifName)
     ctrl = self.ctrl
     url = ctrl.get_ext_mount_config_url(self.name)
     url += modelref
     resp = ctrl.http_get_request(url, data=None, headers=None)
     if (resp is None):
         status.set_status(STATUS.CONN_ERROR)
     elif (resp.content is None):
         status.set_status(STATUS.CTRL_INTERNAL_ERROR)
     elif (resp.status_code == 200):
         cfg = resp.content
         status.set_status(STATUS.OK)
     elif (resp.status_code == 404):
         status.set_status(STATUS.DATA_NOT_FOUND, resp)
     else:
         status.set_status(STATUS.HTTP_ERROR, resp)
     return Result(status, cfg)
Ejemplo n.º 33
0
    def get_vpn_cfg(self):
        """Return VPN configuration of the VRouter5600.
        
        :return: A tuple: Status, JSON for VPN configuration.
        :rtype: instance of the `Result` class (containing configuration data)
        
        - STATUS.CONN_ERROR: If the controller did not respond.
        - STATUS.CTRL_INTERNAL_ERROR: If the controller responded but did
                                      not provide any status.
        - STATUS.OK: Success. Result is valid.
        - STATUS.HTTP_ERROR: If the controller responded with an error
                             status code.
        
        """
        status = OperStatus()
        url_ext = "vyatta-security:security/vyatta-security-vpn-ipsec:vpn"
        cfg = None

        ctrl = self.ctrl
        myname = self.name
        url = ctrl.get_ext_mount_config_url(myname)
        url += url_ext

        resp = ctrl.http_get_request(url, data=None, headers=None)
        if (resp == None):
            status.set_status(STATUS.CONN_ERROR)
        elif (resp.content == None):
            status.set_status(STATUS.CTRL_INTERNAL_ERROR)
        elif (resp.status_code == 200):
            cfg = resp.content
            status.set_status(STATUS.OK)
        elif (resp.status_code == 404):
            status.set_status(STATUS.DATA_NOT_FOUND, resp)
        else:
            status.set_status(STATUS.HTTP_ERROR, resp)

        return Result(status, cfg)
Ejemplo n.º 34
0
    def get_protocols_cfg(self, model_ref=None):
        status = OperStatus()
        templateModelRef = "vyatta-protocols:protocols"
        cfg = None

        ctrl = self.ctrl
        url = ctrl.get_ext_mount_config_url(self.name)
        url += templateModelRef
        if (model_ref != None):
            url += "/" + model_ref

        resp = ctrl.http_get_request(url, data=None, headers=None)
        if (resp == None):
            status.set_status(STATUS.CONN_ERROR)
        elif (resp.content == None):
            status.set_status(STATUS.CTRL_INTERNAL_ERROR)
        elif (resp.status_code == 200):
            cfg = resp.content
            status.set_status(STATUS.OK)
        elif (resp.status_code == 404):
            status.set_status(STATUS.DATA_NOT_FOUND, resp)
        else:
            status.set_status(STATUS.HTTP_ERROR, resp)

        return Result(status, cfg)
Ejemplo n.º 35
0
 def get_openvpn_interface_cfg(self, ifName):
     status = OperStatus()
     templateModelRef = "vyatta-interfaces:" + \
         "interfaces/vyatta-interfaces-openvpn:" + \
         "openvpn/{}"
     cfg = None
     modelref = templateModelRef.format(ifName)
     ctrl = self.ctrl
     url = ctrl.get_ext_mount_config_url(self.name)
     url += modelref
     resp = ctrl.http_get_request(url, data=None, headers=None)
     if(resp is None):
         status.set_status(STATUS.CONN_ERROR)
     elif(resp.content is None):
         status.set_status(STATUS.CTRL_INTERNAL_ERROR)
     elif (resp.status_code == 200):
         cfg = resp.content
         status.set_status(STATUS.OK)
     elif (resp.status_code == 404):
         status.set_status(STATUS.DATA_NOT_FOUND, resp)
     else:
         status.set_status(STATUS.HTTP_ERROR, resp)
     return Result(status, cfg)