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

Commit

Permalink
Merge branch 'dev' of https://github.com/deNBI/cloud-portal-client in…
Browse files Browse the repository at this point in the history
…to dev
  • Loading branch information
Sören Giller authored and Sören Giller committed Jan 10, 2018
2 parents eaf9c0a + bb1a44e commit 68711ef
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 12 deletions.
2 changes: 1 addition & 1 deletion config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
openstack_connection:
host: 0.0.0.0
port: 9091
port: 9090
jumphost_base: 30000
jumphost_ip: 172.21.40.14
use_jumphost: True
Expand Down
49 changes: 39 additions & 10 deletions gen-py/VirtualMachineService/VirtualMachineHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,34 @@ def get_Images(self):

img = img.to_dict()
img.pop('links', None)
metadata=img['metadata']


try:
if 'description' in metadata and 'default_user' in metadata:
image = Image(name=img['name'], min_disk=img['min_disk'], min_ram=img['min_ram'],
status=img['status'], created_at=img['created_at'], updated_at=img['updated_at'],
openstack_id=img['id'], description=img['metadata']['description'])
openstack_id=img['id'], description=metadata['description'],default_user=metadata['default_user'])


except KeyError:
elif 'description' in metadata:
self.logger.warning("No default_user for " + img['name'])
image = Image(name=img['name'], min_disk=img['min_disk'], min_ram=img['min_ram'],
status=img['status'], created_at=img['created_at'], updated_at=img['updated_at'],
openstack_id=img['id'], description=metadata['description'],
)
elif 'default_user' in metadata:
self.logger.warning("No Description for " + img['name'])
image = Image(name=img['name'], min_disk=img['min_disk'], min_ram=img['min_ram'],
status=img['status'], created_at=img['created_at'], updated_at=img['updated_at'],
openstack_id=img['id'])
openstack_id=img['id'],
default_user=metadata['default_user'])
else:
self.logger.warning("No Description and default_user for " + img['name'])
image = Image(name=img['name'], min_disk=img['min_disk'], min_ram=img['min_ram'],
status=img['status'], created_at=img['created_at'], updated_at=img['updated_at'],
openstack_id=img['id'],
)



images.append(image)
return images
Expand Down Expand Up @@ -146,6 +161,11 @@ def get_server(self, servername):

flav = self.conn.compute.get_flavor(serv['flavor']['id']).to_dict()
img = self.conn.compute.get_image(serv['image']['id']).to_dict()
default_user='default'
try:
default_user=img['metadata']['default_user']
except Exception:
pass
for values in server.addresses.values():
for address in values:

Expand All @@ -158,15 +178,15 @@ def get_server(self, servername):
server = VM(flav=Flavor(vcpus=flav['vcpus'], ram=flav['ram'], disk=flav['disk'], name=flav['name'],
openstack_id=flav['id']),
img=Image(name=img['name'], min_disk=img['min_disk'], min_ram=img['min_ram'], status=img['status'],
created_at=img['created_at'], updated_at=img['updated_at'], openstack_id=img['id']),
created_at=img['created_at'], updated_at=img['updated_at'], openstack_id=img['id'],default_user=default_user),
status=serv['status'], metadata=serv['metadata'], project_id=serv['project_id'],
keyname=serv['key_name'], openstack_id=serv['id'], name=serv['name'], created_at=str(timestamp),
floating_ip=floating_ip, fixed_ip=fixed_ip)
else:
server = VM(flav=Flavor(vcpus=flav['vcpus'], ram=flav['ram'], disk=flav['disk'], name=flav['name'],
openstack_id=flav['id']),
img=Image(name=img['name'], min_disk=img['min_disk'], min_ram=img['min_ram'],
status=img['status'],
status=img['status'],default_user=default_user,
created_at=img['created_at'], updated_at=img['updated_at'], openstack_id=img['id']),
status=serv['status'], metadata=serv['metadata'], project_id=serv['project_id'],
keyname=serv['key_name'], openstack_id=serv['id'], name=serv['name'], created_at=str(timestamp),
Expand Down Expand Up @@ -212,16 +232,25 @@ def start_server(self, flavor, image, public_key, servername, elixir_id):
def generate_SSH_Login_String(self,servername):
#check if jumphost is active


if 'True' == str(self.USE_JUMPHOST):
server_base = self.get_server(servername=servername).fixed_ip.split(".")[-1]
server = self.get_server(servername=servername)
img=server.img
default_user=img.default_user
server_base = server.fixed_ip.split(".")[-1]
port=int(self.JUMPHOST_BASE) + int (server_base)*3
ssh_command="ssh -i private_key_file ubuntu@" + str(self.JUMPHOST_IP) + " -p " + str(port)
ssh_command="ssh -i private_key_file " + str(default_user)+"@" + str(self.JUMPHOST_IP) + " -p " + str(port)

return ssh_command

else:
floating_ip=self.add_floating_ip_to_server(servername, self.FLOATING_IP_NETWORK)
return "ssh -i private_key_file ubuntu@" + str(floating_ip)
server = self.get_server(servername=servername)
img = server.img

default_user=img.default_user

return "ssh -i private_key_file " + str(default_user)+"@" + str(floating_ip)

def add_floating_ip_to_server(self, servername, network):
server = self.conn.compute.find_server(servername)
Expand Down
14 changes: 13 additions & 1 deletion gen-py/VirtualMachineService/ttypes.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions portal_client.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ struct Image{
6:optional string updated_at
7:required string openstack_id
8:optional string description
9:optional string default_user
}
/**
* This Struct defines a VirtualMachine.
Expand All @@ -52,6 +53,7 @@ struct VM {
9: required string created_at
10: optional string floating_ip
11: required string fixed_ip


}

Expand Down

0 comments on commit 68711ef

Please sign in to comment.