def _get_subscriptions(self, contract, subs_id_filter):
     query = R()
     query &= R().contract.id.oneof([contract['id']])
     query &= R().id.oneof([subs_id_filter])
     subscriptions = self.client.collection("assets").filter(query)
     subscriptions.order_by('product.id')
     return subscriptions
예제 #2
0
def warm_up_tcs(client, products):
    rql_filter = R()
    rql_filter &= R().product.id.oneof(products)
    tcs = client.ns('tier').configs.filter(rql_filter).all()
    for tc in tcs:
        if not awsmpn.get(f'{tc["account"]["id"]}_{tc["product"]["id"]}'):
            for param in tc['params']:
                if param['id'] == 'awsApnId':
                    awsmpn[
                        f'{tc["account"]["id"]}_{tc["product"]["id"]}'] = param.get(
                            'value', '-')
예제 #3
0
def get_aws_mpn(client, account, product):
    if awsmpn.get(account):
        return awsmpn.get(account)
    rql_filter = R()
    rql_filter &= R().product.id.eq(product)
    rql_filter &= R().account.id.eq(account)
    tc = client.ns('tier').configs.filter(rql_filter).first()
    if tc:
        for param in tc['params']:
            if param['id'] == 'awsApnId':
                awsmpn['account'] = param.get('value', '-')
                return param.get('value', '-')
    return '-'
예제 #4
0
def get_ta_parameter(request, tier, param_id, client):
    try:
        rql = R().configuration.account.id.eq(
            request['asset']['tiers'][tier]['id'])
        rql = rql & R().status.eq('approved')
        tc = client.ns('tier').collection("config-requests").filter(
            rql).order_by('-created').first()
        if 'params' not in tc:
            return "-"
        for param in tc['params']:
            if param["id"] == param_id:
                return param["value"]
    except Exception:
        pass
    return "-"
예제 #5
0
def generate(client, parameters, progress_callback):
    query = R()
    if parameters.get('type') and parameters['type']['all'] is False:
        query &= R().type.oneof(parameters['type']['choices'])
    if parameters.get('status') and parameters['status']['all'] is False:
        query &= R().status.oneof(parameters['status']['choices'])
    contracts = client.contracts.filter(query).select("agreement").order_by(
        "-status")
    progress = 0
    total = contracts.count()
    output = []

    for contract in contracts:
        yield (
            get_basic_value(contract, 'id'),
            get_basic_value(contract, 'type'),
            get_basic_value(contract, 'version'),
            'Yes' if get_basic_value(contract, 'latest') is False else '-',
            get_value(contract, 'agreement', 'id'),
            get_value(contract, 'agreement', 'name'),
            get_value(contract, 'issuer', 'name'),
            convert_to_datetime(get_value(contract['events'], 'created',
                                          'at')),
            get_value(contract, 'marketplace', 'id'),
            get_value(contract, 'marketplace', 'name'),
            get_value(contract['sourcing'], 'product', 'id')
            if 'sourcing' in contract else '-',
            get_value(contract['sourcing'], 'product', 'name')
            if 'sourcing' in contract else '-',
            get_value(contract['events']['signed'], 'by', 'name')
            if 'signed' in contract['events'] else '-',
            convert_to_datetime(get_value(contract['events'], 'signed', 'at'))
            if 'created' in contract['events'] else '-',
            get_value(contract['events']['countersigned'], 'by', 'name')
            if 'countersigned' in contract['events'] else '-',
            convert_to_datetime(
                get_value(contract['events'], 'countersigned', 'at'))
            if 'countersigned' in contract['events'] else '-',
        )
        progress += 1
        progress_callback(progress, total)

    return output
