Beispiel #1
0
    def get(self, configuration, ipv4_address):
        """
        Get an IP4 Address

        """
        configuration = g.user.get_api().get_configuration(configuration)

        try:
            result = se.get_address_data(configuration.get_id(), ipv4_address)
            if result['status'] == 'FAIL':
                raise Exception
            name = ""
            ip_id = 0
            properties = ""
            if result['data']['state'] != 'UNALLOCATED':
                ip = configuration.get_ip4_address(ipv4_address)
                ip_id = ip.get_id()
                name = ip.get_name()
                properties = ""
                for prop, value in ip.get_properties().items():
                    properties += prop + "=" + value + "|"

            response = {
                'id': ip_id,
                'name': name,
                'properties': properties,
                'type': 'IP4Address'
            }
            return response
        except Exception:
            return 'IPv4 address not found', 404
def validate_ip(json):
    configuration = get_key(json, "configuration")
    ip = get_key(json, "ip")
    if ip is None or configuration is None:
        return {
            "data": {},
            "message": "Missing one or more inputs",
            "status": "FAIL"
        }

    try:
        result = se.get_address_data(configuration, ip)
        return result
    except:
        return {"data": {}, "status": "FAIL", "message": "IP not found"}