Skip to content

Commit

Permalink
done
Browse files Browse the repository at this point in the history
  • Loading branch information
dweinholz committed Jan 4, 2024
1 parent 4b7eb24 commit a84a3df
Show file tree
Hide file tree
Showing 4 changed files with 591 additions and 92 deletions.
4 changes: 4 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ omit =
simple_vm_client/ttypes.py
simple_vm_client/forc_connector/template/test_templates.py
simple_vm_client/util/logger.py
simple_vm_client/forc_connector/test_forc_connector.py
simple_vm_client/VirtualMachineServer.py

check_env.py

[report]
exclude_lines =
Expand Down
11 changes: 0 additions & 11 deletions simple_vm_client/VirtualMachineServer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
import signal
import ssl
import sys
Expand Down Expand Up @@ -73,15 +72,5 @@ def catch_shutdown(signal: int, frame: object) -> None:
server.serve()


def check_environment_variables(envs: list[str]) -> None:
def check_env(var: str) -> None:
if var not in os.environ:
click.echo(f"ERROR: There is no {var} set in environment.")
click.echo("Please make sure you have sourced your OpenStack rc file")
sys.exit()

list(map(lambda var: check_env(var), envs))


if __name__ == "__main__":
startServer()
42 changes: 20 additions & 22 deletions simple_vm_client/forc_connector/forc_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,12 @@ def delete_backend(self, backend_id: str) -> None:
if response.status_code:
if response.status_code == 404 or response.status_code == 500:
try:
response_data = response.json()
raise BackendNotFoundException(
message=str(json.dumps(response.json())),
message=str(json.dumps(response_data)),
name_or_id=str(backend_id),
)
except json.JSONDecodeError:
except ValueError:
logger.exception(str(response.content))
raise BackendNotFoundException(
message=str(response.content), name_or_id=str(backend_id)
Expand All @@ -146,14 +147,11 @@ def delete_backend(self, backend_id: str) -> None:

def add_user_to_backend(self, backend_id: str, user_id: str) -> dict[str, str]:
logger.info(f"Add User {user_id} to backend {backend_id}")
try:
post_url = f"{self.FORC_URL}users/{backend_id}"
user_info = {
"user": user_id,
}
except Exception as e:
logger.exception(e)
return {"Error": "Could not create url or json body."}
post_url = f"{self.FORC_URL}users/{backend_id}"
user_info = {
"user": user_id,
}

try:
response = requests.post(
post_url,
Expand All @@ -177,7 +175,9 @@ def add_user_to_backend(self, backend_id: str, user_id: str) -> dict[str, str]:
logger.exception(e)
raise BackendNotFoundException(message=str(e), name_or_id=backend_id)

def create_backend(self, owner: str, user_key_url: str, template: str, upstream_url: str) -> Backend:
def create_backend(
self, owner: str, user_key_url: str, template: str, upstream_url: str
) -> Backend:
logger.info(
f"Create Backend - [Owner:{owner}, user_key_url:{user_key_url}, template:{template}, upstream_url:{upstream_url}"
)
Expand Down Expand Up @@ -362,19 +362,17 @@ def load_env(self) -> None:
logger.info("Load env: FORC")
self.FORC_API_KEY = os.environ.get("FORC_API_KEY", None)

def get_playbook_logs(self, openstack_id: str) -> PlaybookResult:
logger.warning(f"Get Playbook logs {openstack_id}")
if (
def is_playbook_active(self, openstack_id: str) -> bool:
return (
self.redis_connection.exists(openstack_id) == 1
and openstack_id in self._active_playbooks
):
playbook = self._active_playbooks.get(openstack_id)
logger.warning(f"playbook {playbook}")
if not playbook:
raise PlaybookNotFoundException(
message=f"No active Playbook found for {openstack_id}!",
name_or_id=openstack_id,
)
)

def get_playbook_logs(self, openstack_id: str) -> PlaybookResult:
logger.warning(f"Get Playbook logs {openstack_id}")

if self.is_playbook_active(openstack_id):
playbook = self._active_playbooks[openstack_id]
status, stdout, stderr = playbook.get_logs()
logger.warning(f" Playbook logs {openstack_id} status: {status}")

Expand Down
Loading

0 comments on commit a84a3df

Please sign in to comment.