예제 #6
0
def generate(client, parameters, progress_callback):
    query = R()
    if parameters.get('date') and parameters['date']['after'] != '':
        query &= R().events.created.at.ge(parameters['date']['after'])
        query &= R().events.created.at.le(parameters['date']['before'])
    if parameters.get('product') and parameters['product']['all'] is False:
        query &= R().product.id.oneof(parameters['product']['choices'])
    if parameters.get('mkp') and parameters['mkp']['all'] is False:
        query &= R().marketplace.id.oneof(parameters['mkp']['choices'])
    if parameters.get('period') and parameters['period']['all'] is False:
        query &= R().billing.period.uom.oneof(parameters['period']['choices'])
    if parameters.get('status') and parameters['status']['all'] is False:
        query &= R().status.oneof(parameters['status']['choices'])

    subscriptions = client.ns('subscriptions').assets.filter(query)
    progress = 0
    total = subscriptions.count()

    for subscription in subscriptions:
        yield (
            subscription.get('id'),
            subscription.get('external_id', '-'),
            convert_to_datetime(subscription['events']['created']['at']),
            convert_to_datetime(subscription['events']['updated']['at']),
            subscription.get('status'),
            calculate_period(
                subscription['billing']['period']['delta'],
                subscription['billing']['period']['uom'],
            ) if 'billing' in subscription else '-',
            get_anniversary_day(subscription['billing'])
            if 'billing' in subscription else '-',
            get_anniversary_month(subscription['billing'])
            if 'billing' in subscription else '-',
            subscription['contract']['id']
            if 'contract' in subscription else '-',
            subscription['contract']['name']
            if 'contract' in subscription else '-',
            get_value(subscription['tiers'], 'customer', 'id'),
            get_value(subscription['tiers'], 'customer', 'name'),
            get_value(subscription['tiers'], 'customer', 'external_id'),
            get_value(subscription['tiers'], 'tier1', 'id'),
            get_value(subscription['tiers'], 'tier1', 'name'),
            get_value(subscription['tiers'], 'tier1', 'external_id'),
            get_value(subscription['tiers'], 'tier2', 'id'),
            get_value(subscription['tiers'], 'tier2', 'name'),
            get_value(subscription['tiers'], 'tier2', 'external_id'),
            get_value(subscription['connection'], 'provider', 'id'),
            get_value(subscription['connection'], 'provider', 'name'),
            get_value(subscription['connection'], 'vendor', 'id'),
            get_value(subscription['connection'], 'vendor', 'name'),
            get_value(subscription, 'product', 'id'),
            get_value(subscription, 'product', 'name'),
            get_value(subscription['connection'], 'hub', 'id'),
            get_value(subscription['connection'], 'hub', 'name'),
        )
        progress += 1
        progress_callback(progress, total)
예제 #7
0
def generate(client, parameters, progress_callback):

    query = R()
    query &= R().created.ge(parameters['date']['after'])
    query &= R().created.le(parameters['date']['before'])
    if parameters.get('product') and parameters['product']['all'] is False:
        query &= R().asset.product.id.oneof(parameters['product']['choices'])
    if parameters.get('rr_type') and parameters['rr_type']['all'] is False:
        query &= R().type.oneof(parameters['rr_type']['choices'])
    query &= R().status.eq('failed')
    if parameters.get('connection_type') and parameters['connection_type']['all'] is False:
        query &= R().asset.connection.type.oneof(parameters['connection_type']['choices'])
    requests = client.requests.filter(query)
    progress = 0
    total = requests.count()
    today = datetime.today().strftime('%Y-%m-%d-%H:%M:%S')
    for request in requests:
        connection = request['asset']['connection']
        yield (
            get_basic_value(request, 'id'),
            get_basic_value(request, 'type'),
            convert_to_datetime(
                get_basic_value(request, 'created')
            ),
            convert_to_datetime(
                get_basic_value(request, 'updated')
            ),
            today,
            get_value(request['asset']['tiers'], 'customer', 'id'),
            get_value(request['asset']['tiers'], 'customer', 'name'),
            get_value(request['asset']['tiers'], 'customer', 'external_id'),
            get_value(request['asset']['tiers'], 'tier1', 'id'),
            get_value(request['asset']['tiers'], 'tier1', 'name'),
            get_value(request['asset']['tiers'], 'tier1', 'external_id'),
            get_value(request['asset']['tiers'], 'tier2', 'id'),
            get_value(request['asset']['tiers'], 'tier2', 'name'),
            get_value(request['asset']['tiers'], 'tier2', 'external_id'),
            get_value(request['asset']['connection'], 'provider', 'id'),
            get_value(request['asset']['connection'], 'provider', 'name'),
            get_value(request['asset']['connection'], 'vendor', 'id'),
            get_value(request['asset']['connection'], 'vendor', 'name'),
            get_value(request['asset'], 'product', 'id'),
            get_value(request['asset'], 'product', 'name'),
            get_value(request, 'asset', 'id'),
            get_value(request, 'asset', 'external_id'),
            get_value(request['asset'], 'connection', 'type'),
            get_value(connection, 'hub', 'id') if 'hub' in connection else '',
            get_value(connection, 'hub', 'name') if 'hub' in connection else '',
            get_value(request, 'asset', 'status'),
            get_basic_value(request, 'reason'),
        )

        progress += 1
        progress_callback(progress, total)
예제 #8
0
def generate(client, parameters, progress_callback):
    product_rql = R().status.eq('active')

    if parameters.get('product') and parameters['product']['all'] is False:
        product_rql &= R().product.id.oneof(parameters['product']['choices'])

    assets = client.ns('subscriptions').assets.filter(product_rql)

    total = assets.count()
    progress = Progress(progress_callback, total)
    start_date = parameters['period']['after']
    end_date = parameters['period']['before']

    ex = futures.ThreadPoolExecutor(max_workers=10)

    wait_for = []
    for asset in assets:
        wait_for.append(
            ex.submit(get_record, client, asset, start_date, end_date,
                      progress))
    for future in futures.as_completed(wait_for):
        yield future.result()
