def update_origin_group(cmd, client: OriginGroupsOperations, resource_group_name: str, profile_name: str, endpoint_name: str, name: str, probe_path: str = None, probe_method: str = None, probe_protocol: str = None, probe_interval: int = None, origins: str = None): # Move these to the parameters list once support is added in RP: error_types: Optional[str] = None failover_threshold: Optional[int] = None status_code_ranges: Optional[str] = None from azure.mgmt.cdn.models import ( OriginGroupUpdateParameters, HealthProbeParameters, ResponseBasedOriginErrorDetectionParameters, ResourceReference) if probe_method is not None: probe_method = HealthProbeRequestType[probe_method.upper()] if probe_protocol is not None: probe_protocol = ProbeProtocol[probe_protocol.upper()] # Get existing health probe settings: existing = client.get(resource_group_name, profile_name, endpoint_name, name) # Allow removing properties explicitly by specifying as empty string, or # update without modifying by not specifying (value is None). if probe_path == '': probe_path = None elif probe_path is None: probe_path = existing.health_probe_settings.probe_path if probe_method == '': probe_method = None elif probe_method is None: probe_method = existing.health_probe_settings.probe_request_type if probe_protocol == '': probe_protocol = None elif probe_protocol is None: probe_protocol = existing.health_probe_settings.probe_protocol if probe_interval == '': probe_interval = None elif probe_interval is None: probe_interval = existing.health_probe_settings.probe_interval_in_seconds origins = origins or existing.origins health_probe_settings = HealthProbeParameters( probe_path=probe_path, probe_request_type=probe_method, probe_protocol=probe_protocol, probe_interval_in_seconds=probe_interval) if error_types is not None: error_types = error_types.split(',') if status_code_ranges is not None: status_code_ranges = _parse_ranges(status_code_ranges) error_detection_settings = None if error_types or \ failover_threshold or \ status_code_ranges: error_detection_settings = ResponseBasedOriginErrorDetectionParameters( response_based_detected_error_types=error_types, response_based_failover_threshold_percentage=failover_threshold, http_error_ranges=status_code_ranges) formatted_origins = [] subscription_id = get_subscription_id(cmd.cli_ctx) for origin in origins.split(','): # If the origin is not an ID, assume it's a name and format it as an ID. if '/' not in origin: origin = f'/subscriptions/{subscription_id}/resourceGroups/{resource_group_name}' \ f'/providers/Microsoft.Cdn/profiles/{profile_name}/endpoints/{endpoint_name}' \ f'/origins/{origin}' formatted_origins.append(ResourceReference(id=origin)) origin_group = OriginGroupUpdateParameters( origins=formatted_origins, health_probe_settings=health_probe_settings, response_based_origin_error_detection_settings=error_detection_settings ) # client.begin_create isn't really a create, it's a PUT which is create or update, # client.begin_update doesn't allow unsetting fields. return client.begin_create(resource_group_name, profile_name, endpoint_name, name, origin_group)
def update_afd_origin(client: AFDOriginsOperations, resource_group_name: str, profile_name: str, origin_group_name: str, origin_name: str, host_name: str = None, enabled_state: EnabledState = None, http_port: int = None, https_port: int = None, origin_host_header: Optional[str] = None, priority: int = None, weight: int = None, enable_private_link: bool = None, private_link_resource: str = None, private_link_location: str = None, private_link_sub_resource_type: str = None, private_link_request_message: str = None, enforce_certificate_name_check: bool = None): existing = client.get(resource_group_name, profile_name, origin_group_name, origin_name) origin = AFDOrigin( host_name=host_name, http_port=http_port, https_port=https_port, origin_host_header=origin_host_header, priority=priority, weight=weight, enabled_state=enabled_state, enforce_certificate_name_check=enforce_certificate_name_check) _update_mapper(existing, origin, [ "host_name", "http_port", "https_port", "origin_host_header", "priority", "weight", "enabled_state", "enforce_certificate_name_check" ]) if enable_private_link is not None and not enable_private_link: origin.shared_private_link_resource = None elif (private_link_resource is not None or private_link_location is not None or private_link_sub_resource_type is not None or private_link_request_message is not None): shared_private_link_resource = SharedPrivateLinkResourceProperties( private_link=ResourceReference(id=private_link_resource) if private_link_resource is not None else None, private_link_location=private_link_location, group_id=private_link_sub_resource_type, request_message=private_link_request_message) if existing.shared_private_link_resource is not None: existing_shared_private_link_resource = SharedPrivateLinkResourceProperties( private_link=ResourceReference( id=existing.shared_private_link_resource.private_link.id), private_link_location=existing.shared_private_link_resource. private_link_location, group_id=existing.shared_private_link_resource.group_id, request_message=existing.shared_private_link_resource. request_message) _update_mapper(existing_shared_private_link_resource, shared_private_link_resource, [ "private_link", "private_link_location", "group_id", "request_message" ]) origin.shared_private_link_resource = shared_private_link_resource else: origin.shared_private_link_resource = existing.shared_private_link_resource # client.update does not allow unset field return client.begin_create(resource_group_name, profile_name, origin_group_name, origin_name, origin)
def create_origin_group(cmd, client: OriginGroupsOperations, resource_group_name: str, profile_name: str, endpoint_name: str, name: str, probe_path: Optional[str] = None, probe_method: str = "HEAD", probe_protocol: str = "HTTP", probe_interval: int = 240, origins: Optional[str] = None): # Move these to the parameters list once support is added in RP: response_error_detection_error_types: Optional[str] = None response_error_detection_failover_threshold: Optional[int] = None response_error_detection_status_code_ranges: Optional[str] = None from azure.mgmt.cdn.models import ( OriginGroup, HealthProbeParameters, ResponseBasedOriginErrorDetectionParameters, ResourceReference) health_probe_settings = HealthProbeParameters( probe_path=probe_path, probe_request_type=HealthProbeRequestType[probe_method.upper()], probe_protocol=ProbeProtocol[probe_protocol.upper()], probe_interval_in_seconds=probe_interval) error_types = None if response_error_detection_error_types: error_types = response_error_detection_error_types.split(',') error_detection_settings = None if response_error_detection_error_types or \ response_error_detection_failover_threshold or \ response_error_detection_status_code_ranges: error_detection_settings = ResponseBasedOriginErrorDetectionParameters( response_based_detected_error_types=error_types, response_based_failover_threshold_percentage= response_error_detection_failover_threshold, http_error_ranges=_parse_ranges( response_error_detection_status_code_ranges)) formatted_origins = [] subscription_id = get_subscription_id(cmd.cli_ctx) if origins: for origin in origins.split(','): # If the origin is not an ID, assume it's a name and format it as an ID. if '/' not in origin: origin = f'/subscriptions/{subscription_id}/resourceGroups/{resource_group_name}' \ f'/providers/Microsoft.Cdn/profiles/{profile_name}/endpoints/{endpoint_name}' \ f'/origins/{origin}' formatted_origins.append(ResourceReference(id=origin)) origin_group = OriginGroup( origins=formatted_origins, health_probe_settings=health_probe_settings, response_based_origin_error_detection_settings=error_detection_settings ) return client.begin_create(resource_group_name, profile_name, endpoint_name, name, origin_group).result()