Skip to content

Commit 8ac9fbf

Browse files
committed
migrate
1 parent 50677b6 commit 8ac9fbf

File tree

6 files changed

+4787
-3703
lines changed

6 files changed

+4787
-3703
lines changed

src/azure-cli/azure/cli/command_modules/vm/custom.py

Lines changed: 16 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -5688,43 +5688,13 @@ def show_capacity_reservation(client, resource_group_name, capacity_reservation_
56885688

56895689
def set_vm_applications(cmd, vm_name, resource_group_name, application_version_ids, order_applications=False, application_configuration_overrides=None, treat_deployment_as_failure=None, no_wait=False):
56905690
from .aaz.latest.vm import Update as _VMUpdate
5691+
56915692
class SetVMApplications(_VMUpdate):
5692-
# def pre_operations(self):
5693-
# args = self.ctx.args
5694-
# args.no_wait = no_wait
5693+
def pre_operations(self):
5694+
args = self.ctx.args
5695+
args.no_wait = no_wait
56955696

56965697
def pre_instance_update(self, instance):
5697-
# def _flatten(collection, expand_property_fn):
5698-
# for each in collection:
5699-
# yield from expand_property_fn(each)
5700-
5701-
# if disabled_rule_groups or disabled_rules:
5702-
# disabled_groups = []
5703-
# # disabled groups can be added directly
5704-
# for group in disabled_rule_groups or []:
5705-
# disabled_groups.append({"rule_group_name": group})
5706-
# # for disabled rules, we have to look up the IDs
5707-
# if disabled_rules:
5708-
# rule_sets = list_ag_waf_rule_sets(cmd, _type=rule_set_type, version=rule_set_version, group='*')
5709-
# for group in _flatten(rule_sets, lambda r: r["ruleGroups"]):
5710-
# disabled_group = {
5711-
# "rule_group_name": group["ruleGroupName"],
5712-
# "rules": []
5713-
# }
5714-
# for rule in group["rules"]:
5715-
# if str(rule["ruleId"]) in disabled_rules:
5716-
# disabled_group["rules"].append(rule["ruleId"])
5717-
# if disabled_group["rules"]:
5718-
# disabled_groups.append(disabled_group)
5719-
# waf_config["disabled_rule_groups"] = disabled_groups
5720-
# waf_config["request_body_check"] = request_body_check
5721-
# waf_config["max_request_body_size_in_kb"] = max_request_body_size
5722-
# waf_config["file_upload_limit_in_mb"] = file_upload_limit
5723-
# waf_config["exclusions"] = exclusions
5724-
#
5725-
# instance.properties.web_application_firewall_configuration = waf_config
5726-
5727-
# gallery_applications =
57285698
instance.properties.application_profile.gallery_applications = [{"package_reference_id": avid} for avid in application_version_ids]
57295699

57305700
if order_applications:
@@ -5747,67 +5717,35 @@ def pre_instance_update(self, instance):
57475717
treat_as_failure.lower() == 'true'
57485718
index += 1
57495719

5720+
def _output(self, *args, **kwargs):
5721+
from azure.cli.core.aaz import AAZUndefined, has_value
57505722

5751-
# client = _compute_client_factory(cmd.cli_ctx)
5752-
# ApplicationProfile, VMGalleryApplication = cmd.get_models('ApplicationProfile', 'VMGalleryApplication')
5753-
# try:
5754-
# from .operations.vm import VMShow
5755-
# vm = VMShow(cli_ctx=cmd.cli_ctx)(command_args={
5756-
# "resource_group": resource_group_name,
5757-
# "vm_name": vm_name
5758-
# })
5759-
# # vm = client.virtual_machines.get(resource_group_name, vm_name)
5760-
# except ResourceNotFoundError:
5761-
# raise ResourceNotFoundError('Could not find vm {}.'.format(vm_name))
5762-
#
5763-
# # vm.application_profile = ApplicationProfile(gallery_applications=[VMGalleryApplication(package_reference_id=avid) for avid in application_version_ids])
5764-
# vm["application_profile"] = {
5765-
# "gallery_applications": [{"package_reference_id": avid} for avid in application_version_ids]
5766-
# }
5767-
#
5768-
# if order_applications:
5769-
# index = 1
5770-
# for app in vm["application_profile"]["gallery_applications"]:
5771-
# app["order"] = index
5772-
# index += 1
5773-
#
5774-
# if application_configuration_overrides:
5775-
# index = 0
5776-
# for over_ride in application_configuration_overrides:
5777-
# if over_ride or over_ride.lower() != 'null':
5778-
# vm["application_profile"]["gallery_applications"][index]["configuration_reference"] = over_ride
5779-
# index += 1
5780-
#
5781-
# if treat_deployment_as_failure:
5782-
# index = 0
5783-
# for treat_as_failure in treat_deployment_as_failure:
5784-
# vm["application_profile"]["gallery_applications"][index]["treat_failure_as_deployment_failure"] = \
5785-
# treat_as_failure.lower() == 'true'
5786-
# index += 1
5787-
# # return sdk_no_wait(no_wait, client.virtual_machines.begin_create_or_update, resource_group_name, vm_name, vm)
5788-
#
5789-
# vm["resource_group"] = resource_group_name
5790-
# vm["vm_name"] = vm_name
5723+
# Resolve flatten conflict
5724+
# When the type field conflicts, the type in inner layer is ignored and the outer layer is applied
5725+
if has_value(self.ctx.vars.instance.resources):
5726+
for resource in self.ctx.vars.instance.resources:
5727+
if has_value(resource.type):
5728+
resource.type = AAZUndefined
5729+
5730+
result = self.deserialize_output(self.ctx.vars.instance, client_flatten=True)
5731+
return result
57915732

5792-
# from .operations.vm import VMCreate
57935733
return SetVMApplications(cli_ctx=cmd.cli_ctx)(command_args={
57945734
"resource_group": resource_group_name,
57955735
"vm_name": vm_name,
57965736
})
57975737

57985738

57995739
def list_vm_applications(cmd, vm_name, resource_group_name):
5800-
# client = _compute_client_factory(cmd.cli_ctx)
58015740
try:
5802-
# vm = client.virtual_machines.get(resource_group_name, vm_name)
58035741
from .operations.vm import VMShow
58045742
vm = VMShow(cli_ctx=cmd.cli_ctx)(command_args={
58055743
"resource_group": resource_group_name,
58065744
"vm_name": vm_name
58075745
})
58085746
except ResourceNotFoundError:
58095747
raise ResourceNotFoundError('Could not find vm {}.'.format(vm_name))
5810-
return vm["applicationProfile"]
5748+
return vm.get("applicationProfile", {})
58115749

58125750

58135751
def set_vmss_applications(cmd, vmss_name, resource_group_name, application_version_ids, order_applications=False, application_configuration_overrides=None, treat_deployment_as_failure=None, no_wait=False):

0 commit comments

Comments
 (0)