diff --git a/src/pycpc/cli/cmd_add_subscription_type.py b/src/pycpc/cli/cmd_add_subscription_type.py index f199d8c..2f2716f 100644 --- a/src/pycpc/cli/cmd_add_subscription_type.py +++ b/src/pycpc/cli/cmd_add_subscription_type.py @@ -1,120 +1,110 @@ # -*- coding: utf-8 -*- # Copyright 2010-2015 Kolab Systems AG (http://www.kolabsys.com) # # Jeroen van Meeuwen (Kolab Systems) # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # import sys import commands import pycpc from pycpc.translate import _ from pycpc import utils log = pycpc.getLogger('pypc.cli') conf = pycpc.getConf() def __init__(): commands.register( 'add_subscription_type', execute, description=description() ) def cli_options(): my_option_group = conf.add_cli_parser_option_group(_("CLI Options")) my_option_group.add_option( '--name', dest = "name", action = "store", default = None, metavar = "NAME", help = _("The name for the product, for example 'Kolab " + \ "Premium Support Subscription'") ) my_option_group.add_option( '--id', dest = "id", action = "store", default = None, metavar = "ID", help = _("The desired ID for the product. May be alpha-numeric.") ) my_option_group.add_option( '--multiplier', dest = "multiplier", action = "store", type = int, default = 1, metavar = "MULTIPLIER", help = _("A multiplier, influencing the pool size for a " + \ "single subscription entitlement.") ) my_option_group.add_option( '--service-level', dest = "service_level", action = "store", default = None, metavar = "STR", help = _("The service level for the product (i.e. 'Standard' or 'Premium').") ) my_option_group.add_option( '--service-type', dest = "service_type", action = "store", default = None, metavar = "STR", help = _("The service type for the product (i.e. 'L2-L3', 'L1'.") ) - my_option_group.add_option( - '--provided-product', - dest = "provided_product_ids", - action = "append", - default = [], - metavar = "ID", - help = _("ID for products provided.") - ) - def description(): return _("Add a type of subscription.") def execute(*args, **kw): """ Add a type of subscription. """ assert(conf.name) assert(conf.multiplier) from pycpc.client import request payload = { "name": conf.name, "multiplier": conf.multiplier, - "attributes": [{"name":"type","value":"MKT"}], - "providedProducts": list(set(conf.provided_product_ids)) + "attributes": [{"name":"type","value":"SUB"}] } if conf.id: payload["id"] = conf.id product = request(method='POST', path='/products', post=payload) diff --git a/src/pycpc/cli/cmd_entitle_customer.py b/src/pycpc/cli/cmd_entitle_customer.py index e91f34e..82edc01 100644 --- a/src/pycpc/cli/cmd_entitle_customer.py +++ b/src/pycpc/cli/cmd_entitle_customer.py @@ -1,140 +1,140 @@ # -*- coding: utf-8 -*- # Copyright 2010-2015 Kolab Systems AG (http://www.kolabsys.com) # # Jeroen van Meeuwen (Kolab Systems) # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # import datetime import sys import time import commands import pycpc from pycpc.translate import _ from pycpc import utils log = pycpc.getLogger('pypc.cli') conf = pycpc.getConf() def __init__(): commands.register( 'entitle_customer', execute, description=description() ) def cli_options(): my_option_group = conf.add_cli_parser_option_group(_("CLI Options")) my_option_group.add_option( '--customer-key', dest = "customer_key", action = "store", type = int, default = None, metavar = "KEY", help = _("The customer key.") ) my_option_group.add_option( '--start-date', dest = "start_date", action = "store", default = str(datetime.date.today()), metavar = "DATE", help = _("A YYYYMMDD date. Default: today.") ) my_option_group.add_option( '--end-date', dest = "end_date", action = "store", default = str(datetime.date.fromtimestamp(time.time() + 60 * 60 * 24 * 365)), metavar = "DATE", help = _("A YYYYMMDD date. Default: now + 1 year") ) my_option_group.add_option( '--quantity', dest = "quantity", action = "store", type = int, default = 1, metavar = "NUM", help = _("Quantity of entitlements.") ) my_option_group.add_option( '--product-id', dest = "product_id", action = "store", default = None, metavar = "ID", help = _("ID for the product.") ) def description(): return _("Entitle a customer to a product.") def execute(*args, **kw): """ Entitle a customer to a product. """ assert(conf.customer_key) assert(conf.start_date) assert(conf.end_date) assert(conf.product_id) from pycpc.client import request provided_product_ids = [] products = request(method='GET', path='/products') for product in products: if product.has_key('attributes'): for attribute in product['attributes']: if attribute.has_key('name'): if attribute['name'] == 'type': - if attribute['value'] in ['server', 'client']: + if attribute['value'] in ['MKT']: provided_product_ids.append({"id":product['id']}) derived_product_ids = [] for product in products: if product.has_key('attributes'): for attribute in product['attributes']: if attribute.has_key('name'): if attribute['name'] == 'type': if attribute['value'] in ['product']: derived_product_ids.append({"id":product['id']}) payload = { "startDate": str(conf.start_date), "endDate": str(conf.end_date), "quantity": conf.quantity, "product": { "id": conf.product_id }, "providedProducts": provided_product_ids, "derivedProvidedProducts": derived_product_ids } subscription = request(method='POST', path='/owners/%s/subscriptions' % (conf.customer_key), post=payload) pools = request(method='PUT', path='/owners/%s/subscriptions' % (conf.customer_key))