Commit a5a2ad01 by Arnau Comas Codina

Port Forwarding interface & resources classes

parent 9adbf711
"""
General interface for using the CIRCLE portal API
It should be implemented for using other providers e. g. OpenStack
"""
class PortForwardingInterface:
def create_port_forwarding(self, instance_id, internal_port_number, protocol):
raise NotImplementedError
def remove_port_forwarding(self, instance_id, internal_port_number):
raise NotImplementedError
def list_instance_port_forwardings(self, instance_id):
raise NotImplementedError
import json
class FloatingIP:
""" From the OpenStack Floating IP source data:
- Releveant attributes are stored
- Some methods regarding class representation
"""
def __init__(self, data):
self.id = data['id'] # str
self.address = data['floating_ip_address'] # str
self.status = data['status'] # str e.g. 'ACTIVE'
self.floating_network_id = data['floating_network_id'] # str
self.router_id = data['router_id'] # str
self.port_forwardings = [] # objects come w/o id here, are fetched after
# [PortForwarding(item) for item in data['port_forwardings']]
self.created_at = data['created_at'] # str
self.updated_at = data['updated_at'] # str
def __repr__(self):
return f"FloatingIP({self.address})"
def __str__(self):
return f"FloatingIP({self.address})"
def JSON(self):
return json.dumps(self.__dict__)
class PortForwarding:
""" From the OpenStack Port Forwarding source data:
- Releveant attributes are stored
- Some methods regarding class representation
"""
def __init__(self, data):
self.id = data['id'] # str
self.protocol = data['protocol'] # str
self.internal_ip_address = data['internal_ip_address'] # str
self.internal_port = data['internal_port'] # number
self.external_port = data['external_port'] # number
def __repr__(self):
return(
f"PortForwarding({self.internal_ip_address}:{self.internal_port}"
f" -> {self.external_port})")
def __str__(self):
return(
f"PortForwarding({self.internal_ip_address}:{self.internal_port}"
f" -> {self.external_port})")
def JSON(self):
return json.dumps(self.__dict__)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment