Beispiel #1
0
    def get_selfips(self, bigip, partition=const.DEFAULT_PARTITION,
                    vlan_name=None):
        selfips_list = []

        if vlan_name:
            if not vlan_name.startswith('/'):
                vlan_name = "/%s/%s" % (partition, vlan_name)

        params = {'params': get_filter(bigip, 'partition', 'eq', partition)}
        try:
            selfips_list = [selfip for selfip in
                            bigip.tm.net.selfips.get_collection(
                                requests_params=params
                            )
                            if vlan_name == selfip.vlan or not vlan_name]
        except HTTPError as err:
            LOG.exception("Error getting selfips for vlan(%s). "
                          "Response status code: %s. "
                          "Response message: %s." % (
                              vlan_name,
                              err.response.status_code,
                              err.message))
            raise f5_ex.SelfIPQueryException(
                "Failed to get selfips assigned to vlan")

        return selfips_list
    def get_resources(self,
                      bigip,
                      partition=None,
                      expand_subcollections=False):
        u"""Retrieve a collection BIG-IP of resources from a BIG-IP.

        Generates a list of resources objects on a BIG-IP system.

        :param bigip: BigIP instance to use for creating resource.
        :param name: Name of resource to load.
        :param partition: Partition name for resource.
        :returns: list of created or updated resource objects.
        """
        resources = []
        try:
            collection = self._collection(bigip)
        except KeyError as err:
            LOG.exception(err.message)
            raise err

        if collection:
            params = {'params': ''}
            if partition:
                params['params'] = get_filter(bigip, 'partition', 'eq',
                                              partition)
                if expand_subcollections and \
                        isinstance(params['params'], dict):
                    params['params']['expandSubcollections'] = 'true'
                elif expand_subcollections:
                    params['params'] += '&expandSubCollections=true'
                resources = collection.get_collection(requests_params=params)
            else:
                resources = collection.get_collection()

        return resources
Beispiel #3
0
    def get_resources(self, bigip, partition=None):
        u"""Retrieve a collection BIG-IP of resources from a BIG-IP.

        Generates a list of resources objects on a BIG-IP system.

        :param bigip: BigIP instance to use for creating resource.
        :param name: Name of resource to load.
        :param partition: Partition name for resource.
        :returns: list of created or updated resource objects.
        """
        resources = []
        try:
            collection = self._collection(bigip)
        except KeyError as err:
            LOG.exception(err.message)
            raise err

        if collection:
            if partition:
                params = {
                    'params': get_filter(bigip, 'partition', 'eq', partition)
                }
                resources = collection.get_collection(requests_params=params)
            else:
                resources = collection.get_collection()

        return resources
    def _arp_delete_by_network(self, bigip, partition, network):
        """Delete ARP entry if address in network"""
        if not network:
            return []
        mac_addresses = []
        ac = bigip.tm.net.arps
        params = {'params': get_filter(bigip, 'partition', 'eq', partition)}
        try:
            arps = ac.get_collection(requests_params=params)
        except HTTPError as err:
            LOG.error("Error getting ARPs."
                      "Repsponse status code: %s. Response "
                      "message: %s." % (err.response.status_code,
                                        err.message))
            return mac_addresses

        for arp in arps:
            address_index = arp.ipAddress.find('%')
            if address_index > -1:
                address = netaddr.IPAddress(arp.ipAddress[0:address_index])
            else:
                address = netaddr.IPAddress(arp.ipAddress)

            if address in network:
                mac_addresses.append(arp.macAddress)
                try:
                    arp.delete()
                except HTTPError as err:
                    LOG.error("Error deleting ARP %s."
                              "Repsponse status code: %s. Response "
                              "message: %s." % (arp.ipAddress,
                                                err.response.status_code,
                                                err.message))
        return mac_addresses
    def get_resources(self, bigip, partition=None):
        u"""Retrieve a collection BIG-IP® of resources from a BIG-IP®.

        Generates a list of resources objects on a BIG-IP® system.

        :param bigip: BigIP instance to use for creating resource.
        :param name: Name of resource to load.
        :param partition: Partition name for resource.
        :returns: list of created or updated resource objects.
        """
        resources = []
        try:
            collection = self._collection(bigip)
        except KeyError as err:
            LOG.exception(err.message)
            raise err

        if collection:
            if partition:
                params = {"params": get_filter(bigip, "partition", "eq", partition)}
                resources = collection.get_collection(requests_params=params)
            else:
                resources = collection.get_collection()

        return resources
