Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
ConfigureResources,
ConfigureResourcesStatus,
JobStatus,
DurableId)
DurableId,
VirtualMachinePlanTechnicalConfiguration,
)


class ProductIngestionApiClientConfiguration:
Expand All @@ -37,6 +39,7 @@ def __init__(self, access_token=None):
'get-container-plan-technical-configuration': '2022-03-01-preview3',
'post-configure': '2022-03-01-preview2',
'get-configure-status': '2022-03-01-preview2',
'get-virtual-machine-plan-technical-configuration': '2022-03-01-preview6',
'get-submission': '2022-03-01-preview2'
}

Expand Down Expand Up @@ -86,6 +89,13 @@ def configure_resources(self, *resources):
# otherwise the status of the job is completed, so return it
return status

def update_virtual_machine_plan_technical_configuration(self, offer_id, plan_id, resource=VirtualMachinePlanTechnicalConfiguration | None):
""" Update the technical configuration for a virtual machines vmProperties"""

configuration = resource.dict(by_alias=True)
return self.configure_resources(configuration)


def update_container_plan_technical_configuration_for_bundle(self, offer_durable_id, plan_durable_id,
properties=ContainerCnabPlanTechnicalConfigurationProperties | None):
"""Updates the technical configuration for a 'list and sell' offer, which uses a CNAB bundle"""
Expand Down Expand Up @@ -167,6 +177,18 @@ def get_container_plan_technical_configuration(self, offer_durable_id, plan_dura
configuration = self._parse_technical_configuration_response(response, sell_through_microsoft)
return configuration

def get_third_party_virtual_machine_plan_technical_configuration(self, offer_durable_id, plan_durable_id):
""" Gets the response from the Graph endpoint for the virtual machine technical configuration

:return: instance of VritualMachinePlanTechnicalConfiguration [azext_partnercenter.vendored_sdks.production_ingestion.models.virtual_machine_plan_technical_configuration]
"""
operation_id = 'get-virtual-machine-plan-technical-configuration'
path = f'virtual-machine-plan-technical-configuration/{offer_durable_id}/{plan_durable_id}'

response = self.__call_api(operation_id, path)

return VirtualMachinePlanTechnicalConfiguration.parse_obj(response.json())

def get_resource_tree(self, offer_durable_id):
"""Returns the raw response as a dictionary"""
operation_id = 'get-resource-tree'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ def get(self, offer_external_id, plan_external_id):
technical_configuration = self._graph_api_client.get_container_plan_technical_configuration(offer_durable_id, plan_durable_id, sell_through_microsoft)
elif variant_package_branch.product.resource_type == 'AzureApplication':
technical_configuration = self._get_azure_application_plan_technical_configuration(offer_durable_id, variant_package_branch.current_draft_instance_id)
elif variant_package_branch.product.resource_type == 'AzureThirdPartyVirtualMachine':
technical_configuration = self._graph_api_client.get_third_party_virtual_machine_plan_technical_configuration(offer_durable_id, plan_durable_id)
else:
technical_configuration = self._get_plan_technical_configuration(variant_package_branch.product.id, variant_package_branch.variant_id)
technical_configuration['planId'] = plan_external_id
Expand Down Expand Up @@ -191,6 +193,20 @@ def _map_package_reference(self, package_ref):
def _map_package_authorization(self, pkg_auth):
return PackageAuthorization(principal_id=pkg_auth.principal_id, role_definition_id=pkg_auth.role_definition_id)

def update_virtual_machine_technical_configuration(self, offer_id, plan_id, vmconfig):
status = self._graph_api_client.update_virtual_machine_plan_technical_configuration(offer_id, plan_id, vmconfig)

if len(status.errors) > 0:
return {
'errors': status.errors,
'result': status.job_result
}
else:
return {
'message': status.job_status.value,
'result': status.job_result
}

def _update_technical_configuration_properties(self, offer_external_id, plan_external_id, properties=ContainerCnabPlanTechnicalConfigurationProperties | None):
variant_package_branch = self._get_variant_package_branch(offer_external_id, plan_external_id)
offer_durable_id = variant_package_branch.product.id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ class PlanTechnicalConfigurationType(str, Enum, metaclass=CaseInsensitiveEnumMet

Container = "Container"
ContainerCnab = "ContainerCnab"
ThirdPartyVirtualMachine = "ThirdPartyVritualMachine"
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ def load_help():
short-summary: Manage packages for a plan's technical configuration.
"""

helps['partnercenter marketplace offer plan technical-configuration vmimageversion'] = """
type: group
short-summary: Manage virtual machine image versions for a plan's technical configuration.
"""

helps['partnercenter marketplace offer plan technical-configuration show'] = """
type: command
short-summary: Show a plan's technical configuration
Expand All @@ -32,3 +37,13 @@ def load_help():
type: command
short-summary: Deletes a package to the technical configuration of a plan
"""

helps['partnercenter marketplace offer plan technical-configuration vm-image-version add'] = """
type: command
short-summary: Adds image version to image version to list in technical configuration
"""

helps['partnercenter marketplace offer plan technical-configuration vm-image-version delete'] = """
type: command
short-summary: Deletes image version from a plans technical configuration
"""
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@ def load_command_table(commands_loader, _):
with commands_loader.command_group('partnercenter marketplace offer plan technical-configuration package', custom_command_type=custom_command_type, is_preview=True) as g:
g.custom_command('add', 'add_technical_configuration_bundle', supports_no_wait=True, table_transformer=None)
g.custom_command('delete', 'delete_technicalconfiguration_package', supports_no_wait=True)

with commands_loader.command_group('partnercenter marketplace offer plan technical-configuration vm-image-version', custom_command_type=custom_command_type, is_preview=True) as g:
g.custom_command('add', 'add_technical_configuration_vm_image_version', supports_no_wait=True,
table_transformer=None)
g.custom_command('delete', 'delete_technical_configuration_vm_image_version',
supports_no_wait=True, table_transformer=None)
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from azext_partnercenter import ISSUES_URL
from azext_partnercenter.models import PlanTechnicalConfigurationType

import json

def get_technicalconfiguration(client, offer_id, plan_id):
return client.get(offer_id, plan_id)
Expand Down Expand Up @@ -67,6 +68,24 @@ def add_technical_configuration_bundle(client, offer_id, plan_id, cluster_extens
result = client.add_managed_app_bundle(offer_id, plan_id, package_path, public_azure_tenant_id, public_azure_authorization_principal, public_azure_authorization_role)
return result

def add_technical_configuration_vm_image_version(client, offer_id, plan_id, vm_image_version_json_file):
new_vm_image_version = None
with open(vm_image_version_json_file) as json_file:
new_vm_image_version = json.load(json_file)

technical_configuration = client.get(offer_id, plan_id)
technical_configuration.vm_image_versions = technical_configuration.vm_image_versions + new_vm_image_version

return client.update_virtual_machine_technical_configuration(offer_id, plan_id, technical_configuration)

def delete_technical_configuration_vm_image_version(client, offer_id, plan_id,
vm_image_version):
technical_configuration = client.get(offer_id, plan_id)
technical_configuration.vm_image_versions = [version for version in
technical_configuration.vm_image_versions
if version["versionNumber"] != vm_image_version]

return client.update_virtual_machine_technical_configuration(offer_id, plan_id, technical_configuration)

def _has_existing_package(technical_configuration):
return technical_configuration.get('package_references') and len(technical_configuration['package_references']) > 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,9 @@ def load_arguments(commands_loader, _):
with commands_loader.argument_context('partnercenter marketplace offer plan technical-configuration package delete') as c:
c.argument('repository_name', arg_group='CNAB Resource', options_list=['--repository'], help='The name of the image repository in the Azure Container Registry.')
c.argument('tag', arg_group='CNAB Resource', options_list=['--tag'], help='The name of the image repository.')

with commands_loader.argument_context('partnercenter marketplace offer plan technical-configuration vm-image-version add') as c:
c.argument('vm-image-version-json-file', arg_group='VMImage', options_list="--vm-image-version-json-file", help="Json file containing the vm image version to add")

with commands_loader.argument_context('partnercenter marketplace offer plan technical-configuration vm-image-version delete') as c:
c.argument('vm-image-version', arg_group='VMImage', options_list="--vm-image-version", help="Version of VM image(s) that you want to remove")
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,13 @@ class ContainerPlanTechnicalConfiguration(Resource):
product: ResourceReference
plan: ResourceReference

class VirtualMachinePlanTechnicalConfiguration(Resource):
product: str
plan: ResourceReference
operating_system: dict = Field(..., alias='operatingSystem')
skus: List[dict] = Field(..., alias="skus")
vm_image_versions: List[dict] = Field(..., alias="vmImageVersions")
vm_properties: dict = Field(..., alias="vmProperties")

class ConfigureResources(BaseModel):
model_config = ConfigDict(extra="forbid")
Expand Down
Loading