def pre_instance_update()

in src/mcc/azext_mcc/custom.py [0:0]


    def pre_instance_update(self, instance):
        args = self.ctx.args

        instanceOsType = None

        try:
            instanceOsType = instance.properties.additionalCacheNodeProperties.osType
        except KeyError:
            pass

        if instanceOsType is not None:
            if has_value(args.cache_drive):
                if instanceOsType == "Windows":
                    if len(args.cache_drive) > 1:
                        err_msg = "ValidationError: --cache-drive must not include more than 1 drive when updating a \'Windows\' cache node."
                        raise ValidationError(err_msg)

                    driveArray = args.cache_drive
                    index = 0
                    for drive in driveArray:
                        if has_value(drive.physical_path):
                            if drive.physical_path != "/var/mcc":
                                err_msg = "ValidationError: --cache-drive[" + str(index) + "].physical-path: Must be \'/var/mcc\'"
                                raise ValidationError(err_msg)
                if instanceOsType == "Linux":
                    if len(args.cache_drive) > 9:
                        err_msg = "ValidationError: --cache-drive must not include more than 9 drives when updating a \'Linux\' cache node."
                        raise ValidationError(err_msg)

        instanceIsProxyRequired = None

        try:
            instanceIsProxyRequired = instance.properties.additionalCacheNodeProperties.isProxyRequired
        except KeyError:
            pass

        if instanceIsProxyRequired is not None:
            if instanceIsProxyRequired == "Enabled":
                if has_value(args.proxy):
                    if args.proxy == "Disabled":
                        if has_value(args.proxy_host) or has_value(args.proxy_port):
                            err_msg = "ValidationError: Parameter --enable-proxy is set to \"Disabled\": --proxy-host and --proxy-port cannot be provided."
                            raise ValidationError(err_msg)
                        args.proxy_host = None
                        args.proxy_port = None
                        instance.properties.additionalCacheNodeProperties.proxyUrlConfiguration = None
                    else:
                        oldProxyUrl = instance.properties.additionalCacheNodeProperties.proxyUrlConfiguration.proxyUrl
                        oldProxyUrlParts = str(oldProxyUrl).split(":")
                        newProxyHost = None
                        newProxyPort = None

                        if has_value(args.proxy_host):
                            if ':' in str(args.proxy_host):
                                err_msg = "ValidationError: --proxy-host must not include \':\'."
                                raise ValidationError(err_msg)
                            newProxyHost = args.proxy_host
                        else:
                            newProxyHost = oldProxyUrlParts[0]

                        if has_value(args.proxy_port):
                            if ':' in str(args.proxy_port):
                                err_msg = "ValidationError: --proxy-port must not include \':\'."
                                raise ValidationError(err_msg)
                            newProxyPort = args.proxy_port
                        else:
                            newProxyPort = oldProxyUrlParts[1]

                        args.proxy_host = str(newProxyHost) + ":" + str(newProxyPort)
                else:
                    oldProxyUrl = instance.properties.additionalCacheNodeProperties.proxyUrlConfiguration.proxyUrl
                    oldProxyUrlParts = str(oldProxyUrl).split(":")
                    newProxyHost = None
                    newProxyPort = None

                    if has_value(args.proxy_host):
                        if ':' in str(args.proxy_host):
                            err_msg = "ValidationError: --proxy-host must not include \':\'."
                            raise ValidationError(err_msg)
                        newProxyHost = args.proxy_host
                    else:
                        newProxyHost = oldProxyUrlParts[0]

                    if has_value(args.proxy_port):
                        if ':' in str(args.proxy_port):
                            err_msg = "ValidationError: --proxy-port must not include \':\'."
                            raise ValidationError(err_msg)
                        newProxyPort = args.proxy_port
                    else:
                        newProxyPort = oldProxyUrlParts[1]

                    args.proxy_host = str(newProxyHost) + ":" + str(newProxyPort)
            else:
                if has_value(args.proxy):
                    if args.proxy == "Enabled":
                        if not has_value(args.proxy_host) or not has_value(args.proxy_port):
                            err_msg = "ValidationError: Parameter --enable-proxy is set to \"Enabled\", must provide --proxy-host and --proxy-port parameter."
                            raise ValidationError(err_msg)

                        if ':' in str(args.proxy_host) or ':' in str(args.proxy_port):
                            err_msg = "ValidationError: --proxy-host and --proxy-port must not include \':\'."
                            raise ValidationError(err_msg)

                        args.proxy_host = str(args.proxy_host) + ":" + str(args.proxy_port)
                    else:
                        if has_value(args.proxy_host) or has_value(args.proxy_port):
                            err_msg = "ValidationError: Parameter --enable-proxy is set not provided and cache node is in proxy state \"Disabled\": --proxy-host and --proxy-port cannot be provided."
                            raise ValidationError(err_msg)
                else:
                    if has_value(args.proxy_host) or has_value(args.proxy_port):
                        err_msg = "ValidationError: Parameter --enable-proxy is set not provided and cache node is in proxy state \"Disabled\": --proxy-host and --proxy-port cannot be provided."
                        raise ValidationError(err_msg)
        else:
            if args.proxy == "Enabled":
                if not has_value(args.proxy_host) or not has_value(args.proxy_port):
                    err_msg = "ValidationError: Parameter --enable-proxy is set to \"Enabled\", must provide --proxy-host and --proxy-port parameter."
                    raise ValidationError(err_msg)

                if ':' in str(args.proxy_host) or ':' in str(args.proxy_port):
                    err_msg = "ValidationError: --proxy-host and --proxy-port must not include \':\'."
                    raise ValidationError(err_msg)

                args.proxy_host = str(args.proxy_host) + ":" + str(args.proxy_port)
            else:
                if has_value(args.proxy_host) or has_value(args.proxy_port):
                    err_msg = "ValidationError: Parameter --enable-proxy is set to \"Disabled\": --proxy-host and --proxy-port cannot be provided."
                    raise ValidationError(err_msg)

        instanceAutoUpdateRing = None

        try:
            instanceAutoUpdateRing = instance.properties.cacheNode.autoUpdateRingType
        except KeyError:
            pass

        if instanceAutoUpdateRing is not None:
            if str(instanceAutoUpdateRing) == "Fast":
                if has_value(args.auto_update_ring):
                    if str(args.auto_update_ring) == "Slow":
                        if not has_value(args.auto_update_day) or not has_value(args.auto_update_week) or not has_value(args.auto_update_time):
                            err_msg = "ValidationError: Switching cache node auto update ring from \"Fast\" to \"Slow\", --auto-update-day, --auto-update-week, and --auto-update-time must not be Undefined"
                            raise ValidationError(err_msg)
                    else:
                        if has_value(args.auto_update_day) or has_value(args.auto_update_week) or has_value(args.auto_update_time):
                            err_msg = "ValidationError: Parameter --auto-update-ring is set to \"Fast\" and cache node is already on \"Fast\" ring type, --auto-update-day, --auto-update-week, and --auto-update-time must be Undefined"
                            raise ValidationError(err_msg)
                else:
                    if has_value(args.auto_update_day) or has_value(args.auto_update_week) or has_value(args.auto_update_time):
                        err_msg = "ValidationError: Parameter --auto-update-ring is Undefined, --auto-update-day, --auto-update-week, and --auto-update-time must be Undefined"
                        raise ValidationError(err_msg)
            else:
                if has_value(args.auto_update_ring):
                    if str(args.auto_update_ring) == "Fast":
                        if has_value(args.auto_update_day) or has_value(args.auto_update_week) or has_value(args.auto_update_time):
                            err_msg = "ValidationError: Switching cache node auto update ring from \"Slow\" to \"Fast\", --auto-update-day, --auto-update-week, and --auto-update-time must be Undefined"
                            raise ValidationError(err_msg)