Beispiel #6
0
    def get_route_domain_by_id(self, bigip, partition=const.DEFAULT_PARTITION,
                               id=const.DEFAULT_ROUTE_DOMAIN_ID):
        """Returns the route domain by id

        This takes in an id and attempts to find the domain by ID and partition
        off of the BIG-IP and returns the Route Domain object.
        args:
            bigip - should be a f5.bigip.RootManager object instance
        kwargs:
            partition - default is Common - a str that contains the name of the
                tenant's partition
            domain_id - int containing the domain's id
        """
        ret_rd = None
        rdc = bigip.tm.net.route_domains
        params = {}
        if partition:
            params = {
                'params': get_filter(bigip, 'partition', 'eq', partition)
            }
        route_domains = rdc.get_collection(requests_params=params)
        for rd in route_domains:
            if rd.id == id:
                ret_rd = rd
                break
        return ret_rd
    def get_resources(self, bigip, partition=None,
                      expand_subcollections=False):
        u"""Retrieve a collection BIG-IP of resources from a BIG-IP.

        Generates a list of resources objects on a BIG-IP system.

        :param bigip: BigIP instance to use for creating resource.
        :param name: Name of resource to load.
        :param partition: Partition name for resource.
        :returns: list of created or updated resource objects.
        """
        resources = []
        try:
            collection = self._collection(bigip)
        except KeyError as err:
            LOG.exception(err.message)
            raise err

        if collection:
            params = {'params': ''}
            if partition:
                params['params'] = get_filter(
                    bigip, 'partition', 'eq', partition)
                if expand_subcollections and \
                        isinstance(params['params'], dict):
                    params['params']['expandSubcollections'] = 'true'
                elif expand_subcollections:
                    params['params'] += '&expandSubCollections=true'
                resources = collection.get_collection(requests_params=params)
            else:
                resources = collection.get_collection()

        return resources
Beispiel #8
0
    def _arp_delete_by_network(self, bigip, partition, network):
        """Delete ARP entry if address in network"""
        if not network:
            return []
        mac_addresses = []
        ac = bigip.tm.net.arps
        params = {'params': get_filter(bigip, 'partition', 'eq', partition)}
        try:
            arps = ac.get_collection(requests_params=params)
        except HTTPError as err:
            LOG.error("Error getting ARPs."
                      "Repsponse status code: %s. Response "
                      "message: %s." % (err.response.status_code,
                                        err.message))
            return mac_addresses

        for arp in arps:
            address_index = arp.ipAddress.find('%')
            if address_index > -1:
                address = netaddr.IPAddress(arp.ipAddress[0:address_index])
            else:
                address = netaddr.IPAddress(arp.ipAddress)

            if address in network:
                mac_addresses.append(arp.macAddress)
                try:
                    arp.delete()
                except HTTPError as err:
                    LOG.error("Error deleting ARP %s."
                              "Repsponse status code: %s. Response "
                              "message: %s." % (arp.ipAddress,
                                                err.response.status_code,
                                                err.message))
        return mac_addresses
    def get_route_domain_by_id(self, bigip, partition=const.DEFAULT_PARTITION,
                               id=const.DEFAULT_ROUTE_DOMAIN_ID):
        """Returns the route domain by id

        This takes in an id and attempts to find the domain by ID and partition
        off of the BIG-IP and returns the Route Domain object.
        args:
            bigip - should be a f5.bigip.RootManager object instance
        kwargs:
            partition - default is Common - a str that contains the name of the
                tenant's partition
            domain_id - int containing the domain's id
        """
        ret_rd = None
        rdc = bigip.tm.net.route_domains
        params = {}
        if partition:
            params = {
                'params': get_filter(bigip, 'partition', 'eq', partition)
            }
        route_domains = rdc.get_collection(requests_params=params)
        for rd in route_domains:
            if rd.id == id:
                ret_rd = rd
                break
        return ret_rd
