Skip to content

Commit

Permalink
Merge pull request #662 from deNBI/fix/addtional_owner_and_user_keys
Browse files Browse the repository at this point in the history
Fix/addtional owner and user keys
  • Loading branch information
dweinholz authored Jan 8, 2025
2 parents b74a113 + ba6463f commit 494c362
Show file tree
Hide file tree
Showing 9 changed files with 1,435 additions and 560 deletions.
37 changes: 26 additions & 11 deletions portal_client.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,15 @@ service VirtualMachineService {
throws (1:DefaultException r,2:ServerNotFoundException s

)

void add_project_security_group_to_server(
/** OpenStack id of the server*/
1:string server_id,2:string project_name, 3:string project_id)

throws (1:DefaultException r,2:ServerNotFoundException s

)

/**
* Add metadata to a server.
*/
Expand Down Expand Up @@ -449,6 +458,8 @@ service VirtualMachineService {

void delete_security_group_rule(1:string openstack_id) throws (1:SecurityGroupRuleNotFoundException e,2:DefaultException f)

void remove_security_groups_from_server(1:string openstack_id) throws (1:SecurityGroupRuleNotFoundException e,2:OpenStackConflictException f)


/**
* Delete server.
Expand Down Expand Up @@ -496,12 +507,13 @@ service VirtualMachineService {

7:list<map<string,string>> volume_ids_path_new,
8:list<map<string,string>> volume_ids_path_attach,
9:list <string> additional_keys,
10:optional string research_environment
11:optional list<string> additional_security_group_ids,
12:optional string slurm_version,
13:optional string metadata_token,
14:optional string metadata_endpoint
9:list <string> additional_owner_keys,
10:list <string> additional_user_keys,
11:optional string research_environment
12:optional list<string> additional_security_group_ids,
13:optional string slurm_version,
14:optional string metadata_token,
15:optional string metadata_endpoint

)

Expand Down Expand Up @@ -535,9 +547,10 @@ service VirtualMachineService {
7:list<map<string,string>> volume_ids_path_new,
8:list<map<string,string>> volume_ids_path_attach,
9:optional list<string> additional_security_group_ids,
10:optional list<string> additional_keys,
11:optional string metadata_token,
12:optional string metadata_endpoint,
10:list <string> additional_owner_keys,
11:list <string> additional_user_keys,
12:optional string metadata_token,
13:optional string metadata_endpoint,



Expand Down Expand Up @@ -669,14 +682,16 @@ service VirtualMachineService {
VM get_server(

/** Id of the server.*/
1:string openstack_id)
1:string openstack_id,
2:optional bool no_connection)

throws (1:ServerNotFoundException e),

VM get_server_by_unique_name(

/** Id of the server.*/
1:string unique_name)
1:string unique_name,
2:optional bool no_connection)

throws (1:ServerNotFoundException e),

Expand Down
36 changes: 28 additions & 8 deletions simple_vm_client/VirtualMachineHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,20 @@ def set_server_metadata(self, openstack_id: str, metadata: dict[str, str]):
openstack_id=openstack_id, metadata=metadata
)

def get_server_by_unique_name(self, unique_name: str) -> VM:
def get_server_by_unique_name(
self, unique_name: str, no_connection: bool = False
) -> VM:
server = self.openstack_connector.get_server_by_unique_name(
unique_name=unique_name
unique_name=unique_name, no_connection=no_connection
)
server = self.forc_connector.get_playbook_status(server=server)
server = thrift_converter.os_to_thrift_server(openstack_server=server)
return server

def get_server(self, openstack_id: str) -> VM:
server = self.openstack_connector.get_server(openstack_id=openstack_id)
def get_server(self, openstack_id: str, no_connection: bool = False) -> VM:
server = self.openstack_connector.get_server(
openstack_id=openstack_id, no_connection=no_connection
)
server = self.forc_connector.get_playbook_status(server=server)
server = thrift_converter.os_to_thrift_server(openstack_server=server)
return server
Expand Down Expand Up @@ -346,6 +350,11 @@ def delete_security_group_rule(self, openstack_id):
openstack_id=openstack_id
)

def remove_security_groups_from_server(self, openstack_id):
return self.openstack_connector.remove_security_groups_from_server(
openstack_id=openstack_id
)

