Skip to content
This repository has been archived by the owner on May 27, 2024. It is now read-only.

Commit

Permalink
Dev (#200)
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
eKatchko authored Jan 16, 2020
2 parents ea475ad + 3b0d6cf commit 9df87b1
Show file tree
Hide file tree
Showing 5 changed files with 739 additions and 411 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## (2020-01-15)


#### Features

* **Modi:** added more Methods ([f1f357b5](f1f357b5))


## (2020-01-09)

Expand Down
69 changes: 36 additions & 33 deletions VirtualMachineService/VirtualMachineHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1227,7 +1227,7 @@ def get_servers(self):
# self.logger.info(server_list)
return server_list

def add_security_group_to_server(self, http, https, udp, server_id):
def add_udp_security_group(self, server_id):
"""
Adds the default simple vm security group to the vm.
Also adds a security group which can open http,https and udp ports.
Expand All @@ -1242,6 +1242,15 @@ def add_security_group_to_server(self, http, https, udp, server_id):
if server is None:
self.logger.exception("Instance {0} not found".format(server_id))
raise serverNotFoundException
sec = self.conn.get_security_group(name_or_id=server.name + "_udp")
if sec:
self.logger.info(
"Security group with name {} already exists.".format(server.name + "_udp"))
self.conn.compute.add_security_group_to_server(
server=server_id, security_group=sec
)

return True

ip_base = \
list(self.conn.compute.server_ips(server=server_id))[0].to_dict()['address'].split(".")[
Expand All @@ -1252,10 +1261,10 @@ def add_security_group_to_server(self, http, https, udp, server_id):
security_group = self.create_security_group(
name=server.name + "_udp",
udp_port_start=udp_port_start,
udp=udp,
udp=True,
ssh=False,
https=https,
http=http, description="UDP"
https=False,
http=False, description="UDP"
)
self.logger.info(security_group)
self.logger.info("Add security group {} to server {} ".format(security_group.id, server_id))
Expand All @@ -1273,34 +1282,21 @@ def get_servers_by_bibigrid_id(self, bibigrid_id):
thrift_servers.append(self.openstack_server_to_thrift_server(server))
return thrift_servers

def get_ip_ports(self, openstack_id):
def get_vm_ports(self, openstack_id):
"""
Get Ip and Port of the sever.
Get Ports of the sever.
:param openstack_id: Id of the server
:return: {'IP': ip, 'PORT': port, 'UDP':start_port}
"""
:param openstack_id: Id of the server
:return: {'PORT': port, 'UDP':start_port}
"""
self.logger.info("Get IP and PORT for server {0}".format(openstack_id))
server = self.get_server(openstack_id)
server_base = server.fixed_ip.split(".")[-1]
x = int(server_base)
port = eval(self.SSH_PORT_CALCULATION)
udp_port_start = eval(self.UDP_PORT_CALCULATION)
return {"port": str(port), "udp": str(udp_port_start)}

# check if gateway is active
try:
if self.USE_GATEWAY:
server = self.get_server(openstack_id)
server_base = server.fixed_ip.split(".")[-1]
x = int(server_base)
port = eval(self.SSH_PORT_CALCULATION)
udp_port_start = eval(self.UDP_PORT_CALCULATION)
return {"IP": str(self.GATEWAY_IP), "PORT": str(port), "UDP": str(udp_port_start)}

else:
# todo security groups floating ips
floating_ip = self.get_server(openstack_id)
return {"IP": str(floating_ip)}
except Exception as e:
self.logger.exception(
"Get IP and PORT for server {0} error:".format(openstack_id, e)
)
return {}

def get_cluster_info(self, cluster_id):
headers = {"content-Type": "application/json"}
Expand Down Expand Up @@ -1332,6 +1328,12 @@ def get_cluster_info(self, cluster_id):

return None

def get_calculation_formulars(self):
return {"ssh_port_calculation": self.SSH_FORMULAR,
"udp_port_calculation": self.UDP_FORMULAR}

def get_gateway_ip(self):
return {"gateway_ip": self.GATEWAY_IP}

def start_cluster(self, public_key, master_instance, worker_instances, user):
master_instance = master_instance.__dict__
Expand All @@ -1356,7 +1358,7 @@ def terminate_cluster(self, cluster_id):
self.logger.info(response.json())
return response.json()

def create_snapshot(self, openstack_id, name, elixir_id, base_tag, description):
def create_snapshot(self, openstack_id, name, elixir_id, base_tags, description):
"""
Create an Snapshot from an server.
Expand Down Expand Up @@ -1389,10 +1391,11 @@ def create_snapshot(self, openstack_id, name, elixir_id, base_tag, description):
self.conn.update_image_properties(
image=image,
meta={'description': description})

self.conn.image.add_tag(
image=snapshot_id, tag="snapshot_image:{0}".format(base_tag)
)

for tag in base_tags:
self.conn.image.add_tag(
image=snapshot_id, tag=tag
)
except Exception:
self.logger.exception("Tag error catched")
pass
Expand Down
36 changes: 25 additions & 11 deletions VirtualMachineService/VirtualMachineService-remote
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ if len(sys.argv) <= 1 or sys.argv[1] == '--help':
print('Functions:')
print(' bool check_Version(double version)')
print(' string get_client_version()')
print(' get_gateway_ip()')
print(' get_calculation_formulars()')
print(' string import_keypair(string keyname, string public_key)')
print(' get_ip_ports(string openstack_id)')
print(' get_vm_ports(string openstack_id)')
print(' get_Flavors()')
print(' get_Images()')
print(' Image get_Image_with_Tag(string openstack_id)')
Expand All @@ -53,14 +55,14 @@ if len(sys.argv) <= 1 or sys.argv[1] == '--help':
print(' get_templates()')
print(' get_templates_by_template(string template_name)')
print(' check_template(string template_name, string template_version)')
print(' bool add_security_group_to_server(bool http, bool https, bool udp, string server_id)')
print(' bool add_udp_security_group(string server_id)')
print(' get_servers()')
print(' get_servers_by_ids( server_ids)')
print(' get_servers_by_bibigrid_id(string bibigrid_id)')
print(' ClusterInfo get_cluster_info(string cluster_id)')
print(' VM get_server(string openstack_id)')
print(' bool stop_server(string openstack_id)')
print(' string create_snapshot(string openstack_id, string name, string elixir_id, string base_tag, string description)')
print(' string create_snapshot(string openstack_id, string name, string elixir_id, base_tags, string description)')
print(' get_limits()')
print(' start_cluster(string public_key, ClusterInstance master_instance, worker_instance, string user)')
print(' terminate_cluster(string cluster_id)')
Expand Down Expand Up @@ -164,17 +166,29 @@ elif cmd == 'get_client_version':
sys.exit(1)
pp.pprint(client.get_client_version())

elif cmd == 'get_gateway_ip':
if len(args) != 0:
print('get_gateway_ip requires 0 args')
sys.exit(1)
pp.pprint(client.get_gateway_ip())

elif cmd == 'get_calculation_formulars':
if len(args) != 0:
print('get_calculation_formulars requires 0 args')
sys.exit(1)
pp.pprint(client.get_calculation_formulars())

elif cmd == 'import_keypair':
if len(args) != 2:
print('import_keypair requires 2 args')
sys.exit(1)
pp.pprint(client.import_keypair(args[0], args[1],))

elif cmd == 'get_ip_ports':
elif cmd == 'get_vm_ports':
if len(args) != 1:
print('get_ip_ports requires 1 args')
print('get_vm_ports requires 1 args')
sys.exit(1)
pp.pprint(client.get_ip_ports(args[0],))
pp.pprint(client.get_vm_ports(args[0],))

elif cmd == 'get_Flavors':
if len(args) != 0:
Expand Down Expand Up @@ -326,11 +340,11 @@ elif cmd == 'check_template':
sys.exit(1)
pp.pprint(client.check_template(args[0], args[1],))

elif cmd == 'add_security_group_to_server':
if len(args) != 4:
print('add_security_group_to_server requires 4 args')
elif cmd == 'add_udp_security_group':
if len(args) != 1:
print('add_udp_security_group requires 1 args')
sys.exit(1)
pp.pprint(client.add_security_group_to_server(eval(args[0]), eval(args[1]), eval(args[2]), args[3],))
pp.pprint(client.add_udp_security_group(args[0],))

elif cmd == 'get_servers':
if len(args) != 0:
Expand Down Expand Up @@ -372,7 +386,7 @@ elif cmd == 'create_snapshot':
if len(args) != 5:
print('create_snapshot requires 5 args')
sys.exit(1)
pp.pprint(client.create_snapshot(args[0], args[1], args[2], args[3], args[4],))
pp.pprint(client.create_snapshot(args[0], args[1], args[2], eval(args[3]), args[4],))

elif cmd == 'get_limits':
if len(args) != 0:
Expand Down
Loading

0 comments on commit 9df87b1

Please sign in to comment.