Ejemplo n.º 1
0
    def run(self):
        org_name = self.get_option('org')
        env_name = self.get_option('environment')
        dist_name = self.get_option('name')
        dist_uuid = self.get_option('uuid')

        if dist_uuid:
            self.printer.set_header(_("Distributor Information [ %s ]") % dist_uuid)
        elif env_name is None:
            self.printer.set_header(_("Distributor Information For Org [ %s ]") % org_name)
        else:
            self.printer.set_header(_("Distributor Information For Environment [ %(env)s ] in Org [ %(org)s ]") \
                % {'env':env_name, 'org':org_name})

        # get distributor details
        distributor = get_distributor(org_name, dist_name, env_name, dist_uuid)

        custom_info_api = CustomInfoAPI()
        custom_info = custom_info_api.get_custom_info("distributor", distributor['id'])
        distributor['custom_info'] = stringify_custom_info(custom_info)

        if 'environment' in distributor:
            distributor['environment'] = distributor['environment']['name']

        batch_add_columns(self.printer, {'name': _("Name")}, {'version': _("Version")},
            {'uuid': _("UUID")}, {'environment': _("Environment")})
        self.printer.add_column('created_at', _("Created"), formatter=format_date)
        self.printer.add_column('updated_at', _("Last Updated"), formatter=format_date)
        self.printer.add_column('description', _("Description"), multiline=True)
        self.printer.add_column('custom_info', _("Custom Info"), multiline=True, show_with=printer.VerboseStrategy)

        self.printer.print_item(distributor)

        return os.EX_OK
Ejemplo n.º 2
0
    def run(self):
        org_name = self.get_option('org')
        env_name = self.get_option('environment')
        dist_name = self.get_option('name')
        new_name = self.get_option('new_name')
        new_environment_name = self.get_option('new_environment')
        new_description = self.get_option('description')
        dist_uuid = self.get_option('uuid')

        distributor = get_distributor(org_name, dist_name, env_name, dist_uuid)
        new_environment = get_environment(org_name, new_environment_name)

        updates = {}
        if new_name:
            updates['name'] = new_name
        if new_description:
            updates['description'] = new_description
        if new_environment_name:
            new_environment = get_environment(org_name, new_environment_name)
            updates['environment_id'] = new_environment['id']

        response = self.api.update(distributor['uuid'], updates)

        test_record(
            response,
            _("Successfully updated distributor [ %s ]") % distributor['name'],
            _("Could not update distributor [ %s ]") % distributor['name'])
    def run(self):
        org_name = self.get_option('org')
        env_name = self.get_option('environment')
        dist_name = self.get_option('name')
        dist_uuid = self.get_option('uuid')
        keyname = self.get_option('keyname')

        distributor = get_distributor(org_name, dist_name, env_name, dist_uuid)

        custom_info_api = CustomInfoAPI()

        response = custom_info_api.remove_custom_info("distributor",
                                                      distributor['id'],
                                                      keyname)

        ident = dist_uuid if dist_uuid else dist_name

        if len(response) == 0:
            print _(
                "Successfully removed Custom Information from Distributor [ %s ]"
            ) % ident
        else:
            print _(
                "Could not remove Custom Information from Distributor [ %s ]"
            ) % ident
Ejemplo n.º 4
0
    def run(self):
        org_name = self.get_option('org')
        env_name = self.get_option('environment')
        dist_name = self.get_option('name')
        new_name = self.get_option('new_name')
        new_environment_name = self.get_option('new_environment')
        new_description = self.get_option('description')
        dist_uuid = self.get_option('uuid')

        distributor = get_distributor(org_name, dist_name, env_name, dist_uuid)
        new_environment = get_environment(org_name, new_environment_name)

        updates = {}
        if new_name:
            updates['name'] = new_name
        if new_description:
            updates['description'] = new_description
        if new_environment_name:
            new_environment = get_environment(org_name, new_environment_name)
            updates['environment_id'] = new_environment['id']

        response = self.api.update(distributor['uuid'], updates)

        test_record(response,
            _("Successfully updated distributor [ %s ]") % distributor['name'],
            _("Could not update distributor [ %s ]") % distributor['name']
        )
Ejemplo n.º 5
0
    def run(self):
        name = self.get_option('name')
        org = self.get_option('org')
        pool = self.get_option('pool')
        qty = self.get_option('quantity') or 1
        dist_uuid = self.get_option('uuid')

        display_name = name or dist_uuid

        distributor = get_distributor(org, name, None, dist_uuid)

        self.api.subscribe(distributor['uuid'], pool, qty)
        print _("Successfully attached subscription to Distributor [ %s ]") % display_name
        return os.EX_OK
Ejemplo n.º 6
0
    def run(self):
        name = self.get_option('name')
        org = self.get_option('org')
        pool = self.get_option('pool')
        qty = self.get_option('quantity') or 1
        dist_uuid = self.get_option('uuid')

        display_name = name or dist_uuid

        distributor = get_distributor(org, name, None, dist_uuid)

        self.api.subscribe(distributor['uuid'], pool, qty)
        print _("Successfully attached subscription to Distributor [ %s ]"
                ) % display_name
        return os.EX_OK
Ejemplo n.º 7
0
    def run(self):
        name = self.get_option('name')
        org = self.get_option('org')
        env_name = self.get_option('environment')
        dist_uuid = self.get_option('uuid')

        display_name = name or dist_uuid

        try:
            distributor = get_distributor(org, name, env_name, dist_uuid)

        except ServerRequestError, e:
            if e[0] == 404:
                return os.EX_DATAERR
            else:
                raise
Ejemplo n.º 8
0
    def run(self):
        name = self.get_option('name')
        org = self.get_option('org')
        env_name = self.get_option('environment')
        dist_uuid = self.get_option('uuid')

        display_name = name or dist_uuid

        try:
            distributor = get_distributor(org, name, env_name, dist_uuid)

        except ServerRequestError, e:
            if e[0] == 404:
                return os.EX_DATAERR
            else:
                raise
Ejemplo n.º 9
0
    def run(self):
        org_name = self.get_option('org')
        env_name = self.get_option('environment')
        dist_name = self.get_option('name')
        dist_uuid = self.get_option('uuid')

        if dist_uuid:
            self.printer.set_header(
                _("Distributor Information [ %s ]") % dist_uuid)
        elif env_name is None:
            self.printer.set_header(
                _("Distributor Information For Org [ %s ]") % org_name)
        else:
            self.printer.set_header(_("Distributor Information For Environment [ %(env)s ] in Org [ %(org)s ]") \
                % {'env':env_name, 'org':org_name})

        # get distributor details
        distributor = get_distributor(org_name, dist_name, env_name, dist_uuid)

        custom_info_api = CustomInfoAPI()
        custom_info = custom_info_api.get_custom_info("distributor",
                                                      distributor['id'])
        distributor['custom_info'] = stringify_custom_info(custom_info)

        if 'environment' in distributor:
            distributor['environment'] = distributor['environment']['name']

        batch_add_columns(self.printer, {'name': _("Name")}, \
            {'uuid': _("UUID")}, {'environment': _("Environment")})
        self.printer.add_column('created_at',
                                _("Created"),
                                formatter=format_date)
        self.printer.add_column('updated_at',
                                _("Last Updated"),
                                formatter=format_date)
        self.printer.add_column('description',
                                _("Description"),
                                multiline=True)
        self.printer.add_column('custom_info',
                                _("Custom Info"),
                                multiline=True,
                                show_with=printer.VerboseStrategy)

        self.printer.print_item(distributor)

        return os.EX_OK
Ejemplo n.º 10
0
    def run(self):
        org_name = self.get_option('org')
        env_name = self.get_option('environment')
        dist_name = self.get_option('name')
        dist_uuid = self.get_option('uuid')
        keyname = self.get_option('keyname')

        distributor = get_distributor(org_name, dist_name, env_name, dist_uuid)

        custom_info_api = CustomInfoAPI()

        response = custom_info_api.remove_custom_info("distributor", distributor['id'], keyname)

        ident = dist_uuid if dist_uuid else dist_name

        if len(response) == 0:
            print _("Successfully removed Custom Information from Distributor [ %s ]") % ident
        else:
            print _("Could not remove Custom Information from Distributor [ %s ]") % ident
Ejemplo n.º 11
0
    def run(self):
        name = self.get_option('name')
        org = self.get_option('org')
        entitlement = self.get_option('entitlement')
        serial = self.get_option('serial')
        all_entitlements = self.get_option('all')
        uuid = self.get_option('uuid')

        display_name = name or uuid

        if not uuid:
            uuid = get_distributor(org, name)['uuid']

        if all_entitlements: #unsubscribe from all
            self.api.unsubscribe_all(uuid)
        elif serial: # unsubscribe from cert
            self.api.unsubscribe_by_serial(uuid, serial)
        elif entitlement: # unsubscribe from entitlement
            self.api.unsubscribe(uuid, entitlement)
        print _("Successfully removed subscription from Distributor [ %s ]") % display_name

        return os.EX_OK
Ejemplo n.º 12
0
    def run(self):
        org_name = self.get_option('org')
        env_name = self.get_option('environment')
        dist_name = self.get_option('name')
        dist_uuid = self.get_option('uuid')
        keyname = self.get_option('keyname')
        new_value = self.get_option('value')

        distributor = get_distributor(org_name, dist_name, env_name, dist_uuid)

        custom_info_api = CustomInfoAPI()

        response = custom_info_api.update_custom_info("distributor", distributor['id'], keyname, new_value)

        ident = dist_uuid if dist_uuid else dist_name

        test_record(response,
            _("Successfully updated Custom Information [ %(keyname)s ] for Distributor [ %(ident)s ]") \
                % {'keyname':keyname, 'ident':ident},
            _("Could not update Custom Information [ %(keyname)s ] for Distributor [ %(ident)s ]") \
                % {'keyname':keyname, 'ident':ident}
        )
Ejemplo n.º 13
0
    def run(self):
        org_name = self.get_option('org')
        env_name = self.get_option("environment")
        dist_name = self.get_option('name')
        dist_uuid = self.get_option('uuid')
        keyname = self.get_option('keyname')
        value = self.get_option('value')

        distributor = get_distributor(org_name, dist_name, env_name, dist_uuid)

        custom_info_api = CustomInfoAPI()

        response = custom_info_api.add_custom_info("distributor", distributor['id'], keyname, value)

        ident = dist_uuid if dist_uuid else dist_name

        test_record(response,
            _("Successfully added Custom Information [ %(keyname)s : %(value)s ] to Distributor [ %(ident)s ]") \
                % {'keyname':keyname, 'value':value, 'ident':ident},
            _("Could not add Custom Information [ %(keyname)s : %(value)s ] to Distributor [ %(ident)s ]") \
                % {'keyname':keyname, 'value':value, 'ident':ident}
        )
Ejemplo n.º 14
0
    def run(self):
        name = self.get_option('name')
        org = self.get_option('org')
        entitlement = self.get_option('entitlement')
        serial = self.get_option('serial')
        all_entitlements = self.get_option('all')
        uuid = self.get_option('uuid')

        display_name = name or uuid

        if not uuid:
            uuid = get_distributor(org, name)['uuid']

        if all_entitlements:  #unsubscribe from all
            self.api.unsubscribe_all(uuid)
        elif serial:  # unsubscribe from cert
            self.api.unsubscribe_by_serial(uuid, serial)
        elif entitlement:  # unsubscribe from entitlement
            self.api.unsubscribe(uuid, entitlement)
        print _("Successfully removed subscription from Distributor [ %s ]"
                ) % display_name

        return os.EX_OK
Ejemplo n.º 15
0
    def run(self):
        org_name = self.get_option('org')
        env_name = self.get_option("environment")
        dist_name = self.get_option('name')
        dist_uuid = self.get_option('uuid')
        keyname = self.get_option('keyname')
        value = self.get_option('value')

        distributor = get_distributor(org_name, dist_name, env_name, dist_uuid)

        custom_info_api = CustomInfoAPI()

        response = custom_info_api.add_custom_info("distributor",
                                                   distributor['id'], keyname,
                                                   value)

        ident = dist_uuid if dist_uuid else dist_name

        test_record(response,
            _("Successfully added Custom Information [ %(keyname)s : %(value)s ] to Distributor [ %(ident)s ]") \
                % {'keyname':keyname, 'value':value, 'ident':ident},
            _("Could not add Custom Information [ %(keyname)s : %(value)s ] to Distributor [ %(ident)s ]") \
                % {'keyname':keyname, 'value':value, 'ident':ident}
        )
