Unverified Commit 78e83d94 authored by efikalti's avatar efikalti Committed by Avraam Tsantekidis

LAM-39 method to assign public ip to vm

parent 12c1528b
...@@ -133,11 +133,11 @@ class Provisioner: ...@@ -133,11 +133,11 @@ class Provisioner:
def reserve_ip(self): def reserve_ip(self):
""" """
Reserve ip Reserve ip
:return: the id of the ip if successfull :return: the ip object if successfull
""" """
try: try:
ip = self.network_client.create_floatingip() ip = self.network_client.create_floatingip()
return ip['id'] return ip
except ClientError as ex: except ClientError as ex:
raise ex raise ex
return okeanos_response return okeanos_response
...@@ -168,12 +168,29 @@ class Provisioner: ...@@ -168,12 +168,29 @@ class Provisioner:
""" """
try: try:
port = self.network_client.create_port(network_id=net_id, port = self.network_client.create_port(network_id=net_id,
device_id=vm_id,) device_id=vm_id)
return True return True
except ClientError as ex: except ClientError as ex:
raise ex raise ex
return okeanos_response return okeanos_response
def attach_public_ip(self, ip, vm_id):
"""
Attach the public ip with this id to the vm
:param fnet_id: id of the floating network of the ip
:param vm_id: id of the vm
:return: returns True if successfull
"""
try:
port = self.network_client.create_port(network_id=ip['floating_network_id'],
device_id=vm_id,
fixed_ips=[dict(ip_address=ip['floating_ip_address']), ])
return True
except ClientError as ex:
raise ex
return okeanos_response
if __name__ == "__main__": if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Okeanos VM provisioning") parser = argparse.ArgumentParser(description="Okeanos VM provisioning")
parser.add_argument('--cloud', type=str, dest="cloud", default="lambda") parser.add_argument('--cloud', type=str, dest="cloud", default="lambda")
...@@ -187,5 +204,7 @@ if __name__ == "__main__": ...@@ -187,5 +204,7 @@ if __name__ == "__main__":
# net_id = provisioner.create_vpn("test") # net_id = provisioner.create_vpn("test")
# print provisioner.create_private_subnet(net_id) # print provisioner.create_private_subnet(net_id)
# provisioner.connect_vm(663972,net_id) # provisioner.connect_vm(663972,net_id)
# provisioner.reserve_ip() # ip = provisioner.reserve_ip()
# print ip['id']
# provisioner.attach_public_ip(ip,663972)
# provisioner.attach_vm_to_network(663972,net_id) # provisioner.attach_vm_to_network(663972,net_id)
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 to comment