def _get_requests(client, parameters):
    all_types = [
        'tiers_setup', 'inquiring', 'pending', 'approved', 'failed', 'draft'
    ]

    query = R()
    query &= R().created.ge(parameters['date']['after'])
    query &= R().created.le(parameters['date']['before'])

    if parameters.get('product') and parameters['product']['all'] is False:
        query &= R().asset.product.id.oneof(parameters['product']['choices'])
    if parameters.get('rr_type') and parameters['rr_type']['all'] is False:
        query &= R().type.oneof(parameters['rr_type']['choices'])
    if parameters.get('rr_status') and parameters['rr_status']['all'] is False:
        query &= R().status.oneof(parameters['rr_status']['choices'])
    else:
        query &= R().status.oneof(all_types)
    if parameters.get('mkp') and parameters['mkp']['all'] is False:
        query &= R().asset.marketplace.id.oneof(parameters['mkp']['choices'])

    return client.requests.filter(query)
예제 #10
0
def generate(client, parameters, progress_callback):
    all_status = ['draft', 'reviewing', 'deploying', 'completed', 'canceled']
    query = R()
    if parameters.get('date') and parameters['date']['after'] != '':
        query &= R().created.ge(parameters['date']['after'])
        query &= R().created.le(parameters['date']['before'])
    if parameters.get('product') and parameters['product']['all'] is False:
        query &= R().listing.product.id.oneof(parameters['product']['choices'])
    if parameters.get('mkp') and parameters['mkp']['all'] is False:
        query &= R().listing.contract.marketplace.id.oneof(
            parameters['mkp']['choices'])
    if parameters.get('rr_status') and parameters['rr_status']['all'] is False:
        query &= R().state.oneof(parameters['rr_status']['choices'])
    else:
        query &= R().state.oneof(all_status)
    requests = client.listing_requests.filter(query).order_by("-created")
    progress = 0
    total = requests.count()
    output = []
    today = datetime.today().strftime('%Y-%m-%d %H:%M:%S')

    for request in requests:
        yield (
            get_basic_value(request, 'id'),
            get_basic_value(request, 'type'),
            get_basic_value(request, 'state'),
            convert_to_datetime(get_basic_value(request, 'created')),
            convert_to_datetime(get_basic_value(request, 'updated')),
            today,
            get_value(request, 'listing', 'id'),
            get_value(request['listing'], 'contract', 'id'),
            get_value(request, 'product', 'id'),
            get_value(request, 'product', 'name'),
            get_value(request['listing'], 'provider', 'id'),
            get_value(request['listing'], 'provider', 'name'),
            get_value(request['listing'], 'vendor', 'id'),
            get_value(request['listing'], 'vendor', 'name'),
        )
        progress += 1
        progress_callback(progress, total)

    return output
예제 #11
0
def get_record(client, asset, start_date, end_date, progress):
    billable_status = ['approved', 'closed']
    rql = R().asset.id.eq(asset['id']) & R().status.oneof(billable_status) & (
        (R().start_date.ge(f'{start_date}') & R().start_date.lt(f'{end_date}'))
        | (R().end_date.ge(f'{start_date}') & R().end_date.lt(f'{end_date}')))
    usage_records = client.ns('usage').records.filter(rql)
    uf = []
    for record in usage_records:
        if record['usagefile']['id'] not in uf:
            uf.append(record['usagefile']['id'])
    progress.increment()
    return [
        get_basic_value(asset, 'id'),
        get_basic_value(asset, 'external_id'),
        get_basic_value(asset, 'status'),
        convert_to_datetime(asset['events']['created']['at']),
        convert_to_datetime(asset['events']['updated']['at']),
        get_value(asset['tiers'], 'customer', 'id'),
        get_value(asset['tiers'], 'customer', 'name'),
        get_value(asset['tiers'], 'customer', 'external_id'),
        get_value(asset['tiers'], 'tier1', 'id'),
        get_value(asset['tiers'], 'tier1', 'name'),
        get_value(asset['tiers'], 'tier1', 'external_id'),
        get_value(asset['tiers'], 'tier2', 'id'),
        get_value(asset['tiers'], 'tier2', 'name'),
        get_value(asset['tiers'], 'tier2', 'external_id'),
        get_value(asset['connection'], 'provider', 'id'),
        get_value(asset['connection'], 'provider', 'name'),
        get_value(asset['connection'], 'vendor', 'id'),
        get_value(asset['connection'], 'vendor', 'name'),
        get_value(asset, 'product', 'id'),
        get_value(asset, 'product', 'name'),
        get_value(asset['connection'], 'hub', 'id'),
        get_value(asset['connection'], 'hub', 'name'),
        len(uf), ', '.join(uf)
    ]
