Skip to content

Commit

Permalink
create default org if it doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
Lorquas committed Jan 29, 2025
1 parent 0554612 commit 09a3ab4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
9 changes: 4 additions & 5 deletions virtwho/provision/virtwho_satellite.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@ def satellite_deploy_for_virtwho(args):
default_org = config.satellite.default_org
if not default_org:
default_org = "Default_Organization"
satellite.sca(org=None)
else:
satellite.org_create(name=default_org, label=default_org)
satellite.sca(org=default_org)
# satellite.sca(org=None)
# else:
# satellite.sca(org=default_org)

satellite_manifest_upload(
org=default_org,
Expand All @@ -67,7 +66,7 @@ def satellite_deploy_for_virtwho(args):
second_org = config.satellite.secondary_org
if second_org:
satellite.org_create(name=second_org, label=second_org)
satellite.sca(org=second_org)
# satellite.sca(org=second_org)
satellite_manifest_upload(
org=second_org,
ssh=ssh_satellite,
Expand Down
14 changes: 12 additions & 2 deletions virtwho/register.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import requests

from json.decoder import JSONDecodeError
from virtwho import logger, FailException
from virtwho.configure import get_register_handler
from virtwho.ssh import SSHConnect
Expand Down Expand Up @@ -286,7 +287,12 @@ def __init__(self, server=None, org=None, activation_key=None):
host=self.server, user=register.ssh_username, pwd=register.ssh_password
)
self.hammer = "hammer --output=json"
self.org_id = self.organization_id()
try:
# import ipdb; ipdb.set_trace()
self.org_id = self.organization_id()
except FailException: #retry by creating org first
self.org_create(name=self.org, label=self.org)
self.org_id = self.organization_id()
self.api = f"https://{self.server}"
self.auth = (register.username, register.password)

Expand All @@ -301,7 +307,11 @@ def organization_id(self, org=None):
ret, output = self.ssh.runcmd(
f'{self.hammer} organization info --label "{org}" --fields Id'
)
output = json.loads(output)
try:
output = json.loads(output)
except JSONDecodeError:
raise FailException(f"Failed to get the organization id for {org}")

if ret == 0 and output:
return output["Id"]
raise FailException(f"Failed to get the organization id for {org}")
Expand Down

0 comments on commit 09a3ab4

Please sign in to comment.