Exemple #1
0
def remove_cloud(cloud_name):
    from azure.cli.core.context import get_contexts
    if not _get_cloud(cloud_name):
        raise CloudNotRegisteredException(cloud_name)
    is_known_cloud = next((x for x in KNOWN_CLOUDS if x.name == cloud_name), None)
    if is_known_cloud:
        raise CannotUnregisterCloudException("The cloud '{}' cannot be unregistered as it's not a custom cloud.".format(cloud_name)) #pylint: disable=line-too-long
    contexts_using_cloud = [context for context in get_contexts() if context.get('cloud', None) == cloud_name] #pylint: disable=line-too-long
    if contexts_using_cloud:
        context_names = [context['name'] for context in contexts_using_cloud]
        many_contexts = len(context_names) > 1
        raise CannotUnregisterCloudException("The cloud '{0}' is in use by the following context{1} '{2}'.".format( #pylint: disable=line-too-long
            cloud_name,
            's' if many_contexts else '',
            ', '.join(context_names)))
    config = configparser.SafeConfigParser()
    config.read(CUSTOM_CLOUD_CONFIG_FILE)
    config.remove_section(cloud_name)
    with open(CUSTOM_CLOUD_CONFIG_FILE, 'w') as configfile:
        config.write(configfile)
Exemple #2
0
def list_contexts():
    return ctx.get_contexts()
Exemple #3
0
def get_context_completion_list(prefix, action, parsed_args, **kwargs):  #pylint: disable=unused-argument
    return [c['name'] for c in get_contexts()]
Exemple #4
0
def get_context_completion_list(prefix, action, parsed_args, **kwargs):#pylint: disable=unused-argument
    return [c['name'] for c in get_contexts()]
Exemple #5
0
def list_contexts():
    return ctx.get_contexts()