Exemplo n.º 1
0
 def get_arps(self, ip_address=None, folder="Common"):
     folder = str(folder).replace("/", "")
     if ip_address:
         request_url = self.bigip.icr_url + "/net/arp/"
         request_url += "~" + folder + "~" + urllib.quote(self._remove_route_domain_zero(ip_address))
         response = self.bigip.icr_session.get(request_url, timeout=const.CONNECTION_TIMEOUT)
         Log.debug("ARP::get response", "%s" % response.json())
         if response.status_code < 400:
             response_obj = json.loads(response.text)
             return [{strip_domain_address(response_obj["name"]): response_obj["macAddress"]}]
         else:
             Log.error("ARP", response.text)
             raise exceptions.StaticARPQueryException(response.text)
     else:
         request_url = self.bigip.icr_url + "/net/arp"
         request_filter = "partition eq " + folder
         request_url += "?$filter=" + request_filter
         response = self.bigip.icr_session.get(request_url, timeout=const.CONNECTION_TIMEOUT)
         Log.debug("ARP::get response", "%s" % response.json())
         if response.status_code < 400:
             response_obj = json.loads(response.text)
             if "items" in response_obj:
                 arps = []
                 for arp in response_obj["items"]:
                     arps.append({strip_domain_address(arp["name"]): arp["macAddress"]})
                 return arps
         else:
             Log.error("ARP", response.text)
             raise exceptions.StaticARPQueryException(response.text)
     return []
Exemplo n.º 2
0
 def get_fdb_entry(self,
                   tunnel_name=None,
                   mac=None,
                   folder='Common'):
     folder = str(folder).replace('/', '')
     request_url = self.bigip.icr_url + '/net/fdb/tunnel/'
     request_url += '~' + folder + '~' + tunnel_name
     response = self.bigip.icr_session.get(request_url,
                                           timeout=const.CONNECTION_TIMEOUT)
     if response.status_code < 400:
         response_obj = json.loads(response.text)
         if 'records' in response_obj:
             if not mac:
                 return_fdbs = []
                 for fdb in response_obj['records']:
                     fdb['endpoint'] = strip_domain_address(fdb['endpoint'])
                     return_fdbs.append(fdb)
                 return return_fdbs
             else:
                 for record in response_obj['records']:
                     if record['name'] == mac:
                         record['endpoint'] = strip_domain_address(
                                                         record['endpoint'])
                         return record
     elif response.status_code != 404:
         Log.error('L2GRE', response.text)
         raise exceptions.L2GRETunnelQueryException(response.text)
     return []
Exemplo n.º 3
0
 def get_fdb_entry(self, tunnel_name=None, mac=None, folder='Common'):
     folder = str(folder).replace('/', '')
     request_url = self.bigip.icr_url + '/net/fdb/tunnel/'
     request_url += '~' + folder + '~' + tunnel_name
     response = self.bigip.icr_session.get(request_url,
                                           timeout=const.CONNECTION_TIMEOUT)
     if response.status_code < 400:
         response_obj = json.loads(response.text)
         if 'records' in response_obj:
             if not mac:
                 return_fdbs = []
                 for fdb in response_obj['records']:
                     fdb['endpoint'] = strip_domain_address(fdb['endpoint'])
                     return_fdbs.append(fdb)
                 return return_fdbs
             else:
                 for record in response_obj['records']:
                     if record['name'] == mac:
                         record['endpoint'] = strip_domain_address(
                             record['endpoint'])
                         return record
     elif response.status_code != 404:
         Log.error('VXLAN', response.text)
         raise exceptions.VXLANQueryException(response.text)
     return []
