class Product(): api = ProductAPI() def create_product(self, prv, name=None, label=None, description='Built by API', gpgkey=None): if name is None: name = generate_name(8) if label is None: label = "label-%s" % name.lower() return self.api.create(prv['id'], name, label, description, gpgkey) def delete_product(self, org, pId): return self.api.delete(org['label'], pId) def product(self, org, pId): return self.api.show(org['label'], pId) def products_by_org(self, org, name=None): return self.api.products_by_org(org['label'], name) def sync(self, org, pId): task = self.api.sync(org['label'], pId) while task['sync_status'] != 'finished': task = self.api.last_sync_status(org['label'], pId) return task
def get_product(orgName, prodName): product_api = ProductAPI() prod = product_api.product_by_name(orgName, prodName) if prod == None: raise ApiDataError( _("Could not find product [ %s ] within organization [ %s ]") % (prodName, orgName)) return prod
def get_product(orgName, prodName=None, prodLabel=None, prodId=None): """ Retrieve product by name, label or id. """ product_api = ProductAPI() products = product_api.product_by_name_or_label_or_id( orgName, prodName, prodLabel, prodId) 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 [ %(prodName)s ] within organization [ %(orgName)s ]" ) % { 'prodName': prodName or prodLabel or prodId, 'orgName': orgName }) return products[0]
def create_data(numorgs, numsystems, numproviders, numproducts, numrepos, singleorg): # Setup connection to Katello admin = AdminCLI() admin.setup_parser() admin.opts, admin.args = admin.parser.parse_args([]) admin.setup_server() admin._username = "******" admin._password = "******" org_names = [] if (singleorg): # If we pass in a single org name # we just load all the data into that. org_names.append(singleorg) else: # Otherwise just create fake orgs orgapi = OrganizationAPI() print "Creating [%s] Orgs" % numorgs for i in range(numorgs): name = "Org-%s" % randomString() org_names.append(name) print "[%s] Creating org with name [%s]" % (i, name) orgapi.create(name, "description") # create envs envapi = EnvironmentAPI() for i in range(len(org_names)): print "[%s] Creating DEV/TEST/STAGE in org: [%s]" % (i, org_names[i]) libraryId = get_environment(org_names[i], "Library")["id"] print "Library ID: %s" % libraryId envids = [libraryId] for x in range(len(ENVIRONMENTS)): existing_env = get_environment(org_names[i], ENVIRONMENTS[x]) if not existing_env: e = envapi.create(org_names[i], ENVIRONMENTS[x], "Desc", envids[x]) envids.append(e["id"]) else: envids.append(existing_env["id"]) ## create providers, products and repos print "Creating [%s] providers in each org" % numproviders for i in range(len(org_names)): for y in range(numproviders): provider_name = "Provider-%s" % randomString() print "[%s] Creating Provider with name: [%s] in org: [%s] and products + repos" % ( y, provider_name, org_names[i]) providerapi = ProviderAPI() provider = providerapi.create(provider_name, org_names[i], "Desc", "Custom", None) print " Creating [%s] Products in each provider" % numproducts for z in range(numproducts): product_name = "P-%s" % randomString() print " [%s] Creating product with name: [%s]" % ( z, product_name) productapi = ProductAPI() product = productapi.create(provider["id"], product_name, "Desc", None) print " Creating [%s] Products in each product" % numproducts for x in range(numrepos): repo_name = "Repo-%s" % randomString() print " [%s] Creating repo with name: [%s]" % ( x, repo_name) repoapi = RepoAPI() url = "http://repos.example.com/%s" % repo_name repoapi.create(org_names[i], product["id"], repo_name, url, None, True) ## Create systems print "Creating [%s] Systems in each org and assigning to random envs" % numsystems for i in range(len(org_names)): systemapi = SystemAPI() for x in range(numsystems): system_name = "System-%s" % randomString() randenv = random.choice(ENVIRONMENTS) print "Registering system: [%s] in environment: [%s]" % ( system_name, randenv) system = systemapi.register(system_name, org_names[i], randenv, [], 'system') print "[%s] Created system: %s" % (x, system["name"])
def __init__(self): super(ProductAction, self).__init__() self.api = ProductAPI() self.repoapi = RepoAPI() self.csapi = ChangesetAPI()
def __init__(self): super(ShowSubscriptions, self).__init__() self.productApi = ProductAPI()