Ejemplo n.º 16
0
    def run(self):
        org_name = self.get_option('org')
        env_name = self.get_option('environment')
        dist_name = self.get_option('name')
        dist_uuid = self.get_option('uuid')
        keyname = self.get_option('keyname')
        new_value = self.get_option('value')

        distributor = get_distributor(org_name, dist_name, env_name, dist_uuid)

        custom_info_api = CustomInfoAPI()

        response = custom_info_api.update_custom_info("distributor",
                                                      distributor['id'],
                                                      keyname, new_value)

        ident = dist_uuid if dist_uuid else dist_name

        test_record(response,
            _("Successfully updated Custom Information [ %(keyname)s ] for Distributor [ %(ident)s ]") \
                % {'keyname':keyname, 'ident':ident},
            _("Could not update Custom Information [ %(keyname)s ] for Distributor [ %(ident)s ]") \
                % {'keyname':keyname, 'ident':ident}
        )
Ejemplo n.º 17
0
    def run(self):
        name = self.get_option('name')
        org = self.get_option('org')
        available = self.get_option('available')
        uuid = self.get_option('uuid')

        display_name = name or uuid

        if not uuid:
            uuid = get_distributor(org, name)['uuid']

        self.printer.set_strategy(VerboseStrategy())
        if not available:
            # listing current subscriptions
            result = self.api.subscriptions(uuid)
            if result == None or len(result['entitlements']) == 0:
                print _("No Subscriptions found for Distributor [ %(display_name)s ] in Org [ %(org)s ]") \
                    % {'display_name':display_name, 'org':org}
                return os.EX_OK

            def entitlements():
                for entitlement in result['entitlements']:
                    entitlement_ext = entitlement.copy()
                    provided_products = ', '.join([e['name'] for e in entitlement_ext['providedProducts']])
                    if provided_products:
                        entitlement_ext['providedProductsFormatted'] = _('Not Applicable')
                    else:
                        entitlement_ext['providedProductsFormatted'] = provided_products
                    serial_ids = ', '.join([u_str(s['id']) for s in entitlement_ext['serials']])
                    entitlement_ext['serialIds'] = serial_ids
                    yield entitlement_ext

            self.printer.set_header(_("Current Subscriptions for Distributor [ %s ]") % display_name)
            self.printer.add_column('entitlementId', _("Subscription ID"))
            self.printer.add_column('serialIds', _('Serial ID'))
            batch_add_columns(self.printer, {'poolName': _("Pool Name")}, \
                {'expires': _("Expires")}, {'consumed': _("Consumed")}, \
                {'quantity': _("Quantity")}, {'sla': _("SLA")}, {'contractNumber': _("Contract Number")})
            self.printer.add_column('providedProductsFormatted', _('Provided Products'))
            self.printer.print_items(entitlements())
        else:
            # listing available pools
            result = self.api.available_pools(uuid)

            if result == None or len(result) == 0:
                print _("No Pools found for Distributor [ %(display_name)s ] in Org [ %(org)s ]") \
                    % {'display_name':display_name, 'org':org}
                return os.EX_OK

            def available_pools():
                for pool in result['pools']:
                    pool_ext = pool.copy()
                    provided_products = ', '.join([p['productName'] for p in pool_ext['providedProducts']])
                    if provided_products:
                        pool_ext['providedProductsFormatted'] = _('Not Applicable')
                    else:
                        pool_ext['providedProductsFormatted'] = provided_products

                    if pool_ext['quantity'] == -1:
                        pool_ext['quantity'] = _('Unlimited')

                    # Make the productAttributes easier to access
                    for productAttribute in pool['productAttributes']:
                        pool_ext['attr_' + productAttribute['name']] = productAttribute['value']
                    yield pool_ext

            self.printer.set_header(_("Available Subscriptions for Distributor [ %s ]") % display_name)

            self.printer.add_column('id', _("ID"))
            self.printer.add_column('productName', _("Name"))
            batch_add_columns(self.printer, {'endDate': _("End Date")}, \
                {'consumed': _("Consumed")}, {'quantity': _("Quantity")}, {'sockets': _("Sockets")})
            self.printer.add_column('attr_stacking_id', _("Stacking ID"))
            self.printer.add_column('attr_multi-entitlement', _("Multi-entitlement"))
            self.printer.add_column('providedProductsFormatted', _("Provided products"))
            self.printer.print_items(available_pools())

        return os.EX_OK