Beispiel #10
0
    def get_selfips(self,
                    bigip,
                    partition=const.DEFAULT_PARTITION,
                    vlan_name=None):
        selfips_list = []

        if vlan_name:
            if not vlan_name.startswith('/'):
                vlan_name = "/%s/%s" % (partition, vlan_name)

        params = {'params': get_filter(bigip, 'partition', 'eq', partition)}
        try:
            selfips_list = [
                selfip for selfip in bigip.tm.net.selfips.get_collection(
                    requests_params=params)
                if vlan_name == selfip.vlan or not vlan_name
            ]
        except HTTPError as err:
            LOG.exception("Error getting selfips for vlan(%s). "
                          "Response status code: %s. "
                          "Response message: %s." %
                          (vlan_name, err.response.status_code, err.message))
            raise f5_ex.SelfIPQueryException(
                "Failed to get selfips assigned to vlan")

        return selfips_list
def print_arps(te):
    ac = te.mgmt_root.tm.net.arps
    params = {
        'params': get_filter(te.mgmt_root, 'partition', 'eq', te.partition)
    }
    arps = ac.get_collection(requests_params=params)
    for arp in arps:
        pprint(arp.__dict__)
Beispiel #12
0
def print_arps(te):
    ac = te.mgmt_root.tm.net.arps
    params = {
        'params': get_filter(te.mgmt_root, 'partition', 'eq', te.partition)
    }
    arps = ac.get_collection(requests_params=params)
    for arp in arps:
        pprint(arp.__dict__)
 def get_route_domain_names(self, bigip, partition=const.DEFAULT_PARTITION):
     rdc = bigip.tm.net.route_domains
     params = {}
     if partition:
         params = {
             'params': get_filter(bigip, 'partition', 'eq', partition)
         }
     route_domains = rdc.get_collection(requests_params=params)
     rd_names_list = []
     for rd in route_domains:
         rd_names_list.append(rd.name)
     return rd_names_list
Beispiel #14
0
 def get_route_domain_names(self, bigip, partition=const.DEFAULT_PARTITION):
     rdc = bigip.tm.net.route_domains
     params = {}
     if partition:
         params = {
             'params': get_filter(bigip, 'partition', 'eq', partition)
         }
     route_domains = rdc.get_collection(requests_params=params)
     rd_names_list = []
     for rd in route_domains:
         rd_names_list.append(rd.name)
     return rd_names_list
Beispiel #15
0
 def get_route_domain_by_id(self, bigip, partition=const.DEFAULT_PARTITION,
                            id=const.DEFAULT_ROUTE_DOMAIN_ID):
     ret_rd = None
     rdc = bigip.tm.net.route_domains
     params = {}
     if partition:
         params = {
             'params': get_filter(bigip, 'partition', 'eq', partition)
         }
     route_domains = rdc.get_collection(requests_params=params)
     for rd in route_domains:
         if rd.id == id:
             ret_rd = rd
             break
     return ret_rd
