Beispiel #1
0
def get_cv_definition(org_name, def_label=None, def_name=None, def_id=None):
    cvd_api = ContentViewDefinitionAPI()

    cvds = cvd_api.cvd_by_label_or_name_or_id(org_name, def_label, def_name,
            def_id)

    if len(cvds) > 1:
        raise ApiDataError(_("More than 1 definition found with name, " \
                "recommend using label or id. These may be retrieved using " \
                "the 'content definition list' command"))
    elif len(cvds) < 1:
        raise ApiDataError(_("Could not find content view definition [ %(a)s ]" \
                " within organization [ %(b)s ]") %
                ({"a": (def_label or def_id or def_name), "b": org_name}))

    return cvds[0]
Beispiel #2
0
    def identify_product(self, cvd, product_name, product_label, product_id):
        org_name = self.get_option('org')
        cvd_api = ContentViewDefinitionAPI()
        cvd_products = cvd_api.all_products(org_name, cvd["id"])

        products = [prod for prod in cvd_products if prod["id"] == product_id \
                             or prod["name"] == product_name or prod["label"] == product_label]

        if len(products) > 1:
            raise ApiDataError(_("More than 1 product found with the name or label provided, "\
                                 "recommend using product id.  The product id may be retrieved "\
                                 "using the 'product list' command."))
        elif len(products) == 0:
            raise ApiDataError(_("Could not find product [ %s ] within organization [ %s ] and definition [%s] ") %
                               ((product_name or product_label or product_id), org_name, cvd["name"]))

        return products[0]
 def __init__(self):
     super(ContentViewDefinitionAction, self).__init__()
     self.api = ContentViewDefinitionAPI()
class ContentViewDefinition():
    task_api = TaskStatusAPI()
    api = ContentViewDefinitionAPI()

    def create_content_view_definition(self,
                                       org,
                                       name=None,
                                       label=None,
                                       description=None,
                                       composite=False):

        if name is None:
            name = generate_name(8)

        if label is None:
            label = "label-%s" % name.lower()

        if description is None:
            description = "Created on %s" % datetime.datetime.now().strftime(
                "%Y-%m-%d-%H-%M-%S")

        return self.api.create(org['label'], name, label, description,
                               composite)

    def delete_content_view_definition(self, cvdId):
        return self.api.delete(cvdId)

    def content_view_definition(self, org, cvdId):
        return self.api.show(org['label'], cvdId)

    def content_view_definitions_by_org(self, org):
        return self.api.content_view_definitions_by_org(org['label'])

    def publish(self, org, cvdId, name=None, label=None, description=None):

        if name is None:
            name = generate_name(8)

        if label is None:
            label = "label-%s" % name.lower()

        if description is None:
            description = "Published on %s" % datetime.datetime.now().strftime(
                "%Y-%m-%d-%H-%M-%S")

        ptask = self.api.publish(org['label'], cvdId, name, label, description)

        task = self.task_api.status(ptask['uuid'])
        while task['state'] != 'finished':
            print "Publishing content view description %s" % name
            task = self.task_api.status(ptask['uuid'])

    def clone(self, org, cvdId, name=None, label=None, description=None):

        if name is None:
            name = generate_name(8)

        if label is None:
            label = "label-%s" % name.lower()

        if description is None:
            description = "Cloned on %s" % datetime.datetime.now().strftime(
                "%Y-%m-%d-%H-%M-%S")

        return self.api.clone(org['label'], cvdId, name, label, description)

    def update_products(self, org, cvdId, prd):
        return self.api.update_products(org['label'], cvdId, [prd['id']])

    def products(self, org, cvdId):
        return self.api.products(org['label'], cvdId)