예제 #12
0
def generate(client, parameters, progress_callback):
    query = R()
    if parameters.get('date') and parameters['date']['after'] != '':
        query &= R().created.ge(parameters['date']['after'])
        query &= R().created.le(parameters['date']['before'])
    if parameters.get('mkp') and parameters['mkp']['all'] is False:
        query &= R().asset.marketplace.id.oneof(parameters['mkp']['choices'])
    if parameters.get('tier_type') and parameters['tier_type']['all'] is False:
        query &= R().scopes.oneof(parameters['tier_type']['choices'])

    marketplaces_list = client.marketplaces.all()
    marketplaces = {}
    for marketplace in marketplaces_list:
        marketplaces[marketplace['id']] = {
            'name': marketplace['owner']['name'],
            'id': marketplace['owner']['id'],
        }
    customers = client.ns('tier').accounts.filter(query).order_by(
        '-created').limit(1000)
    progress = 0
    total = customers.count()

    output = []

    def get_provider(mkp, prop):
        if not mkp or mkp == '-' or mkp not in marketplaces:  # pragma: no branch
            return '-'  # pragma: no cover
        return marketplaces[mkp][prop]

    def create_phone(pn):
        return f'{pn["country_code"]}{pn["area_code"]}{pn["phone_number"]}{pn["extension"]}'

    for customer in customers:
        try:
            customer_row = [
                get_basic_value(customer, 'id'),
                get_basic_value(customer, 'external_id'),
                get_basic_value(customer, 'environment'),
                'Yes' if 'customer' in customer['scopes'] else '-',
                'Yes' if 'tier1' in customer['scopes'] else '-',
                'Yes' if 'tier2' in customer['scopes'] else '-',
                get_provider(get_value(customer, 'marketplace', 'id'), 'id'),
                get_provider(get_value(customer, 'marketplace', 'id'), 'name'),
                get_value(customer, 'marketplace', 'id'),
                get_value(customer, 'marketplace', 'name'),
                get_basic_value(customer, 'name'),
                get_basic_value(customer, 'tax_id'),
            ]

            if parameters['full_contact_info'] == 'yes':
                customer_extended_info = client.ns('tier').accounts[
                    get_basic_value(customer, 'id')].get()

                contact = customer_extended_info['contact_info']
                customer_row_extended = [
                    get_basic_value(contact, 'address_line1'),
                    get_basic_value(contact, 'address_line2'),
                    get_basic_value(contact, 'city'),
                    get_basic_value(contact, 'state'),
                    get_basic_value(contact, 'postal_code'),
                    get_basic_value(contact, 'country'),
                    get_value(contact, 'contact', 'first_name'),
                    get_value(contact, 'contact', 'last_name'),
                    get_value(contact, 'contact', 'email'),
                    create_phone(contact['contact']['phone_number'])
                ]
            else:
                customer_row_extended = ['-'] * 10
            output.append(customer_row + customer_row_extended)

        except Exception:
            progress += 1
            progress_callback(progress, total)
            pass
        progress += 1
        progress_callback(progress, total)

    return output
예제 #13
0
    config_file = Utils.get_config_file()
    # apiEndpoint is the API End-point of Connect
    connect_api_url = config_file['connectApiEndpoint'],
    # apiKey is the API key for authorization created in Integrations menu of Connect
    connect_key = config_file['connectApiKey'],
    # Products are the list of IDs of the products which needs to be processed by this Processor
    client = ConnectClient(api_key=connect_key[0], endpoint=connect_api_url[0])

    # If the Product has parameters of scope 'Tier' then Tier use case implementation will be required.
    # Make sure the project has the Tier use case included during project creation
    # The Tier Config Requests (TCR) needs to be processed first and then the corresponding Fulfillment Requests
    if hasattr(project_manager, 'tier_fulfillment'):
        # Filter to fetch the Tier-Config-Request (TCR) for this product
        # The processor needs to process only the TCRs in Pending status

        query_tcr = R()
        query_tcr &= R().configuration.product.id.oneof(Globals.PRODUCTS)
        query_tcr &= R().configuration.connection.type.oneof(
            Globals.ENVIRONMENT)
        query_tcr &= R().status.oneof(['pending'])
        tc_requests = client.ns('tier').collection('config-requests').filter(
            query_tcr)
        # Process each TCR
        for tcr in tc_requests:
            project_manager.tier_fulfillment.TierConfiguration.process_request(
                tcr, client)

    # Filter to fetch all the subscription Fulfillment requests from Connect that need to be processed by this Processor
    query = R()
    query &= R().asset.product.id.oneof(Globals.PRODUCTS)
    query &= R().asset.connection.type.oneof(Globals.ENVIRONMENT)
예제 #14
0
def generate(client, parameters, progress_callback):
    all_types = ['tiers_setup', 'inquiring', 'pending', 'approved', 'failed']
    query = R()
    query &= R().events.created.at.ge(parameters['date']['after'])
    query &= R().events.created.at.le(parameters['date']['before'])
    if parameters.get('product') and parameters['product']['all'] is False:
        query &= R().product.id.oneof(parameters['product']['choices'])
    if parameters.get('mkp') and parameters['mkp']['all'] is False:
        query &= R().marketplace.id.oneof(parameters['mkp']['choices'])
    if parameters.get('rr_type') and parameters['rr_type']['all'] is False:
        query &= R().type.oneof(parameters['rr_type']['choices'])
    if parameters.get('rr_status') and parameters['rr_status']['all'] is False:
        query &= R().status.oneof(parameters['rr_status']['choices'])
    else:
        query &= R().status.oneof(all_types)

    requests = client.ns('tier').collection('config-requests').filter(query).order_by('-created')
    progress = 0
    total = requests.count()
    today = datetime.today().strftime('%Y-%m-%d %H:%M:%S')

    for request in requests:
        config = request['configuration']
        yield(
            get_basic_value(request, 'id'),
            get_basic_value(request, 'type'),
            convert_to_datetime(get_value(request['events'], 'created', 'at')),
            convert_to_datetime(get_value(request['events'], 'updated', 'at')),
            today,
            get_basic_value(request, 'status'),
            get_value(
                config,
                'connection',
                'type'
            ),
            get_value(request, 'configuration', 'id'),
            get_value(request, 'configuration', 'tier_level'),
            get_value(config, 'account', 'name'),
            get_value(config, 'account', 'external_id'),
            get_value(config, 'account', 'id'),
            get_value(request, 'parent_configuration', 'id'),
            get_value(request, 'parent_configuration', 'tier_level'),
            get_value(
                request['parent_configuration'],
                'account',
                'name'
            ) if 'parent_configuration' in request else '-',
            get_value(
                request['parent_configuration'],
                'account',
                'external_id'
            ) if 'parent_configuration' in request else '-',
            get_value(
                request['parent_configuration'],
                'account',
                'id'
            ) if 'parent_configuration' in request else '-',
            get_value(
                config['connection'],
                'provider',
                'id'
            ) if 'connection' in config else '-',
            get_value(
                config['connection'],
                'provider',
                'name'
            ) if 'connection' in config else '-',
            get_value(
                config['connection'],
                'vendor',
                'id'
            ) if 'connection' in config else '-',
            get_value(
                config['connection'],
                'vendor',
                'name'
            ) if 'connection' in config else '-',
            get_value(
                config,
                'product',
                'id'
            ),
            get_value(
                config,
                'product',
                'name'
            ),
            get_value(
                config['connection'],
                'hub',
                'id'
            ) if 'connection' in config else '-',
            get_value(
                config['connection'],
                'hub',
                'name'
            ) if 'connection' in config else '-',
            get_value(
                config,
                'contract',
                'id'
            ),
            get_value(
                config,
                'marketplace',
                'id'
            ),
            get_value(
                config,
                'marketplace',
                'name'
            ),
        )

        progress += 1
        progress_callback(progress, total)
 def _get_contracts(self):
     # Loads the distribution contracts to find the subscriptions with data to build the reports
     query = R()
     query &= R().type.oneof(['distribution'])
     query &= R().status.oneof(['active'])
     return self.client.collection("contracts").filter(query)
예제 #16
0
def generate(client, parameters, progress_callback):
    subscriptions_rql = R()
    if parameters.get("date"):
        subscriptions_rql &= R().events.created.at.ge(
            parameters['date']['after'])
        subscriptions_rql &= R().events.created.at.le(
            parameters['date']['before'])
    subscriptions_rql &= R().status.eq("approved")
    subscriptions_rql &= R().type.eq("vendor")
    for product in PRODUCTS_TO_SKIP:
        subscriptions_rql &= R().asset.product.id.ne(product)

    subscriptions = (client.ns('subscriptions').collection('requests').filter(
        subscriptions_rql).order_by("-events.created.at"))
    total_subscriptions = subscriptions.count()

    request_types = ["purchase", "change", "cancel"]
    requests_rql = R()
    if parameters.get("date"):
        requests_rql &= R().created.ge(parameters['date']['after'])
        requests_rql &= R().created.le(parameters['date']['before'])
    requests_rql &= R().status.eq("approved")
    requests_rql &= R().asset.connection.type.eq('production')
    for product in PRODUCTS_TO_SKIP:
        requests_rql &= R().asset.product.id.ne(product)
    requests_rql &= R().type.oneof(request_types)
    requests = client.requests.filter(requests_rql).order_by("-created")

    total_requests = requests.count()

    progress = Progress(progress_callback,
                        total_subscriptions + total_requests)

    ex = futures.ThreadPoolExecutor(max_workers=6, )

    wait_for = []
    for request in requests:
        wait_for.append(
            ex.submit(
                get_request_record,
                client,
                request,
                progress,
            ))
        progress.increment()

    for future in futures.as_completed(wait_for):
        results = future.result()
        for result in results:
            yield result

    wait_for = []
    for subscription in subscriptions:
        wait_for.append(
            ex.submit(
                get_subscription_record,
                client,
                subscription,
                progress,
            ))

    for future in futures.as_completed(wait_for):
        results = future.result()
        for result in results:
            yield result
