def save_credential(self, credential): cred_path = path.join(utils.juju_path(), 'credentials.yaml') cred_name = "conjure-{}-{}".format(app.current_cloud, utils.gen_hash()) try: existing_creds = yaml.safe_load(open(cred_path)) except: existing_creds = {'credentials': {}} if app.current_cloud in existing_creds['credentials'].keys(): c = existing_creds['credentials'][app.current_cloud] c[cred_name] = self._format_creds(credential) else: # Handle the case where path exists but an entry for the cloud # has yet to be added. existing_creds['credentials'][app.current_cloud] = { cred_name: self._format_creds(credential) } with open(cred_path, 'w') as cred_f: cred_f.write( yaml.safe_dump(existing_creds, default_flow_style=False)) # if it's a new MAAS cloud, save it now that we have a credential if app.current_cloud_type == 'maas': try: juju.get_cloud(app.current_cloud) except LookupError: juju.add_cloud(app.current_cloud, credential.cloud_config()) # This should return the credential name so juju bootstrap knows # which credential to bootstrap with self.finish(cred_name)
def get_accounts(): """ List available accounts Returns: List of known accounts """ env = os.path.join(juju_path(), 'accounts.yaml') if not os.path.isfile(env): raise Exception("Unable to find: {}".format(env)) with open(env, 'r') as c: env = yaml.load(c) return env['controllers'] raise Exception("Unable to find accounts")
def read_config(name): """ Reads a juju config file Arguments: name: filename without extension (ext defaults to yaml) Returns: dictionary of yaml object """ abs_path = os.path.join(juju_path(), "{}.yaml".format(name)) if not os.path.isfile(abs_path): raise Exception("Cannot load {}".format(abs_path)) return yaml.safe_load(open(abs_path))
def get_accounts(): """ List available accounts Returns: List of known accounts """ env = os.path.join(juju_path(), 'accounts.yaml') if not os.path.isfile(env): raise Exception( "Unable to find: {}".format(env)) with open(env, 'r') as c: env = yaml.load(c) return env['controllers'] raise Exception("Unable to find accounts")
async def _save_credential(self): cred_path = path.join(utils.juju_path(), 'credentials.yaml') app.provider.credential = "conjure-{}-{}".format( app.provider.cloud, utils.gen_hash()) try: existing_creds = yaml.safe_load(open(cred_path)) except: existing_creds = {'credentials': {}} if app.provider.cloud in existing_creds['credentials'].keys(): c = existing_creds['credentials'][app.provider.cloud] c[app.provider.credential] = self._format_creds() else: # Handle the case where path exists but an entry for the cloud # has yet to be added. existing_creds['credentials'][app.provider.cloud] = { app.provider.credential: self._format_creds() } with open(cred_path, 'w') as cred_f: cred_f.write( yaml.safe_dump(existing_creds, default_flow_style=False)) # Persist input fields in current provider, this is so we # can login to the provider for things like querying VSphere # for datacenters before that custom cloud is known to juju. await app.provider.save_form() # if it's a new MAAS or VSphere cloud, save it now that # we have a credential if app.provider.cloud_type in CUSTOM_PROVIDERS: try: juju.get_cloud(app.provider.cloud) except LookupError: juju.add_cloud(app.provider.cloud, await app.provider.cloud_config()) # This should return the credential name so juju bootstrap knows # which credential to bootstrap with self.finish()
import os.path as path import yaml from conjureup import utils from conjureup.app_config import app cred_path = path.join(utils.juju_path(), 'credentials.yaml') def __format_creds(creds): """ Formats the credentials into strings from the widgets values """ formatted = {} for k, v in creds.items(): if k.startswith('_'): # Not a widget but a private key k = k[1:] formatted[k] = v elif k.startswith('@'): # A Widget, but not stored in credentials continue else: formatted[k] = v.value return formatted def try_get_creds(cloud): """ Check if credentials for existing cloud already exists so we can bypass the cloud config view and go straight to bootstrapping
import os.path as path import yaml from conjureup import utils from conjureup.app_config import app cred_path = path.join(utils.juju_path(), "credentials.yaml") def __format_creds(creds): """ Formats the credentials into strings from the widgets values """ formatted = {} for k, v in creds.items(): if k.startswith("_"): # Not a widget but a private key k = k[1:] formatted[k] = v elif k.startswith("@"): # A Widget, but not stored in credentials continue else: formatted[k] = v.value return formatted def try_get_creds(cloud): """ Check if credentials for existing cloud already exists so we can bypass the cloud config view and go straight to bootstrapping