<filename>src/reservations/azext_reservations/generated/action.py<gh_stars>0
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
#
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------
# pylint: disable=protected-access

import argparse
from collections import defaultdict
from knack.util import CLIError


class AddProperties(argparse.Action):
    def __call__(self, parser, namespace, values, option_string=None):
        action = self.get_action(values, option_string)
        namespace.properties = action

    def get_action(self, values, option_string):  # pylint: disable=no-self-use
        try:
            properties = defaultdict(list)
            for (k, v) in (x.split('=', 1) for x in values):
                properties[k].append(v)
            properties = dict(properties)
        except ValueError:
            raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
        d = {}
        for k in properties:
            kl = k.lower()
            v = properties[k]
            if kl == 'scopes':
                d['scopes'] = v
            else:
                raise CLIError('Unsupported Key {} is provided for parameter properties. All possible keys are: scopes'
                .format(k))
        return d


class AddReservationsToPurchase(argparse._AppendAction):
    def __call__(self, parser, namespace, values, option_string=None):
        action = self.get_action(values, option_string)
        super(AddReservationsToPurchase, self).__call__(parser, namespace, action, option_string)

    def get_action(self, values, option_string):  # pylint: disable=no-self-use
        try:
            properties = defaultdict(list)
            for (k, v) in (x.split('=', 1) for x in values):
                properties[k].append(v)
            properties = dict(properties)
        except ValueError:
            raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
        d = {}
        d['renew'] = False
        for k in properties:
            kl = k.lower()
            v = properties[k]
            if kl == 'location':
                d['location'] = v[0]
            elif kl == 'reserved-resource-type':
                d['reserved_resource_type'] = v[0]
            elif kl == 'billing-scope-id':
                d['billing_scope_id'] = v[0]
            elif kl == 'term':
                d['term'] = v[0]
            elif kl == 'billing-plan':
                d['billing_plan'] = v[0]
            elif kl == 'quantity':
                d['quantity'] = v[0]
            elif kl == 'display-name':
                d['display_name'] = v[0]
            elif kl == 'applied-scope-type':
                d['applied_scope_type'] = v[0]
            elif kl == 'applied-scopes':
                d['applied_scopes'] = v
            elif kl == 'renew':
                d['renew'] = v[0]
            elif kl == 'instance-flexibility':
                d['instance_flexibility'] = v[0]
            elif kl == 'name':
                d['name'] = v[0]
            else:
                raise CLIError('Unsupported Key {} is provided for parameter reservations_to_purchase. All possible '
                               'keys are: location, reserved-resource-type, billing-scope-id, term, billing-plan, '
                               'quantity, display-name, applied-scope-type, applied-scopes, renew, '
                               'instance-flexibility, name'.format(k))
        return d


class AddReservationsToExchange(argparse._AppendAction):
    def __call__(self, parser, namespace, values, option_string=None):
        action = self.get_action(values, option_string)
        super(AddReservationsToExchange, self).__call__(parser, namespace, action, option_string)

    def get_action(self, values, option_string):  # pylint: disable=no-self-use
        try:
            properties = defaultdict(list)
            for (k, v) in (x.split('=', 1) for x in values):
                properties[k].append(v)
            properties = dict(properties)
        except ValueError:
            raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
        d = {}
        for k in properties:
            kl = k.lower()
            v = properties[k]
            if kl == 'reservation-id':
                d['reservation_id'] = v[0]
            elif kl == 'quantity':
                d['quantity'] = v[0]
            else:
                raise CLIError('Unsupported Key {} is provided for parameter reservations_to_exchange. All possible '
                               'keys are: reservation-id, quantity'.format(k))
        return d