def add_default_security_groups_to_server(self, openstack_id):
return self.openstack_connector.add_default_security_groups_to_server(
openstack_id=openstack_id
Expand Down Expand Up @@ -374,6 +383,13 @@ def add_research_environment_security_group(
server_id=server_id, security_group_name=security_group_name
)

def add_project_security_group_to_server(
self, server_id: str, project_name: str, project_id: str
) -> None:
return self.openstack_connector.add_project_security_group_to_server(
server_id=server_id, project_name=project_name, project_id=project_id
)

def add_udp_security_group(self, server_id: str) -> None:
return self.openstack_connector.add_udp_security_group(server_id=server_id)

Expand All @@ -391,7 +407,8 @@ def start_server(
metadata: dict[str, str],
volume_ids_path_new: list[dict[str, str]],
volume_ids_path_attach: list[dict[str, str]],
additional_keys: list[str],
additional_owner_keys: list[str],
additional_user_keys: list[str],
research_environment: str,
additional_security_group_ids: list[str],
slurm_version: str = None,
Expand All @@ -414,7 +431,8 @@ def start_server(
metadata=metadata,
volume_ids_path_new=volume_ids_path_new,
volume_ids_path_attach=volume_ids_path_attach,
additional_keys=additional_keys,
additional_owner_keys=additional_owner_keys,
additional_user_keys=additional_user_keys,
research_environment_metadata=research_environment_metadata,
additional_security_group_ids=additional_security_group_ids,
slurm_version=slurm_version,
Expand All @@ -432,7 +450,8 @@ def start_server_with_custom_key(
volume_ids_path_new: list[dict[str, str]],
volume_ids_path_attach: list[dict[str, str]],
additional_security_group_ids: list[str],
additional_keys: list[str],
additional_owner_keys: list[str],
additional_user_keys: list[str],
metadata_token: str = None,
metadata_endpoint: str = None,
) -> str:
Expand All @@ -449,7 +468,8 @@ def start_server_with_custom_key(
image_name=image_name,
servername=servername,
metadata=metadata,
additional_keys=additional_keys,
additional_owner_keys=additional_owner_keys,
additional_user_keys=additional_user_keys,
research_environment_metadata=research_environment_metadata,
volume_ids_path_new=volume_ids_path_new,
volume_ids_path_attach=volume_ids_path_attach,
Expand Down
62 changes: 46 additions & 16 deletions simple_vm_client/VirtualMachineService-remote
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ if len(sys.argv) <= 1 or sys.argv[1] == "--help":
print(
" void add_research_environment_security_group(string server_id, string security_group_name)"
)
print(
" void add_project_security_group_to_server(string server_id, string project_name, string project_id)"
)
print(" void add_metadata_to_server(string openstack_id, metadata)")
print(" get_flavors()")
print(" get_images()")
Expand All @@ -51,18 +54,19 @@ if len(sys.argv) <= 1 or sys.argv[1] == "--help":
" string open_port_range_for_vm_in_project(int range_start, int range_stop, string openstack_id, string ethertype, string protocol)"
)
print(" void delete_security_group_rule(string openstack_id)")
print(" void remove_security_groups_from_server(string openstack_id)")
print(" void delete_server(string openstack_id)")
print(
" void rescue_server(string openstack_id, string admin_pass, string image_ref)"
)
print(" void unrescue_server(string openstack_id)")
print(
" string start_server(string flavor_name, string image_name, string public_key, string servername, metadata, volume_ids_path_new, volume_ids_path_attach, additional_keys, string research_environment, additional_security_group_ids, string slurm_version, string metadata_token, string metadata_endpoint)"
" string start_server(string flavor_name, string image_name, string public_key, string servername, metadata, volume_ids_path_new, volume_ids_path_attach, additional_owner_keys, additional_user_keys, string research_environment, additional_security_group_ids, string slurm_version, string metadata_token, string metadata_endpoint)"
)
print(" bool is_bibigrid_available()")
print(" void detach_ip_from_server(string server_id, string floating_ip)")
print(
" string start_server_with_custom_key(string flavor_name, string image_name, string servername, metadata, string research_environment, volume_ids_path_new, volume_ids_path_attach, additional_security_group_ids, additional_keys, string metadata_token, string metadata_endpoint)"
" string start_server_with_custom_key(string flavor_name, string image_name, string servername, metadata, string research_environment, volume_ids_path_new, volume_ids_path_attach, additional_security_group_ids, additional_owner_keys, additional_user_keys, string metadata_token, string metadata_endpoint)"
)
print(" bool exist_server(string name)")
print(
Expand Down Expand Up @@ -103,8 +107,8 @@ if len(sys.argv) <= 1 or sys.argv[1] == "--help":
print(" string get_keypair_public_key_by_name(string key_name)")
print(" void delete_keypair(string key_name)")
print(" void add_default_security_groups_to_server(string openstack_id)")
print(" VM get_server(string openstack_id)")
print(" VM get_server_by_unique_name(string unique_name)")
print(" VM get_server(string openstack_id, bool no_connection)")
print(" VM get_server_by_unique_name(string unique_name, bool no_connection)")
print(" void stop_server(string openstack_id)")
print(
" string create_snapshot(string openstack_id, string name, string username, base_tags, string description)"
Expand Down Expand Up @@ -289,6 +293,18 @@ elif cmd == "add_research_environment_security_group":
)
)

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

elif cmd == "add_metadata_to_server":
if len(args) != 2:
print("add_metadata_to_server requires 2 args")
Expand Down Expand Up @@ -390,6 +406,16 @@ elif cmd == "delete_security_group_rule":
)
)

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

elif cmd == "delete_server":
if len(args) != 1:
print("delete_server requires 1 args")
Expand Down Expand Up @@ -423,8 +449,8 @@ elif cmd == "unrescue_server":
)

elif cmd == "start_server":
if len(args) != 13:
print("start_server requires 13 args")
if len(args) != 14:
print("start_server requires 14 args")
sys.exit(1)
pp.pprint(
client.start_server(
Expand All @@ -436,11 +462,12 @@ elif cmd == "start_server":
eval(args[5]),
eval(args[6]),
eval(args[7]),
args[8],
eval(args[9]),
args[10],
eval(args[8]),
args[9],
eval(args[10]),
args[11],
args[12],
args[13],
)
)

Expand All @@ -462,8 +489,8 @@ elif cmd == "detach_ip_from_server":
)

elif cmd == "start_server_with_custom_key":
if len(args) != 11:
print("start_server_with_custom_key requires 11 args")
if len(args) != 12:
print("start_server_with_custom_key requires 12 args")
sys.exit(1)
pp.pprint(
client.start_server_with_custom_key(
Expand All @@ -476,8 +503,9 @@ elif cmd == "start_server_with_custom_key":
eval(args[6]),
eval(args[7]),
eval(args[8]),
args[9],
eval(args[9]),
args[10],
args[11],
)
)

Expand Down Expand Up @@ -774,22 +802,24 @@ elif cmd == "add_default_security_groups_to_server":
)

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

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

Expand Down
Loading

0 comments on commit 494c362

Please sign in to comment.