~sseman/juju-ci-tools/model-change-watcher-py3-2

« back to all changes in this revision

Viewing changes to substrate.py

  • Committer: Aaron Bentley
  • Date: 2016-11-24 17:19:37 UTC
  • mto: This revision was merged to the branch mainline in revision 1761.
  • Revision ID: aaron.bentley@canonical.com-20161124171937-6wkpzoy5jzaadaao
Update substrate to use get_cloud_credentials for maas credentials.

Show diffs side-by-side

added added

removed removed

Lines of Context:
60
60
        environ.update(translate_to_env(env.config))
61
61
        command_args = ['nova', 'delete'] + instance_ids
62
62
    elif provider_type == 'maas':
63
 
        with maas_account_from_config(env.config) as substrate:
 
63
        with maas_account_from_boot_config(env) as substrate:
64
64
            substrate.terminate_instances(instance_ids)
65
65
        return
66
66
    else:
691
691
 
692
692
 
693
693
@contextmanager
694
 
def maas_account_from_config(config):
 
694
def maas_account_from_boot_config(env):
695
695
    """Create a ContextManager for either a MAASAccount or a MAAS1Account.
696
696
 
697
697
    As it's not possible to tell from the maas config which version of the api
698
698
    to use, try 2.0 and if that fails on login fallback to 1.0 instead.
699
699
    """
700
 
    args = (config['name'], config['maas-server'], config['maas-oauth'])
 
700
    maas_oauth = env.get_cloud_credentials()['maas-oauth']
 
701
    args = (env.config['name'], env.config['maas-server'], maas_oauth)
701
702
    manager = MAASAccount(*args)
702
703
    try:
703
704
        manager.login()
908
909
        # Only MAAS requires special handling at prsent.
909
910
        return
910
911
    # MAAS hostnames are not resolvable, but we can adapt them to IPs.
911
 
    with maas_account_from_config(env.config) as account:
 
912
    with maas_account_from_boot_config(env) as account:
912
913
        allocated_ips = account.get_allocated_ips()
913
914
    for remote in remote_machines:
914
915
        if remote.get_address() in allocated_ips: