Skip to content

Commit

Permalink
if there is only one machine, then naming machines with a sequence nu…
Browse files Browse the repository at this point in the history
…mber is omitted.

Also fixed are a few nasty errors that were only uncovered in testing this. rstrip() has been
removed from getting hostname from domains in favor of the more canonical hostname.split(".")[0]

previously, adding DNS if the DNS entry already existed would fail, and then error messages would
fail as well
  • Loading branch information
GIJack committed Apr 30, 2023
1 parent 82e8e64 commit 8450b2e
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions harbor_wave.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,11 +544,11 @@ def update_subdomain(loaded_config,hostname,ip_address):
api_key = loaded_config['api-key']
domain_name = loaded_config['domain']
domain_obj = digitalocean.Domain(token=api_key, name=domain_name)
hostname = hostname.rstrip(domain_name)

# Get the DO identifier for the record.
entry_id = None
domain_entries = domain_obj.get_records()

for item in domain_entries:
if item.name == hostname:
entry_id = item.id
Expand All @@ -563,8 +563,7 @@ def remove_subdomain(loaded_config,hostname):
api_key = loaded_config['api-key']
domain_name = loaded_config['domain']
domain_obj = digitalocean.Domain(token=api_key, name=domain_name)
hostname = hostname.rstrip(domain_name)

hostname = hostname.split(".")[0]
entry_id = None
domain_entries = domain_obj.get_records()
for item in domain_entries:
Expand Down Expand Up @@ -632,7 +631,13 @@ def spawn_machines(loaded_config,N=1):
"payload-filename":meta_filename,
}
user_meta = json.dumps(user_meta,indent=2)
vm_name = loaded_config['base-name'] + str(i)
# If there is only one machine in sequence, then don't add a number
# This is so you can use some whacky vhosts
if N == 1:
vm_name = loaded_config['base-name']
else:
vm_name = loaded_config['base-name'] + str(i)

if loaded_config['use-dns'] == True:
vm_name += "." + loaded_config['domain']
msg_line = vm_name + " created"
Expand Down Expand Up @@ -754,19 +759,21 @@ def destroy_machines(loaded_config,args=[]):
submsg(item.name + " destroyed")
except:
warn("Could not destroy" + item.name)
fails+=1
fails += 1
else:
if loaded_config['use-dns'] == True:
submsg("[+]-Removing DNS")
try:
remove_subdomain(loaded_config,item.name)
except digitalocean.NotFoundError:
warn("No DNS for entry:" + item.name)
fails += 1
except:
warn("Could not remove DNS entry for " + item.name)
fails += 1

if fails >= 1:
message("Done, but with " + fails + " failures")
message("Done, but with " + str(fails) + " failures")
sys.exit(1)
else:
message("Done")
Expand Down

0 comments on commit 8450b2e

Please sign in to comment.