Skip to content

Commit

Permalink
Merge pull request NixOS#364 from @basvandijk.
Browse files Browse the repository at this point in the history
Also closes NixOS#361.

This makes sure that machines that are already deployed using the "none"
backend get the right public key before even attempting to connect
blindly.

To make sure this works even with new deployments, I successfully ran
the VM test for the "none" backend.
  • Loading branch information
aszlig committed Dec 8, 2015
2 parents 8f61177 + 8d7a4bf commit 98d40e3
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion nixops/backends/none.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def get_type(cls):
target_host = nixops.util.attr_property("targetHost", None)
_ssh_private_key = attr_property("none.sshPrivateKey", None)
_ssh_public_key = attr_property("none.sshPublicKey", None)
_ssh_public_key_deployed = attr_property("none.sshPublicKeyDeployed", False, type = bool)

def __init__(self, depl, name, id):
MachineState.__init__(self, depl, name, id)
Expand Down Expand Up @@ -56,6 +57,12 @@ def create(self, defn, check, allow_reboot, allow_recreate):
self.log_end("done.")
self.vm_id = "nixops-{0}-{1}".format(self.depl.uuid, self.name)

def switch_to_configuration(self, method, sync, command=None):
res = super(NoneState, self).switch_to_configuration(method, sync, command)
if res == 0:
self._ssh_public_key_deployed = True
return res

def get_ssh_name(self):
assert self.target_host
return self.target_host
Expand All @@ -68,7 +75,7 @@ def get_ssh_private_key_file(self):

def get_ssh_flags(self):
super_state_flags = super(NoneState, self).get_ssh_flags()
if self.vm_id and self.cur_toplevel:
if self.vm_id and self.cur_toplevel and self._ssh_public_key_deployed:
return super_state_flags + ["-o", "StrictHostKeyChecking=no", "-i", self.get_ssh_private_key_file()]
return super_state_flags

Expand Down

0 comments on commit 98d40e3

Please sign in to comment.