Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tanzu component create in service creation #38

Merged
merged 1 commit into from
Dec 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/spring-cloud/azext_spring_cloud/_enterprise.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
from .vendored_sdks.appplatform.v2022_01_01_preview import models
from ._utils import get_azure_files_info, _pack_source_code
from ._build_service import _update_default_build_agent_pool
from ._tanzu_component import (create_application_configuration_service,
create_service_registry,
create_gateway,
create_api_portal)
from .custom import (app_get, _create_service)
from azure.cli.core.commands.client_factory import get_subscription_id
from azure.cli.core.util import sdk_no_wait
Expand Down Expand Up @@ -37,6 +41,8 @@ def spring_cloud_create(cmd, client, resource_group, name, location=None,
service_runtime_network_resource_group=None, app_network_resource_group=None,
app_insights_key=None, app_insights=None, sampling_rate=None,
disable_app_insights=None, enable_java_agent=None,
enable_application_configuration_service=None, enable_service_registry=None,
enable_gateway=None, enable_api_portal=None,
sku=None, tags=None, build_pool_size=None, no_wait=False):
poller = _create_service(cmd, client, resource_group, name,
location=location,
Expand All @@ -48,6 +54,10 @@ def spring_cloud_create(cmd, client, resource_group, name, location=None,
sku=sku,
tags=tags)
_update_default_build_agent_pool(cmd, client, resource_group, name, build_pool_size)
create_application_configuration_service(cmd, client, resource_group, name, enable_application_configuration_service)
create_service_registry(cmd, client, resource_group, name, enable_service_registry)
create_gateway(cmd, client, resource_group, name, enable_gateway)
create_api_portal(cmd, client, resource_group, name, enable_api_portal)
return poller


Expand Down
20 changes: 20 additions & 0 deletions src/spring-cloud/azext_spring_cloud/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,26 @@ def load_arguments(self, _):
default='S1',
is_preview=True,
help='Only support in enterprise tier now. Size of build agent pool.')
c.argument('enable_application_configuration_service',
arg_type=get_three_state_flag(),
default=False,
is_preview=True,
help='Only support in enterprise tier now. Enable Application Configuration Service.')
c.argument('enable_service_registry',
arg_type=get_three_state_flag(),
default=False,
is_preview=True,
help='Only support in enterprise tier now. Enable Service Registry.')
c.argument('enable_gateway',
arg_type=get_three_state_flag(),
default=False,
is_preview=True,
help='Only support in enterprise tier now. Enable Spring Cloud Gateway.')
c.argument('enable_api_portal',
arg_type=get_three_state_flag(),
default=False,
is_preview=True,
help='Only support in enterprise tier now. Enable API portal.')

with self.argument_context('spring-cloud update') as c:
c.argument('sku', arg_type=get_enum_type(['Basic', 'Standard', 'Enterprise']), validator=validate_sku, help='Name of SKU.')
Expand Down
55 changes: 55 additions & 0 deletions src/spring-cloud/azext_spring_cloud/_tanzu_component.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

# pylint: disable=too-few-public-methods, unused-argument, redefined-builtin

from .vendored_sdks.appplatform.v2022_01_01_preview import models
from azure.cli.core.commands.client_factory import get_subscription_id
from msrestazure.tools import resource_id
from knack.log import get_logger

GATEWAY_RESOURCE_TYPE = "gateways"
DEFAULT_NAME = "default"
logger = get_logger(__name__)

def create_application_configuration_service(cmd, client, resource_group, service, enable_application_configuration_service=None):
if enable_application_configuration_service:
logger.warning(" - Creating Application Configuration Service ..")
acs_resource = models.ConfigurationServiceResource()
client.configuration_services.begin_create_or_update(resource_group, service, DEFAULT_NAME, acs_resource)


def create_service_registry(cmd, client, resource_group, service, enable_service_registry):
if enable_service_registry:
logger.warning(" - Creating Service Registry ..")
client.service_registries.begin_create_or_update(resource_group, service, DEFAULT_NAME)


def create_gateway(cmd, client, resource_group, service, enable_gateway):
if enable_gateway:
logger.warning(" - Creating Spring Cloud Gateway ..")
gateway_resource = models.GatewayResource()
client.gateways.begin_create_or_update(resource_group, service, DEFAULT_NAME, gateway_resource)


def create_api_portal(cmd, client, resource_group, service, enable_api_portal):
if enable_api_portal:
logger.warning(" - Creating API portal ..")
gateway_id = resource_id(
subscription=get_subscription_id(cmd.cli_ctx),
resource_group=resource_group,
namespace='Microsoft.AppPlatform',
type='Spring',
name=service,
child_type_1=GATEWAY_RESOURCE_TYPE,
child_name_1=DEFAULT_NAME
)

api_portal_resource = models.GatewayResource(
properties = models.GatewayProperties(
gateway_ids=[gateway_id]
)
)
client.api_portals.begin_create_or_update(resource_group, service, DEFAULT_NAME, api_portal_resource)
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ def spring_cloud_create(cmd, client, resource_group, name,
sampling_rate=None,
disable_app_insights=None,
enable_java_agent=None,
enable_application_configuration_service=None,
enable_service_registry=None,
enable_gateway=None,
enable_api_portal=None,
sku=None,
tags=None,
build_pool_size=None,
Expand All @@ -44,6 +48,10 @@ def spring_cloud_create(cmd, client, resource_group, name,
sampling_rate=sampling_rate,
disable_app_insights=disable_app_insights,
enable_java_agent=enable_java_agent,
enable_application_configuration_service=enable_application_configuration_service,
enable_service_registry=enable_service_registry,
enable_gateway=enable_gateway,
enable_api_portal=enable_api_portal,
sku=sku,
tags=tags,
build_pool_size=build_pool_size,
Expand Down