+ def _create_juju_public_key(self, public_key):
+ """Recreate the Juju public key on disk.
+
+ Certain libjuju commands expect to be run from the same machine as Juju
+ is bootstrapped to. This method will write the public key to disk in
+ that location: ~/.local/share/juju/ssh/juju_id_rsa.pub
+ """
+ # Make sure that we have a public key before writing to disk
+ if public_key is None or len(public_key) == 0:
+ if 'OSM_VCA_PUBKEY' in os.environ:
+ public_key = os.getenv('OSM_VCA_PUBKEY', '')
+ if len(public_key == 0):
+ return
+ else:
+ return
+
+ path = "{}/.local/share/juju/ssh".format(
+ os.path.expanduser('~'),
+ )
+ if not os.path.exists(path):
+ os.makedirs(path)
+
+ with open('{}/juju_id_rsa.pub'.format(path), 'w') as f:
+ f.write(public_key)
+