예제 #17
0
def generate(client, parameters, progress_callback):
    """
    Extracts data from Connect using the ConnectClient instance
    and input parameters provided as arguments, applies
    required transformations (if any) and returns an iterator of rows
    that will be used to fill the Excel file.
    Each element returned by the iterator must be an iterator over
    the columns value.

    :param client: An instance of the CloudBlue Connect
                    client.
    :type client: cnct.ConnectClient
    :param parameters: Input parameters used to calculate the
                        resulting dataset.
    :type parameters: dict
    :param progress_callback: A function that accepts t
                                argument of type int that must
                                be invoked to notify the progress
                                of the report generation.
    :type progress_callback: func
    """
    all_types = ['tiers_setup', 'inquiring', 'pending', 'approved', 'failed', 'draft']
    query = R()
    query &= R().created.ge(parameters['date']['after'])
    query &= R().created.le(parameters['date']['before'])
    if parameters.get('product') and parameters['product']['all'] is False:
        query &= R().asset.product.id.oneof(parameters['product']['choices'])
    if parameters.get('rr_type') and parameters['rr_type']['all'] is False:
        query &= R().type.oneof(parameters['rr_type']['choices'])
    if parameters.get('rr_status') and parameters['rr_status']['all'] is False:
        query &= R().status.oneof(parameters['rr_status']['choices'])
    else:
        query &= R().status.oneof(all_types)
    if parameters.get('mkp') and parameters['mkp']['all'] is False:
        query &= R().asset.marketplace.id.oneof(parameters['mkp']['choices'])
    if parameters.get('hub') and parameters['hub']['all'] is False:
        query &= R().asset.connection.hub.id.oneof(parameters['hub']['choices'])

    requests = client.requests.filter(query)
    progress = 0
    total = requests.count()

    output = []
    today = datetime.today().strftime('%Y-%m-%d %H:%M:%S')

    for request in requests:
        connection = request['asset']['connection']
        for item in request['asset']['items']:
            output.append([
                get_basic_value(request, 'id'),
                get_basic_value(request, 'type'),
                convert_to_datetime(
                    get_basic_value(request, 'created')
                ),
                convert_to_datetime(
                    get_basic_value(request, 'updated')
                ),
                today,
                get_basic_value(item, 'global_id'),
                get_basic_value(item, 'display_name'),
                get_basic_value(item, 'item_type'),
                get_basic_value(item, 'type'),
                get_basic_value(item, 'mpn'),
                get_basic_value(item, 'period'),
                get_basic_value(item, 'quantity'),
                get_value(request['asset']['tiers'], 'customer', 'id'),
                get_value(request['asset']['tiers'], 'customer', 'name'),
                get_value(request['asset']['tiers'], 'customer', 'external_id'),
                get_value(request['asset']['tiers'], 'tier1', 'id'),
                get_value(request['asset']['tiers'], 'tier1', 'name'),
                get_value(request['asset']['tiers'], 'tier1', 'external_id'),
                get_value(request['asset']['tiers'], 'tier2', 'id'),
                get_value(request['asset']['tiers'], 'tier2', 'name'),
                get_value(request['asset']['tiers'], 'tier2', 'external_id'),
                get_value(request['asset']['connection'], 'provider', 'id'),
                get_value(request['asset']['connection'], 'provider', 'name'),
                get_value(request['asset']['connection'], 'vendor', 'id'),
                get_value(request['asset']['connection'], 'vendor', 'name'),
                get_value(request['asset'], 'product', 'id'),
                get_value(request['asset'], 'product', 'name'),
                get_value(request, 'asset', 'id'),
                get_value(request, 'asset', 'external_id'),
                get_value(request['asset'], 'connection', 'type'),
                get_value(connection, 'hub', 'id') if 'hub' in connection else '',
                get_value(connection, 'hub', 'name') if 'hub' in connection else '',
                get_value(request, 'asset', 'status'),
            ])
        progress += 1
        progress_callback(progress, total)

    return output
