Skip to content

Commit

Permalink
[fix] corrected known_hosts considerations in gce.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Wilson committed Apr 14, 2019
1 parent 6de024f commit 0c0d605
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions nixops/backends/gce.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,12 @@ def create(self, defn, check, allow_reboot, allow_recreate):
node.public_ips[0] if node.public_ips else None,
property_name = 'public IP address')

if self.public_ipv4:
known_hosts.add(self.public_ipv4, self.public_host_key)

self.handle_changed_property('private_ipv4',
node.private_ips[0] if node.private_ips else None,
property_name = 'private IP address')

known_hosts.add(self.get_ssh_name(), self.public_host_key)

if self.ipAddress:
try:
address = self.connect().ex_get_address(self.ipAddress)
Expand Down Expand Up @@ -449,10 +448,10 @@ def create_node(self, defn):
if self.associate_public_ip_address:
self.public_ipv4 = node.public_ips[0]
self.log("got public IP: {0}".format(self.public_ipv4))
known_hosts.add(self.public_ipv4, self.public_host_key)
self.private_ipv4 = node.private_ips[0]
if not self.associate_public_ip_address:
self.log("got private IP: {0}".format(self.private_ipv4))
known_hosts.add(self.get_ssh_name(), self.public_host_key)
for k,v in self.block_device_mapping.iteritems():
v['needsAttach'] = True
self.update_block_device_mapping(k, v)
Expand Down Expand Up @@ -567,7 +566,7 @@ def create_node(self, defn):
self.ipAddress = defn.ipAddress
self.public_ipv4 = self.node().public_ips[0]
self.log("got public IP: {0}".format(self.public_ipv4))
known_hosts.add(self.public_ipv4, self.public_host_key)
known_hosts.add(self.get_ssh_name(), self.public_host_key)
self.ssh.reset()
self.ssh_pinged = False

Expand Down Expand Up @@ -606,8 +605,8 @@ def start(self):
self.connect().ex_start_node(node)
if self.associate_public_ip_address:
self.public_ipv4 = self.node().public_ips[0]
known_hosts.add(self.public_ipv4, self.public_host_key)
self.private_ipv4 = self.node().private_ips[0]
known_hosts.add(self.get_ssh_name())
self.wait_for_ssh(check=True)
self.send_keys()

Expand Down Expand Up @@ -669,8 +668,7 @@ def destroy(self, wipe=False):
if not self.depl.logger.confirm(question.format(self.full_name)):
return False

if self.associate_public_ip_address:
known_hosts.remove(self.public_ipv4, self.public_host_key)
known_hosts.remove(self.get_ssh_name(), self.public_host_key)
self.log("destroying the GCE machine...")
node.destroy()

Expand Down Expand Up @@ -751,8 +749,7 @@ def _check(self, res):
self.handle_changed_property('public_ipv4',
node.public_ips[0] if node.public_ips else None,
property_name = 'public IP address')
if self.public_ipv4:
known_hosts.add(self.public_ipv4, self.public_host_key)
known_hosts.add(self.get_ssh_name(), self.public_host_key)

self.handle_changed_property('private_ipv4',
node.private_ips[0] if node.private_ips else None,
Expand Down

0 comments on commit 0c0d605

Please sign in to comment.