コード例 #1
0
def get_network_from_ip(ip, database_environment):
    net_api_credentials = get_credentials_for(
        environment=database_environment,
        credential_type=CredentialType.NETWORKAPI
    )

    ip_client = Ip.Ip(
        net_api_credentials.endpoint, net_api_credentials.user,
        net_api_credentials.password
    )

    ips = ip_client.get_ipv4_or_ipv6(ip)
    ips = ips['ips']
    if type(ips) != list:
        ips = [ips]

    net_ip = ips[0]
    network_client = Network.Network(
        net_api_credentials.endpoint, net_api_credentials.user,
        net_api_credentials.password
    )

    network = network_client.get_network_ipv4(net_ip['networkipv4'])
    network = network['network']

    return network['oct1'] + '.' + network['oct2'] + '.' + network['oct3'] + '.' + network['oct4'] + '/' + network['block']
コード例 #2
0
ファイル: acl.py プロジェクト: renatosis/rpaas
 def __init__(self, config, storage, lock_manager):
     self.storage = storage
     self.service_name = config.get("RPAAS_SERVICE_NAME", "rpaas")
     self.acl_api_host = config.get("ACL_API_HOST")
     self.acl_api_user = config.get("ACL_API_USER")
     self.acl_api_password = config.get("ACL_API_PASSWORD")
     self.acl_api_timeout = int(config.get("ACL_API_TIMEOUT", 30))
     self.acl_port_range_start = config.get("ACL_PORT_RANGE_START", "30000")
     self.acl_port_range_end = config.get("ACL_PORT_RANGE_END", "61000")
     self.network_api_url = config.get("NETWORK_API_URL", None)
     self.acl_auth_basic = HTTPBasicAuth(self.acl_api_user,
                                         self.acl_api_password)
     self.lock_manager = lock_manager
     self.lock_name = "acl_manager:{}".format(self.service_name)
     if self.network_api_url:
         self.network_api_username = config.get("NETWORK_API_USERNAME")
         self.network_api_password = config.get("NETWORK_API_PASSWORD")
         self.ip_client = Ip.Ip(self.network_api_url,
                                self.network_api_username,
                                self.network_api_password)
         self.network_client = Network.Network(self.network_api_url,
                                               self.network_api_username,
                                               self.network_api_password)