예제 #18
0
def generate(client, parameters, progress_callback):
    query = R()
    query &= R().created.ge(parameters['date']['after'])
    query &= R().created.le(parameters['date']['before'])
    if parameters.get('product') and parameters['product']['all'] is False:
        query &= R().asset.product.id.oneof(parameters['product']['choices'])
    if parameters.get('mkp') and parameters['mkp']['all'] is False:
        query &= R().asset.marketplace.id.oneof(parameters['mkp']['choices'])
    if parameters.get('hub') and parameters['hub']['all'] is False:
        query &= R().asset.connection.hub.id.oneof(
            parameters['hub']['choices'])

    requests = client.ns('subscriptions').requests.filter(query)
    progress = 0
    total = requests.count()
    output = []
    for request in requests:
        connection = request['asset']['connection']
        for item in request['items']:
            output.append([
                request['id'],
                convert_to_datetime(request['period']['from']),
                convert_to_datetime(request['period']['to']),
                get_basic_value(request['period'], 'delta'),
                get_basic_value(request['period'], 'uom'),
                get_basic_value(item['billing'], 'cycle_number'),
                get_basic_value(item, 'global_id'),
                get_basic_value(item, 'display_name'),
                get_basic_value(item, 'item_type'),
                get_basic_value(item, 'type'),
                get_basic_value(item, 'mpn'),
                get_basic_value(item, 'period'),
                get_basic_value(item, 'quantity'),
                get_value(request['asset']['tiers'], 'customer', 'id'),
                get_value(request['asset']['tiers'], 'customer', 'name'),
                get_value(request['asset']['tiers'], 'customer',
                          'external_id'),
                get_value(request['asset']['tiers'], 'tier1', 'id'),
                get_value(request['asset']['tiers'], 'tier1', 'name'),
                get_value(request['asset']['tiers'], 'tier1', 'external_id'),
                get_value(request['asset']['tiers'], 'tier2', 'id'),
                get_value(request['asset']['tiers'], 'tier2', 'name'),
                get_value(request['asset']['tiers'], 'tier2', 'external_id'),
                get_value(request['asset']['connection'], 'provider', 'id'),
                get_value(request['asset']['connection'], 'provider', 'name'),
                get_value(request['asset']['connection'], 'vendor', 'id'),
                get_value(request['asset']['connection'], 'vendor', 'name'),
                get_value(request['asset'], 'product', 'id'),
                get_value(request['asset'], 'product', 'name'),
                get_value(request, 'asset', 'id'),
                get_value(request, 'asset', 'external_id'),
                get_value(request, 'asset', 'status'),
                get_value(request['asset'], 'connection', 'type'),
                get_value(connection, 'hub', 'id')
                if 'hub' in connection else '',
                get_value(connection, 'hub', 'name')
                if 'hub' in connection else '',
            ])
        progress += 1
        progress_callback(progress, total)

    return output
예제 #19
0
def generate(client, parameters, progress_callback):
    warm_up_tcs(client, parameters['products']['choices'])
    subscriptions_rql = R()
    if not parameters.get("products") or len(
            parameters['products']['choices']) < 1:
        raise RuntimeError("AWS products was not selected")
    if parameters.get("date"):
        subscriptions_rql &= R().events.created.at.ge(
            parameters['date']['after'])
        subscriptions_rql &= R().events.created.at.le(
            parameters['date']['before'])
    subscriptions_rql &= R().product.id.oneof(
        parameters['products']['choices'])
    subscriptions_rql &= R().status.ne('draft')
    subscriptions = client.assets.filter(subscriptions_rql)
    total_subscriptions = subscriptions.count()
    progress = 0
    for subscription in subscriptions:
        yield (
            subscription['id'],
            subscription.get('external_id', "-"),
            subscription['status'],
            subscription['marketplace']['name'],
            subscription['product']['id'],
            convert_to_datetime(subscription['events']['created']['at']),
            get_asset_parameter(subscription, "awsAccountId"),
            get_value(subscription['tiers'], "customer", "external_id"),
            get_value(subscription['tiers'], "customer", "name"),
            get_value(subscription['tiers']["customer"], "contact_info",
                      "address_line1"),
            get_value(subscription['tiers']["customer"], "contact_info",
                      "address_line2"),
            get_value(subscription['tiers']["customer"], "contact_info",
                      "city"),
            get_value(subscription['tiers']["customer"], "contact_info",
                      "state"),
            get_value(subscription['tiers']["customer"], "contact_info",
                      "postal_code"),
            get_value(subscription['tiers']["customer"], "contact_info",
                      "country"),
            get_value(subscription['tiers']["customer"]["contact_info"],
                      "contact", "email"),
            get_asset_parameter(subscription, "isGovernmentEntity"),
            get_asset_parameter(subscription, "useAccountFor"),
            get_value(subscription['tiers'], "tier1", "external_id"),
            get_value(subscription['tiers'], "tier1", "name"),
            get_value(subscription['tiers']["tier1"], "contact_info",
                      "address_line1"),
            get_value(subscription['tiers']["tier1"], "contact_info",
                      "address_line2"),
            get_value(subscription['tiers']["tier1"], "contact_info", "city"),
            get_value(subscription['tiers']["tier1"], "contact_info", "state"),
            get_value(subscription['tiers']["tier1"], "contact_info",
                      "postal_code"),
            get_value(subscription['tiers']["tier1"], "contact_info",
                      "country"),
            get_value(subscription['tiers']["tier1"]["contact_info"],
                      "contact", "email"),
            # get_aws_mpn(client, get_value(subscription['tiers'], "tier1", 'id'), subscription['product']['id'])
            get_awsmpn(get_value(subscription['tiers'], "tier1", 'id'),
                       subscription['product']['id']))
        progress += 1
        progress_callback(progress, total_subscriptions)