Exemplo n.º 4
0
 def set_mask(self, name=None, netmask=None, folder='Common'):
     if name:
         folder = str(folder).replace('/', '')
         request_url = self.bigip.icr_url + '/net/self/'
         request_url += '~' + folder + '~' + name
         request_url += '?$select=address'
         response = self.bigip.icr_session.get(
             request_url, timeout=const.CONNECTION_TIMEOUT)
         if response.status_code < 400:
             return_obj = json.loads(response.text)
             try:
                 address = self._strip_mask(return_obj['address'])
                 net = netaddr.IPNetwork(
                     strip_domain_address(address) + '/' + netmask)
                 payload = dict()
                 payload['address'] = address + '/' + str(net.prefixlen)
                 request_url = self.bigip.icr_url + '/net/self/'
                 request_url += '~' + folder + '~' + name
                 response = self.bigip.icr_session.put(
                     request_url,
                     data=json.dumps(payload),
                     timeout=const.CONNECTION_TIMEOUT)
                 if response.status_code < 400:
                     return True
                 else:
                     Log.error('self', response.text)
                     raise exceptions.SelfIPUpdateException(response.text)
             except Exception as e:
                 Log.error('self', 'set_mask exception:' + e.message)
         else:
             Log.error('self', response.text)
             raise exceptions.SelfIPQueryException(response.text)
     return False
Exemplo n.º 5
0
 def get_members_monitor_status(self, name=None, folder='Common'):
     if name:
         folder = str(folder).replace('/', '')
         request_url = self.bigip.icr_url + '/ltm/pool/'
         request_url += '~' + folder + '~' + name
         request_url += '/members?$select=name,state'
         response = self.bigip.icr_session.get(request_url,
                                 timeout=const.CONNECTION_TIMEOUT)
         members = []
         if response.status_code < 400:
             return_obj = json.loads(response.text)
             if 'items' in return_obj:
                 for member in return_obj['items']:
                     name_parts = member['name'].split(":")
                     member_state = 'MONITOR_STATUS_' + \
                                            member['state'].upper()
                     members.append(
                          {
                           'addr': strip_domain_address(name_parts[0]),
                           'port': name_parts[1],
                           'state': member_state
                          }
                     )
         else:
             Log.error('pool', response.text)
             raise exceptions.PoolQueryException(response.text)
         return members
     return None
Exemplo n.º 6
0
 def set_mask(self, name=None, netmask=None, folder="Common"):
     if name:
         folder = str(folder).replace("/", "")
         request_url = self.bigip.icr_url + "/net/self/"
         request_url += "~" + folder + "~" + name
         request_url += "?$select=address"
         response = self.bigip.icr_session.get(request_url, timeout=const.CONNECTION_TIMEOUT)
         if response.status_code < 400:
             return_obj = json.loads(response.text)
             try:
                 address = self._strip_mask(return_obj["address"])
                 net = netaddr.IPNetwork(strip_domain_address(address) + "/" + netmask)
                 payload = dict()
                 payload["address"] = address + "/" + str(net.prefixlen)
                 request_url = self.bigip.icr_url + "/net/self/"
                 request_url += "~" + folder + "~" + name
                 response = self.bigip.icr_session.put(
                     request_url, data=json.dumps(payload), timeout=const.CONNECTION_TIMEOUT
                 )
                 if response.status_code < 400:
                     return True
                 else:
                     Log.error("self", response.text)
                     raise exceptions.SelfIPUpdateException(response.text)
             except Exception as e:
                 Log.error("self", "set_mask exception:" + e.message)
         else:
             Log.error("self", response.text)
             raise exceptions.SelfIPQueryException(response.text)
     return False
Exemplo n.º 7
0
 def get_arps(self, ip_address=None, folder='Common'):
     folder = str(folder).replace('/', '')
     if ip_address:
         request_url = self.bigip.icr_url + '/net/arp/'
         request_url += '~' + folder + '~' + urllib.quote(
             self._remove_route_domain_zero(ip_address))
         response = self.bigip.icr_session.get(
             request_url, timeout=const.CONNECTION_TIMEOUT)
         Log.debug('ARP::get response', '%s' % response.json())
         if response.status_code < 400:
             response_obj = json.loads(response.text)
             return [
                 {strip_domain_address(response_obj['name']): \
                                         response_obj['macAddress']}
             ]
         else:
             Log.error('ARP', response.text)
             raise exceptions.StaticARPQueryException(response.text)
     else:
         request_url = self.bigip.icr_url + '/net/arp'
         request_filter = 'partition eq ' + folder
         request_url += '?$filter=' + request_filter
         response = self.bigip.icr_session.get(
             request_url, timeout=const.CONNECTION_TIMEOUT)
         Log.debug('ARP::get response', '%s' % response.json())
         if response.status_code < 400:
             response_obj = json.loads(response.text)
             if 'items' in response_obj:
                 arps = []
                 for arp in response_obj['items']:
                     arps.append(
                      {strip_domain_address(arp['name']): \
                                            arp['macAddress']}
                     )
                 return arps
         else:
             Log.error('ARP', response.text)
             raise exceptions.StaticARPQueryException(response.text)
     return []
