def allocate_ip_handler(client, args): try: sid_msg = SIDUtils.to_pb(args.sid) except ValueError: print("Invalid SubscriberID format: %s" % args.sid) return request = AllocateIPRequest() if int(args.version) == 4: request.version = AllocateIPRequest.IPV4 elif int(args.version) == 6: request.version = AllocateIPRequest.IPV6 else: print("Error: IP version %d is not supported yet" % args.version) return request.sid.CopyFrom(sid_msg) request.apn = args.apn response = client.AllocateIPAddress(request) ip_list_msg = response.ip_list for ip_msg in ip_list_msg: if ip_msg.version == IPAddress.IPV4: ip = ipaddress.IPv4Address(ip_msg.address) print("IPv4 address allocated: %s" % ip) elif ip_msg.version == IPAddress.IPV6: ip = ipaddress.IPv6Address(ip_msg.address) print("IPv6 address allocated: %s" % ip) else: print("Error: unknown IP version")
def allocate_ip_handler(client, args): try: sid_msg = SIDUtils.to_pb(args.sid) except ValueError: print("Invalid SubscriberID format: %s" % args.sid) return request = AllocateIPRequest() request.version = AllocateIPRequest.IPV4 request.sid.CopyFrom(sid_msg) ip_msg = client.AllocateIPAddress(request) if ip_msg.version == IPAddress.IPV4: ip = ipaddress.IPv4Address(ip_msg.address) print("IPv4 address allocated: %s" % ip) elif ip_msg.version == IPAddress.IPV6: ip = ipaddress.IPv6Address(ip_msg.address) print("IPv6 address allocated: %s" % ip) else: print("Error: unknown IP version")