Ejemplo n.º 18
0
    def run(self):
        name = self.get_option('name')
        org = self.get_option('org')
        available = self.get_option('available')
        uuid = self.get_option('uuid')

        display_name = name or uuid

        if not uuid:
            uuid = get_distributor(org, name)['uuid']

        self.printer.set_strategy(VerboseStrategy())
        if not available:
            # listing current subscriptions
            result = self.api.subscriptions(uuid)
            if result == None or len(result['entitlements']) == 0:
                print _("No Subscriptions found for Distributor [ %(display_name)s ] in Org [ %(org)s ]") \
                    % {'display_name':display_name, 'org':org}
                return os.EX_OK

            def entitlements():
                for entitlement in result['entitlements']:
                    entitlement_ext = entitlement.copy()
                    provided_products = ', '.join([
                        e['name'] for e in entitlement_ext['providedProducts']
                    ])
                    if provided_products:
                        entitlement_ext['providedProductsFormatted'] = _(
                            'Not Applicable')
                    else:
                        entitlement_ext[
                            'providedProductsFormatted'] = provided_products
                    serial_ids = ', '.join(
                        [u_str(s['id']) for s in entitlement_ext['serials']])
                    entitlement_ext['serialIds'] = serial_ids
                    yield entitlement_ext

            self.printer.set_header(
                _("Current Subscriptions for Distributor [ %s ]") %
                display_name)
            self.printer.add_column('entitlementId', _("Subscription ID"))
            self.printer.add_column('serialIds', _('Serial ID'))
            batch_add_columns(self.printer, {'poolName': _("Pool Name")}, \
                {'expires': _("Expires")}, {'consumed': _("Consumed")}, \
                {'quantity': _("Quantity")}, {'sla': _("SLA")}, {'contractNumber': _("Contract Number")})
            self.printer.add_column('providedProductsFormatted',
                                    _('Provided Products'))
            self.printer.print_items(entitlements())
        else:
            # listing available pools
            result = self.api.available_pools(uuid)

            if result == None or len(result) == 0:
                print _("No Pools found for Distributor [ %(display_name)s ] in Org [ %(org)s ]") \
                    % {'display_name':display_name, 'org':org}
                return os.EX_OK

            def available_pools():
                for pool in result['pools']:
                    pool_ext = pool.copy()
                    provided_products = ', '.join([
                        p['productName'] for p in pool_ext['providedProducts']
                    ])
                    if provided_products:
                        pool_ext['providedProductsFormatted'] = _(
                            'Not Applicable')
                    else:
                        pool_ext[
                            'providedProductsFormatted'] = provided_products

                    if pool_ext['quantity'] == -1:
                        pool_ext['quantity'] = _('Unlimited')

                    # Make the productAttributes easier to access
                    for productAttribute in pool['productAttributes']:
                        pool_ext['attr_' +
                                 productAttribute['name']] = productAttribute[
                                     'value']
                    yield pool_ext

            self.printer.set_header(
                _("Available Subscriptions for Distributor [ %s ]") %
                display_name)

            self.printer.add_column('id', _("ID"))
            self.printer.add_column('productName', _("Name"))
            batch_add_columns(self.printer, {'endDate': _("End Date")}, \
                {'consumed': _("Consumed")}, {'quantity': _("Quantity")}, {'sockets': _("Sockets")})
            self.printer.add_column('attr_stacking_id', _("Stacking ID"))
            self.printer.add_column('attr_multi-entitlement',
                                    _("Multi-entitlement"))
            self.printer.add_column('providedProductsFormatted',
                                    _("Provided products"))
            self.printer.print_items(available_pools())

        return os.EX_OK