예제 #1
0
def get_container_registry_service_connection(organization, project):
    import subprocess
    import json
    subscription_id, subscription_name, tenant_id, _environment_name = get_default_subscription_info(
    )
    logger.warning(
        "Using your default Azure subscription %s for fetching Azure Container Registries.",
        subscription_name)
    acr_list = subprocess.check_output('az acr list -o json', shell=True)
    acr_list = json.loads(acr_list)
    if acr_list:
        registry_choice = 0
        registry_choice_list = []
        for acr_clusters in acr_list:
            registry_choice_list.append(acr_clusters['name'])
        registry_choice = prompt_user_friendly_choice_list(
            "Which Azure Container Registry do you want to use for this pipeline?",
            registry_choice_list)
        selected_registry = acr_list[registry_choice]
        cix_client = get_new_cix_client(organization=organization)
        acr_connection_obj = get_container_registry_connection_create_object(
            subscription_id, subscription_name, tenant_id,
            selected_registry['id'], selected_registry['name'],
            selected_registry['loginServer'])
        acr_container_resource = cix_client.create_resources(
            creation_parameters=acr_connection_obj, project=project)
        poll_connection_ready(
            organization, project,
            acr_container_resource.resources['containerRegistryConnection']
            ['Id'])
        return acr_container_resource.resources['containerRegistryConnection']
    raise CLIError(
        'There is no Azure container registry associated with your subscription. '
        'Create an ACR or switch to another subscription, '
        'verify with command \'az acr list\' and try again.')
예제 #2
0
def get_azure_rm_service_connection(organization, project):
    logger.debug('Create a new Azure Resource Manager service connection')
    subscription_id, subscription_name, tenant_id, environment_name = get_default_subscription_info(
    )
    logger.warning(
        "Using your default Azure subscription %s for creating Azure RM connection.",
        subscription_name)
    cix_client = get_new_cix_client(organization=organization)
    azure_rm_connection_create_obj = get_azure_rm_connection_create_object(
        subscription_id, subscription_name, environment_name, tenant_id)
    azure_rm_connection = cix_client.create_resources(
        creation_parameters=azure_rm_connection_create_obj, project=project)
    azure_rm_connection_obj = azure_rm_connection.resources[
        'azureRmConnection']
    poll_connection_ready(organization, project, azure_rm_connection_obj['Id'])
    return azure_rm_connection_obj
예제 #3
0
def get_kubernetes_environment_resource(organization, project, repo_name):
    logger.debug("Creating a new k8s environment resource.")
    import subprocess
    import json
    subscription_id, subscription_name, tenant_id, environment_name = get_default_subscription_info(
    )
    logger.warning(
        "Using your default Azure subscription %s for fetching AKS clusters.",
        subscription_name)
    aks_list = subprocess.check_output('az aks list -o json', shell=True)
    aks_list = json.loads(aks_list)
    if aks_list:
        cluster_choice = 0
        cluster_choice_list = []
        for aks_clusters in aks_list:
            cluster_choice_list.append(aks_clusters['name'])
        cluster_choice = prompt_user_friendly_choice_list(
            "Which kubernetes cluster do you want to target for this pipeline?",
            cluster_choice_list)
        selected_cluster = aks_list[cluster_choice]
        create_namespace, namespace = get_kubernetes_namespace(
            organization, project, selected_cluster, subscription_id,
            subscription_name, tenant_id, environment_name)
        kubernetes_connection_obj = get_kubernetes_connection_create_object(
            subscription_id, subscription_name, selected_cluster['id'],
            selected_cluster['name'], selected_cluster['fqdn'], tenant_id,
            namespace, create_namespace, environment_name)
        cix_client = get_new_cix_client(organization=organization)
        kubernetes_connection = cix_client.create_resources(
            creation_parameters=kubernetes_connection_obj, project=project)
        k8s_connection_obj = kubernetes_connection.resources['k8sConnection']
        poll_connection_ready(organization, project, k8s_connection_obj['Id'])
        kubernetes_env_obj = get_kubernetes_resource_create_object(
            k8s_connection_obj['Name'], selected_cluster['name'], repo_name,
            k8s_connection_obj['Id'], namespace)
        kubernetes_environment_resource = cix_client.create_resources(
            creation_parameters=kubernetes_env_obj, project=project)
        return kubernetes_environment_resource.resources['k8sResource']
    raise CLIError(
        'There are no AKS clusters under your subscription. '
        'Create the clusters or switch to another subscription, verify with '
        'command \'az aks list\' and try again.')
예제 #4
0
def get_webapp_from_list_selection():
    logger.debug("Fetching web app list to display")
    import subprocess
    import json
    _subscription_id, subscription_name, _tenant_id, _environment_name = get_default_subscription_info(
    )
    logger.warning(
        "Using your default Azure subscription %s for fetching Web App list.",
        subscription_name)
    webapp_list = subprocess.check_output('az webapp list -o json', shell=True)
    webapp_list = json.loads(webapp_list)
    if webapp_list:
        app_choice = 0
        app_choice_list = []
        for webapp in webapp_list:
            app_choice_list.append(webapp['name'])
        app_choice = prompt_user_friendly_choice_list(
            "Which Web App do you want to target?", app_choice_list)
        return webapp_list[app_choice]['name']
    raise CLIError(
        'There are no Web apps in this subscription. Either create a Web App using this subscription '
        'or change to another subscription. Verify with command \'az webapp list\'.'
    )