Skip to content

Commit 8450b2e

Browse files
committed
if there is only one machine, then naming machines with a sequence number 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
1 parent 82e8e64 commit 8450b2e

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

harbor_wave.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -544,11 +544,11 @@ def update_subdomain(loaded_config,hostname,ip_address):
544544
api_key = loaded_config['api-key']
545545
domain_name = loaded_config['domain']
546546
domain_obj = digitalocean.Domain(token=api_key, name=domain_name)
547-
hostname = hostname.rstrip(domain_name)
548547

549548
# Get the DO identifier for the record.
550549
entry_id = None
551550
domain_entries = domain_obj.get_records()
551+
552552
for item in domain_entries:
553553
if item.name == hostname:
554554
entry_id = item.id
@@ -563,8 +563,7 @@ def remove_subdomain(loaded_config,hostname):
563563
api_key = loaded_config['api-key']
564564
domain_name = loaded_config['domain']
565565
domain_obj = digitalocean.Domain(token=api_key, name=domain_name)
566-
hostname = hostname.rstrip(domain_name)
567-
566+
hostname = hostname.split(".")[0]
568567
entry_id = None
569568
domain_entries = domain_obj.get_records()
570569
for item in domain_entries:
@@ -632,7 +631,13 @@ def spawn_machines(loaded_config,N=1):
632631
"payload-filename":meta_filename,
633632
}
634633
user_meta = json.dumps(user_meta,indent=2)
635-
vm_name = loaded_config['base-name'] + str(i)
634+
# If there is only one machine in sequence, then don't add a number
635+
# This is so you can use some whacky vhosts
636+
if N == 1:
637+
vm_name = loaded_config['base-name']
638+
else:
639+
vm_name = loaded_config['base-name'] + str(i)
640+
636641
if loaded_config['use-dns'] == True:
637642
vm_name += "." + loaded_config['domain']
638643
msg_line = vm_name + " created"
@@ -754,19 +759,21 @@ def destroy_machines(loaded_config,args=[]):
754759
submsg(item.name + " destroyed")
755760
except:
756761
warn("Could not destroy" + item.name)
757-
fails+=1
762+
fails += 1
758763
else:
759764
if loaded_config['use-dns'] == True:
760765
submsg("[+]-Removing DNS")
761766
try:
762767
remove_subdomain(loaded_config,item.name)
763768
except digitalocean.NotFoundError:
764769
warn("No DNS for entry:" + item.name)
770+
fails += 1
765771
except:
766772
warn("Could not remove DNS entry for " + item.name)
773+
fails += 1
767774

768775
if fails >= 1:
769-
message("Done, but with " + fails + " failures")
776+
message("Done, but with " + str(fails) + " failures")
770777
sys.exit(1)
771778
else:
772779
message("Done")

0 commit comments

Comments
 (0)