Skip to content

Commit

Permalink
merge dev into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
dweinholz committed Sep 11, 2024
2 parents 3b39a2b + 5b631b4 commit 90cf71b
Show file tree
Hide file tree
Showing 20 changed files with 11,692 additions and 3,761 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.12.5
FROM python:3.12.6
RUN echo "deb https://deb.debian.org/debian/ stable main" > /etc/apt/sources.list
RUN apt-get update -y \
&& apt-get install -y build-essential python3-openstackclient vim\
Expand Down
22 changes: 22 additions & 0 deletions portal_client.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ typedef i32 int
/** The Version of the Portal-Client*/
const string VERSION= '1.0.0'


struct VirtualMachineServerMetadata {
1: list<string> public_keys
2: string hashed_auth_token
3: string ip
}
struct Backend {
1: i64 id,
2: string owner,
Expand Down Expand Up @@ -210,6 +216,13 @@ struct PlaybookResult {
3: required string stderr
}

exception MetadataServerNotAvailableException {
1: string message
}
exception MetadataServerNotAllowedException{
1: string message
}

exception ResourceNotFoundException {
/** Name already used. */
1: string message
Expand Down Expand Up @@ -452,6 +465,7 @@ service VirtualMachineService {
10:optional string research_environment
11:optional list<string> additional_security_group_ids,
12:optional string slurm_version,
13:optional string metadata_token,

)

Expand Down Expand Up @@ -485,6 +499,8 @@ 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 string metadata_token,

) throws (1:NameAlreadyUsedException e,2:ResourceNotAvailableException r,3: ImageNotFoundException i,4: FlavorNotFoundException f,5:DefaultException d)

/** Check if there is an instance with name */
Expand Down Expand Up @@ -542,6 +558,9 @@ service VirtualMachineService {
) throws (1:BackendNotFoundException b,2:DefaultException d)


void set_metadata_server_data(1:string ip,2:VirtualMachineServerMetadata metadata) throws (1:MetadataServerNotAvailableException m,2:MetadataServerNotAllowedException b)
void remove_metadata_server_data(1:string ip) throws (1:MetadataServerNotAvailableException m,2:MetadataServerNotAllowedException b)
void is_metadata_server_available() throws (1:MetadataServerNotAvailableException m,2:MetadataServerNotAllowedException b)

/** Delete a backend*/
void delete_backend(
Expand Down Expand Up @@ -825,4 +844,7 @@ service VirtualMachineService {

throws (1:ServerNotFoundException e, 2: OpenStackConflictException c)




}
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ types-PyYAML==6.0.12.20240808
sympy==1.13.2
colorama==0.4.6
gevent==24.2.1
pytest==8.3.2
pytest==8.3.3
types-redis==4.6.0.20240903
oslo.utils==7.3.0
45 changes: 45 additions & 0 deletions scripts/get_keys_from_metadata_server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash

# Load the auth token from .metadata_config.env
source ~/.metadata_config.env

# Define the URL and machine IP
URL="http://192.168.2.122:8000/metadata/192.168.2.74"
AUTH_HEADER="auth_token: ${METADATA_ACCESS_TOKEN}"

# Fetch the JSON response from the URL
response=$(curl -s -X GET "$URL" -H "$AUTH_HEADER")

# Extract the public_keys array from the JSON response
public_keys=$(echo "$response" | jq -r '.public_keys[]')

# Check if public_keys is empty
if [ -z "$public_keys" ]; then
echo "No public keys found. authorized_keys file not updated."
exit 0
fi

# Ensure the .ssh directory and authorized_keys file exist
mkdir -p ~/.ssh
touch ~/.ssh/authorized_keys

# Function to check if a key already exists in the authorized_keys file
key_exists() {
grep -Fqx "$1" ~/.ssh/authorized_keys
}

# Add keys to authorized_keys if they don't already exist
added_keys=0

while IFS= read -r key; do
if ! key_exists "$key"; then
echo "$key" >> ~/.ssh/authorized_keys
((added_keys++))
fi
done <<< "$public_keys"

if [ $added_keys -gt 0 ]; then
echo "$added_keys new public key(s) have been added to the authorized_keys file."
else
echo "All public keys were already present. No changes made to authorized_keys file."
fi
16 changes: 16 additions & 0 deletions simple_vm_client/VirtualMachineHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from simple_vm_client.util import thrift_converter
from simple_vm_client.util.logger import setup_custom_logger

from .metadata_connector.metadata_connector import MetadataConnector
from .ttypes import (
VM,
Backend,
Expand All @@ -23,6 +24,7 @@
PlaybookResult,
ResearchEnvironmentTemplate,
Snapshot,
VirtualMachineServerMetadata,
Volume,
)
from .VirtualMachineService import Iface
Expand All @@ -37,6 +39,7 @@ def __init__(self, config_file: str):
self.openstack_connector = OpenStackConnector(config_file=config_file)
self.bibigrid_connector = BibigridConnector(config_file=config_file)
self.forc_connector = ForcConnector(config_file=config_file)
self.metadata_connetor = MetadataConnector(config_file=config_file)

def keyboard_interrupt_handler_playbooks(self) -> None:
for k, v in self.forc_connector._active_playbooks.items():
Expand All @@ -50,6 +53,15 @@ def keyboard_interrupt_handler_playbooks(self) -> None:
self.openstack_connector.delete_server(openstack_id=k)
raise SystemExit(0)

def is_metadata_server_available(self):
return self.metadata_connetor.is_metadata_server_available()

def set_metadata_server_data(self, ip: str, metadata: VirtualMachineServerMetadata):
return self.metadata_connetor.set_metadata(ip=ip, metadata=metadata)

def remove_metadata_server_data(self, ip: str):
return self.metadata_connetor.remove_metadata(ip=ip)

def get_images(self) -> list[Image]:
images: list[Image] = thrift_converter.os_to_thrift_images(
openstack_images=self.openstack_connector.get_images()
Expand Down Expand Up @@ -370,6 +382,7 @@ def start_server(
research_environment: str,
additional_security_group_ids: list[str],
slurm_version: str = None,
metadata_token: str = None,
) -> str:
if research_environment:
research_environment_metadata = (
Expand All @@ -391,6 +404,7 @@ def start_server(
research_environment_metadata=research_environment_metadata,
additional_security_group_ids=additional_security_group_ids,
slurm_version=slurm_version,
metadata_token=metadata_token,
)

def start_server_with_custom_key(
Expand All @@ -403,6 +417,7 @@ 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],
metadata_token: str = None,
) -> str:
if research_environment:
research_environment_metadata = (
Expand All @@ -421,6 +436,7 @@ def start_server_with_custom_key(
volume_ids_path_new=volume_ids_path_new,
volume_ids_path_attach=volume_ids_path_attach,
additional_security_group_ids=additional_security_group_ids,
metadata_token=metadata_token,
)
self.forc_connector.set_vm_wait_for_playbook(
openstack_id=openstack_id, private_key=private_key, name=servername
Expand Down
Loading

0 comments on commit 90cf71b

Please sign in to comment.