Beispiel #16
0
 def test_route_domain_CRUD(self, setup):
     te = setup
     rd_create = network_helper.create_route_domain(te.mgmt_root,
                                                    te.partition)
     add_resource_teardown(te.request, rd_create)
     rd_read = network_helper.get_route_domain(te.mgmt_root, te.partition)
     assert (rd_read.name == rd_read.name)
     rdc = te.mgmt_root.tm.net.route_domains
     params = {
         'params': get_filter(te.mgmt_root, 'partition', 'eq', te.partition)
     }
     route_domains = rdc.get_collection(requests_params=params)
     rd_names = (rd.name for rd in route_domains)
     assert (rd_create.name in rd_names)
     assert (network_helper.route_domain_exists(te.mgmt_root, te.partition))
     network_helper.delete_route_domain(te.mgmt_root, te.partition,
                                        rd_create.name)
 def test_route_domain_CRUD(self, setup):
     te = setup
     rd_create = network_helper.create_route_domain(
         te.mgmt_root, te.partition)
     add_resource_teardown(te.request, rd_create)
     rd_read = network_helper.get_route_domain(te.mgmt_root, te.partition)
     assert(rd_read.name == rd_read.name)
     rdc = te.mgmt_root.tm.net.route_domains
     params = {
         'params': get_filter(te.mgmt_root, 'partition', 'eq', te.partition)
     }
     route_domains = rdc.get_collection(requests_params=params)
     rd_names = (rd.name for rd in route_domains)
     assert(rd_create.name in rd_names)
     assert(network_helper.route_domain_exists(te.mgmt_root, te.partition))
     network_helper.delete_route_domain(te.mgmt_root, te.partition,
                                        rd_create.name)
def test_gre_profile(setup):
    te = setup
    name = 'test_gre_profile'
    profile = network_helper.create_l2gre_multipoint_profile(
        te.mgmt_root, name, te.partition)
    add_resource_teardown(te.request, profile)
    params = {
        'params': get_filter(te.mgmt_root, 'partition', 'eq', te.partition)
    }
    gc = te.mgmt_root.tm.net.tunnels.gres
    profiles = gc.get_collection(requests_params=params)
    profile_names = (r.name for r in profiles)
    assert(name in profile_names)
    p_obj = te.mgmt_root.tm.net.tunnels.gres.gre
    p = p_obj.load(name=name, partition=te.partition)
    payload = NetworkHelper.l2gre_multipoint_profile_defaults
    for k in payload.keys():
        if k == 'partition':
            continue
        assert(p.__dict__[k] == profile.__dict__[k])
Beispiel #19
0
def test_gre_profile(setup):
    te = setup
    name = 'test_gre_profile'
    profile = network_helper.create_l2gre_multipoint_profile(
        te.mgmt_root, name, te.partition)
    add_resource_teardown(te.request, profile)
    params = {
        'params': get_filter(te.mgmt_root, 'partition', 'eq', te.partition)
    }
    gc = te.mgmt_root.tm.net.tunnels.gres
    profiles = gc.get_collection(requests_params=params)
    profile_names = (r.name for r in profiles)
    assert (name in profile_names)
    p_obj = te.mgmt_root.tm.net.tunnels.gres.gre
    p = p_obj.load(name=name, partition=te.partition)
    payload = NetworkHelper.l2gre_multipoint_profile_defaults
    for k in payload.keys():
        if k == 'partition':
            continue
        assert (p.__dict__[k] == profile.__dict__[k])
 def test_get_filter_v11_5_4(self):
     bigip = mock.MagicMock()
     bigip.tmos_version = "11.5.4"
     f = utils.get_filter(bigip, 'partition', 'eq', 'Common')
     assert f == '$filter=partition+eq+Common'
Beispiel #21
0
 def test_get_filter_v11_5_4(self):
     bigip = mock.MagicMock()
     bigip.tmos_version = "11.5.4"
     f = utils.get_filter(bigip, 'partition', 'eq', 'Common')
     assert f == '$filter=partition+eq+Common'
Beispiel #22
0
 def test_get_filter_v12_1_0(self):
     bigip = mock.MagicMock()
     bigip.tmos_version = "12.1.0"
     f = utils.get_filter(bigip, 'partition', 'eq', 'Common')
     assert isinstance(f, dict)
     assert f == {'$filter': 'partition eq Common'}
 def test_get_filter_v12_1_0(self):
     bigip = mock.MagicMock()
     bigip.tmos_version = "12.1.0"
     f = utils.get_filter(bigip, 'partition', 'eq', 'Common')
     assert isinstance(f, dict)
     assert f == {'$filter': 'partition eq Common'}