-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Spring-Cloud] refactor spring-cloud create (#4291)
* [Spring-Cloud] refactor spring-cloud create * add more tests * group parameters * add mock reset in setup
- Loading branch information
Showing
7 changed files
with
293 additions
and
183 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 133 additions & 0 deletions
133
src/spring-cloud/azext_spring_cloud/spring_cloud_instance.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- | ||
|
||
# pylint: disable=wrong-import-order | ||
# pylint: disable=unused-argument, logging-format-interpolation, protected-access, wrong-import-order, too-many-lines | ||
from ._utils import (wait_till_end, _get_rg_location) | ||
from .vendored_sdks.appplatform.v2022_01_01_preview import models | ||
from knack.log import get_logger | ||
from .custom import (_warn_enable_java_agent, _update_application_insights_asc_create) | ||
|
||
from ._validators import (_parse_sku_name) | ||
from knack.log import get_logger | ||
|
||
logger = get_logger(__name__) | ||
|
||
|
||
class DefaultSpringCloud: | ||
def __init__(self, cmd, client, resource_group, name, location=None, **_): | ||
self.cmd = cmd | ||
self.client = client | ||
self.resource_group = resource_group | ||
self.name = name | ||
self.location = location or _get_rg_location(cmd.cli_ctx, resource_group) | ||
|
||
def create(self, **kwargs): | ||
self.before_create(**kwargs) | ||
resource = self.create_service(**kwargs) | ||
self.after_create(**kwargs) | ||
return resource | ||
|
||
def before_create(self, **kwargs): | ||
_warn_enable_java_agent(**kwargs) | ||
|
||
def after_create(self, **kwargs): | ||
_update_application_insights_asc_create(self.cmd, | ||
self.resource_group, | ||
self.name, | ||
self.location, | ||
**kwargs) | ||
|
||
def create_service(self, | ||
service_runtime_subnet=None, | ||
app_subnet=None, | ||
reserved_cidr_range=None, | ||
service_runtime_network_resource_group=None, | ||
app_network_resource_group=None, | ||
zone_redundant=False, | ||
sku=None, | ||
tags=None, | ||
**_): | ||
properties = models.ClusterResourceProperties( | ||
zone_redundant=zone_redundant | ||
) | ||
|
||
if service_runtime_subnet or app_subnet or reserved_cidr_range: | ||
properties.network_profile = models.NetworkProfile( | ||
service_runtime_subnet_id=service_runtime_subnet, | ||
app_subnet_id=app_subnet, | ||
service_cidr=reserved_cidr_range, | ||
app_network_resource_group=app_network_resource_group, | ||
service_runtime_network_resource_group=service_runtime_network_resource_group | ||
) | ||
|
||
resource = models.ServiceResource(location=self.location, sku=sku, properties=properties, tags=tags) | ||
poller = self.client.services.begin_create_or_update( | ||
self.resource_group, self.name, resource) | ||
logger.warning(" - Creating Service ..") | ||
wait_till_end(self.cmd, poller) | ||
return poller | ||
|
||
|
||
class EnterpriseSpringCloud(DefaultSpringCloud): | ||
def before_create(self, **_): | ||
pass | ||
|
||
def after_create(self, no_wait=None, **kwargs): | ||
pollers = [ | ||
# create sub components like Service registry, ACS, build service, etc. | ||
] | ||
pollers = [x for x in pollers if x] | ||
if not no_wait: | ||
wait_till_end(self.cmd, *pollers) | ||
|
||
|
||
def _get_factory(cmd, client, resource_group, name, location=None, sku=None): | ||
if _parse_sku_name(sku) == 'enterprise': | ||
return EnterpriseSpringCloud(cmd, client, resource_group, name, location) | ||
return DefaultSpringCloud(cmd, client, resource_group, name, location) | ||
|
||
|
||
def spring_cloud_create(cmd, client, resource_group, name, | ||
location=None, | ||
vnet=None, | ||
service_runtime_subnet=None, | ||
app_subnet=None, | ||
reserved_cidr_range=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, | ||
sku=None, | ||
tags=None, | ||
zone_redundant=False, | ||
no_wait=False): | ||
""" | ||
Because Standard/Basic tier vs. Enterprise tier creation are very different. Here routes the command to different | ||
implementation according to --sku parameters. | ||
""" | ||
kwargs = { | ||
'vnet': vnet, | ||
'service_runtime_subnet': service_runtime_subnet, | ||
'app_subnet': app_subnet, | ||
'reserved_cidr_range': reserved_cidr_range, | ||
'service_runtime_network_resource_group': service_runtime_network_resource_group, | ||
'app_network_resource_group': app_network_resource_group, | ||
'app_insights_key': app_insights_key, | ||
'app_insights': app_insights, | ||
'sampling_rate': sampling_rate, | ||
'disable_app_insights': disable_app_insights, | ||
'enable_java_agent': enable_java_agent, | ||
'sku': sku, | ||
'tags': tags, | ||
'zone_redundant': zone_redundant, | ||
'no_wait': no_wait | ||
} | ||
|
||
spring_cloud_factory = _get_factory(cmd, client, resource_group, name, location=location, sku=sku) | ||
return spring_cloud_factory.create(**kwargs) |
Oops, something went wrong.