예제 #20
0
def generate(
    client=None,
    parameters=None,
    progress_callback=None,
    renderer_type=None,
    extra_context_callback=None,
):
    subscriptions_rql = R()

    products = [
        'PRD-814-505-018', 'PRD-561-716-033', 'PRD-275-843-418',
        'PRD-812-485-361', 'PRD-587-782-348', 'PRD-102-273-313',
        'PRD-376-475-231'
    ]

    if parameters.get("date"):
        subscriptions_rql &= R().events.created.at.ge(
            parameters['date']['after'])
        subscriptions_rql &= R().events.created.at.le(
            parameters['date']['before'])
    subscriptions_rql &= R().status.eq("approved")
    subscriptions_rql &= R().type.eq("vendor")
    subscriptions_rql &= R().asset.product.id.oneof(products)

    subscriptions = (client.ns('subscriptions').collection('requests').filter(
        subscriptions_rql).order_by("-events.created.at"))
    total_subscriptions = subscriptions.count()

    request_types = ["purchase", "change", "cancel"]
    requests_rql = R()
    if parameters.get("date"):
        requests_rql &= R().created.ge(parameters['date']['after'])
        requests_rql &= R().created.le(parameters['date']['before'])
    requests_rql &= R().status.eq("approved")
    requests_rql &= R().asset.connection.type.eq('production')
    requests_rql &= R().asset.product.id.oneof(products)
    requests_rql &= R().type.oneof(request_types)
    requests = client.requests.filter(requests_rql).order_by("-created")

    total_requests = requests.count()

    progress = Progress(progress_callback,
                        total_subscriptions + total_requests)

    ex = futures.ThreadPoolExecutor()

    if renderer_type == 'csv':
        yield HEADERS

    wait_for = []
    for request in requests:
        wait_for.append(
            ex.submit(
                get_request_record,
                client,
                request,
                progress,
            ))
        progress.increment()

    for future in futures.as_completed(wait_for):
        results = future.result()
        for result in results:
            if renderer_type == 'json':
                yield {
                    HEADERS[idx].replace(' ', '_').lower(): value
                    for idx, value in enumerate(result)
                }
            else:
                yield result

    wait_for = []
    for subscription in subscriptions:
        wait_for.append(
            ex.submit(
                get_subscription_record,
                client,
                subscription,
                progress,
            ))
        progress.increment()

    for future in futures.as_completed(wait_for):
        results = future.result()
        for result in results:
            if renderer_type == 'json':
                yield {
                    HEADERS[idx].replace(' ', '_').lower(): value
                    for idx, value in enumerate(result)
                }
            else:
                yield result
예제 #21
0
def generate(client, parameters, progress_callback):
    subscriptions_rql = R()
    if not parameters.get("products") or len(
            parameters['products']['choices']) < 1:
        raise RuntimeError("Microsoft products was not selected")

    if parameters.get("date"):
        subscriptions_rql &= R().events.created.at.ge(
            parameters['date']['after'])
        subscriptions_rql &= R().events.created.at.le(
            parameters['date']['before'])
    subscriptions_rql &= R().status.eq("approved")
    subscriptions_rql &= R().type.eq("vendor")
    subscriptions_rql &= R().asset.product.id.oneof(
        parameters['products']['choices'])

    subscriptions = (client.ns('subscriptions').collection('requests').filter(
        subscriptions_rql).order_by("-events.created.at"))
    total_subscriptions = subscriptions.count()

    request_types = ["purchase", "change", "cancel"]
    requests_rql = R()
    if parameters.get("date"):
        requests_rql &= R().created.ge(parameters['date']['after'])
        requests_rql &= R().created.le(parameters['date']['before'])
    requests_rql &= R().status.eq("approved")
    requests_rql &= R().asset.connection.type.eq('production')
    requests_rql &= R().asset.product.id.oneof(
        parameters['products']['choices'])
    requests_rql &= R().type.oneof(request_types)
    requests = client.requests.filter(requests_rql).order_by("-created")

    total_requests = requests.count()

    progress = Progress(progress_callback,
                        total_subscriptions + total_requests)

    ex = futures.ThreadPoolExecutor()

    wait_for = []
    for request in requests:
        wait_for.append(
            ex.submit(
                get_request_record,
                client,
                request,
                progress,
            ))

    for future in futures.as_completed(wait_for):
        results = future.result()
        for result in results:
            yield result

    wait_for = []
    for subscription in subscriptions:
        wait_for.append(
            ex.submit(
                get_subscription_record,
                client,
                subscription,
                progress,
            ))

    for future in futures.as_completed(wait_for):
        results = future.result()
        for result in results:
            yield result