Exemplo n.º 8
0
 def get_addr(self, name=None, folder="Common"):
     folder = str(folder).replace("/", "")
     if name:
         request_url = self.bigip.icr_url + "/net/self/"
         request_url += "~" + folder + "~" + name
         request_url += "?$select=address"
         response = self.bigip.icr_session.get(request_url, timeout=const.CONNECTION_TIMEOUT)
         if response.status_code < 400:
             return_obj = json.loads(response.text)
             return strip_domain_address(self._strip_mask(return_obj["address"]))
         elif response.status_code != 404:
             Log.error("self", response.text)
             raise exceptions.SelfIPQueryException(response.text)
     return None
Exemplo n.º 9
0
 def get_addr(self, name=None, folder='Common'):
     folder = str(folder).replace('/', '')
     if name:
         request_url = self.bigip.icr_url + '/net/self/'
         request_url += '~' + folder + '~' + name
         request_url += '?$select=address'
         response = self.bigip.icr_session.get(
             request_url, timeout=const.CONNECTION_TIMEOUT)
         if response.status_code < 400:
             return_obj = json.loads(response.text)
             return strip_domain_address(
                 self._strip_mask(return_obj['address']))
         elif response.status_code != 404:
             Log.error('self', response.text)
             raise exceptions.SelfIPQueryException(response.text)
     return None
Exemplo n.º 10
0
 def get_original_addr(self, name=None, folder='Common'):
     if name:
         folder = str(folder).replace('/', '')
         request_url = self.bigip.icr_url + '/ltm/nat/'
         request_url += '~' + folder + '~' + name
         request_url += '/?$select=originatingAddress'
         response = self.bigip.icr_session.get(request_url,
                                 timeout=const.CONNECTION_TIMEOUT)
         if response.status_code < 400:
             return_obj = json.loads(response.text)
             if 'originatingAddress' in return_obj:
                 return strip_domain_address(
                                    return_obj['originatingAddress'])
         else:
             Log.error('nat', response.text)
             raise exceptions.NATQueryException(response.text)
         return None
Exemplo n.º 11
0
 def get_original_addr(self, name=None, folder='Common'):
     if name:
         folder = str(folder).replace('/', '')
         request_url = self.bigip.icr_url + '/ltm/nat/'
         request_url += '~' + folder + '~' + name
         request_url += '/?$select=originatingAddress'
         response = self.bigip.icr_session.get(
             request_url, timeout=const.CONNECTION_TIMEOUT)
         if response.status_code < 400:
             return_obj = json.loads(response.text)
             if 'originatingAddress' in return_obj:
                 return strip_domain_address(
                     return_obj['originatingAddress'])
         else:
             Log.error('nat', response.text)
             raise exceptions.NATQueryException(response.text)
         return None
Exemplo n.º 12
0
 def get_addrs(self, folder="Common"):
     folder = str(folder).replace("/", "")
     request_url = self.bigip.icr_url + "/net/self/"
     request_url += "?$select=address"
     request_filter = "partition eq " + folder
     request_url += "&$filter=" + request_filter
     response = self.bigip.icr_session.get(request_url, timeout=const.CONNECTION_TIMEOUT)
     return_list = []
     if response.status_code < 400:
         return_obj = json.loads(response.text)
         if "items" in return_obj:
             for selfip in return_obj["items"]:
                 return_list.append(strip_domain_address(self._strip_mask(selfip["address"])))
     elif response.status_code != 404:
         Log.error("self", response.text)
         raise exceptions.SelfIPQueryException(response.text)
     return return_list
