def on_proxypeer_relation_changed(self, event): if self.peers.is_cluster_initialized: pubkey = self.peers.ssh_public_key privkey = self.peers.ssh_private_key SSHProxy.write_ssh_keys(public=pubkey, private=privkey) self.on_config_changed(event) else: event.defer()
def on_get_ssh_public_key_action(self, event): """Get the SSH public key for this unit.""" if self.is_leader: pubkey = SSHProxy.get_ssh_public_key() event.set_results({"pubkey": SSHProxy.get_ssh_public_key()}) else: event.fail("Unit is not leader") return
def on_install(self, event): """Called when the charm is being installed""" unit = self.model.unit if not SSHProxy.has_ssh_key(): unit.status = MaintenanceStatus("Generating SSH keys...") print("Generating SSH Keys") SSHProxy.generate_ssh_key() unit.status = ActiveStatus()
def get_ssh_proxy(self): """Get the SSHProxy instance""" proxy = SSHProxy( hostname=self.model.config["ssh-hostname"], username=self.model.config["ssh-username"], password=self.model.config["ssh-password"], ) return proxy
def on_generate_ssh_key_action(self, event): """Generate a new SSH keypair for this unit.""" if self.is_leader: if not SSHProxy.generate_ssh_key(): event.fail("Unable to generate ssh key") else: event.fail("Unit is not leader") return
def on_start(self, event): """Called when the charm is being installed""" if not self.peers.is_joined: event.defer() return unit = self.model.unit if not SSHProxy.has_ssh_key(): unit.status = MaintenanceStatus("Generating SSH keys...") pubkey = None privkey = None if self.is_leader: if self.peers.is_cluster_initialized: SSHProxy.write_ssh_keys( public=self.peers.ssh_public_key, private=self.peers.ssh_private_key, ) else: SSHProxy.generate_ssh_key() self.on.ssh_keys_initialized.emit( SSHProxy.get_ssh_public_key(), SSHProxy.get_ssh_private_key()) unit.status = ActiveStatus() else: unit.status = WaitingStatus( "Waiting for leader to populate the keys")
def on_get_ssh_public_key_action(self, event): """Get the SSH public key for this unit.""" pubkey = SSHProxy.get_ssh_public_key() event.set_results({"pubkey": SSHProxy.get_ssh_public_key()})
def on_generate_ssh_key_action(self, event): """Generate a new SSH keypair for this unit.""" if not SSHProxy.generate_ssh_key(): event.fail("Unable to generate ssh key")