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

Commit

Permalink
Merge pull request #126 from deNBI/dev
Browse files Browse the repository at this point in the history
feat(Tags):volumes and instance got more metadata
  • Loading branch information
dweinholz authored Aug 8, 2019
2 parents 4b7aea5 + a2c31a6 commit b4748d7
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 105 deletions.
16 changes: 7 additions & 9 deletions VirtualMachineService/VirtualMachineHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,13 +466,13 @@ def get_network(self):
)
return network

def create_volume_by_start(self, volume_storage, volume_name, server_name):
def create_volume_by_start(self, volume_storage, volume_name, server_name, metadata):
self.logger.info(
"Creating volume with {0} GB diskspace".format(volume_storage)
)
try:
volume = self.conn.block_storage.create_volume(
name=volume_name, size=int(volume_storage)
name=volume_name, size=int(volume_storage), metadata=metadata
).to_dict()
except Exception as e:
self.logger.exception(
Expand All @@ -493,7 +493,7 @@ def create_mount_init_script(self, volume_id):
init_script = base64.b64encode(text).decode("utf-8")
return init_script

def create_volume(self, volume_name, diskspace):
def create_volume(self, volume_name, diskspace, metadata):
"""
Create volume.
:param volume_name: Name of volume
Expand All @@ -503,7 +503,7 @@ def create_volume(self, volume_name, diskspace):
self.logger.info("Creating volume with {0} GB diskspace".format(diskspace))
try:
volume = self.conn.block_storage.create_volume(
name=volume_name, size=int(diskspace)
name=volume_name, size=int(diskspace), metadata=metadata
).to_dict()
volumeId = volume["id"]
return volumeId
Expand All @@ -521,7 +521,7 @@ def start_server(
image,
public_key,
servername,
elixir_id,
metadata,
diskspace,
volumename,
):
Expand All @@ -540,11 +540,10 @@ def start_server(
volume_id = ''
self.logger.info("Start Server {0}".format(servername))
try:
metadata = {"elixir_id": elixir_id}
image = self.get_image(image=image)
flavor = self.get_flavor(flavor=flavor)
network = self.get_network()
key_name = elixir_id[:-18]
key_name = metadata.get("elixir_id")[:-18]
public_key = urllib.parse.unquote(public_key)
key_pair = self.import_keypair(key_name, public_key)

Expand Down Expand Up @@ -581,7 +580,7 @@ def start_server(
self.logger.exception("Start Server {1} error:{0}".format(e, servername))
return {}

def start_server_with_custom_key(self, flavor, image, servername, elixir_id, diskspace,
def start_server_with_custom_key(self, flavor, image, servername, metadata, diskspace,
volumename):

"""
Expand All @@ -599,7 +598,6 @@ def start_server_with_custom_key(self, flavor, image, servername, elixir_id, dis
self.logger.info("Start Server {} with custom key".format(servername))
volume_id = ''
try:
metadata = {"elixir_id": elixir_id}
image = self.get_image(image=image)
flavor = self.get_flavor(flavor=flavor)
network = self.get_network()
Expand Down
16 changes: 8 additions & 8 deletions VirtualMachineService/VirtualMachineService-remote
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ if len(sys.argv) <= 1 or sys.argv[1] == '--help':
print(' delete_metadata_from_server(string servername, keys)')
print(' string add_floating_ip_to_server(string openstack_id, string network)')
print(' bool create_connection(string username, string password, string auth_url, string user_domain_name, string project_domain_name)')
print(' start_server(string flavor, string image, string public_key, string servername, string elixir_id, string diskspace, string volumename)')
print(' start_server_with_custom_key(string flavor, string image, string servername, string elixir_id, string diskspace, string volumename)')
print(' start_server(string flavor, string image, string public_key, string servername, metadata, string diskspace, string volumename)')
print(' start_server_with_custom_key(string flavor, string image, string servername, metadata, string diskspace, string volumename)')
print(' int create_and_deploy_playbook(string public_key, playbooks_information, string openstack_id)')
print(' PlaybookResult get_playbook_logs(string openstack_id)')
print(' bool add_security_group_to_server(bool http, bool https, bool udp, string server_id)')
Expand All @@ -52,7 +52,7 @@ if len(sys.argv) <= 1 or sys.argv[1] == '--help':
print(' VM check_server_status(string openstack_id, int diskspace, string volume_id)')
print(' string setUserPassword(string user, string password)')
print(' bool resume_server(string openstack_id)')
print(' string create_volume(string volume_name, int diskspace)')
print(' string create_volume(string volume_name, int diskspace, metadata)')
print(' bool reboot_server(string server_id, string reboot_type)')
print('')
sys.exit(0)
Expand Down Expand Up @@ -209,13 +209,13 @@ elif cmd == 'start_server':
if len(args) != 7:
print('start_server requires 7 args')
sys.exit(1)
pp.pprint(client.start_server(args[0], args[1], args[2], args[3], args[4], args[5], args[6],))
pp.pprint(client.start_server(args[0], args[1], args[2], args[3], eval(args[4]), args[5], args[6],))

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

elif cmd == 'create_and_deploy_playbook':
if len(args) != 3:
Expand Down Expand Up @@ -302,10 +302,10 @@ elif cmd == 'resume_server':
pp.pprint(client.resume_server(args[0],))

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

elif cmd == 'reboot_server':
if len(args) != 2:
Expand Down
Loading

0 comments on commit b4748d7

Please sign in to comment.