Exemplo n.º 13
0
 def get_floating_addrs(self, prefix=None, folder="Common"):
     folder = str(folder).replace("/", "")
     request_url = self.bigip.icr_url + "/net/self/"
     request_url += "?$select=trafficGroup,floating,address"
     request_filter = "partition eq " + folder
     request_url += "&$filter=" + request_filter
     response = self.bigip.icr_session.get(request_url, timeout=const.CONNECTION_TIMEOUT)
     floats = []
     if response.status_code < 400:
         return_obj = json.loads(response.text)
         if "items" in return_obj:
             for selfip in return_obj["items"]:
                 if selfip["floating"] == "enabled":
                     floats.append(strip_domain_address(self._strip_mask(selfip["address"])))
     else:
         Log.error("self", response.text)
         raise exceptions.SelfIPQueryException(response.text)
     return floats
Exemplo n.º 14
0
    def get_original_addrs(self, folder='Common'):
        folder = str(folder).replace('/', '')
        request_url = self.bigip.icr_url + '/ltm/nat'
        request_url += '?$select=originatingAddress'
        request_url += '&$filter=partition eq ' + folder

        response = self.bigip.icr_session.get(request_url,
                                              timeout=const.CONNECTION_TIMEOUT)
        orig_addresses = []
        if response.status_code < 400:
            return_obj = json.loads(response.text)
            if 'items' in return_obj:
                for nat in return_obj['items']:
                    orig_addresses.append(
                        strip_domain_address(nat['originatingAddress']))
        else:
            Log.error('nat', response.text)
            raise exceptions.NATQueryException(response.text)
        return orig_addresses
Exemplo n.º 15
0
    def get_original_addrs(self, folder='Common'):
        folder = str(folder).replace('/', '')
        request_url = self.bigip.icr_url + '/ltm/nat'
        request_url += '?$select=originatingAddress'
        request_url += '&$filter=partition eq ' + folder

        response = self.bigip.icr_session.get(request_url,
                                     timeout=const.CONNECTION_TIMEOUT)
        orig_addresses = []
        if response.status_code < 400:
            return_obj = json.loads(response.text)
            if 'items' in return_obj:
                for nat in return_obj['items']:
                    orig_addresses.append(
                       strip_domain_address(nat['originatingAddress']))
        else:
            Log.error('nat', response.text)
            raise exceptions.NATQueryException(response.text)
        return orig_addresses
Exemplo n.º 16
0
 def get_addrs(self, folder='Common'):
     folder = str(folder).replace('/', '')
     request_url = self.bigip.icr_url + '/net/self/'
     request_url += '?$select=address'
     request_filter = 'partition eq ' + folder
     request_url += '&$filter=' + request_filter
     response = self.bigip.icr_session.get(request_url,
                                           timeout=const.CONNECTION_TIMEOUT)
     return_list = []
     if response.status_code < 400:
         return_obj = json.loads(response.text)
         if 'items' in return_obj:
             for selfip in return_obj['items']:
                 return_list.append(
                     strip_domain_address(
                         self._strip_mask(selfip['address'])))
     elif response.status_code != 404:
         Log.error('self', response.text)
         raise exceptions.SelfIPQueryException(response.text)
     return return_list
Exemplo n.º 17
0
 def get_floating_addrs(self, prefix=None, folder='Common'):
     folder = str(folder).replace('/', '')
     request_url = self.bigip.icr_url + '/net/self/'
     request_url += '?$select=trafficGroup,floating,address'
     request_filter = 'partition eq ' + folder
     request_url += '&$filter=' + request_filter
     response = self.bigip.icr_session.get(request_url,
                                           timeout=const.CONNECTION_TIMEOUT)
     floats = []
     if response.status_code < 400:
         return_obj = json.loads(response.text)
         if 'items' in return_obj:
             for selfip in return_obj['items']:
                 if selfip['floating'] == 'enabled':
                     floats.append(
                         strip_domain_address(
                             self._strip_mask(selfip['address'])))
     else:
         Log.error('self', response.text)
         raise exceptions.SelfIPQueryException(response.text)
     return floats