Exemplo n.º 1
0
def get_env_id(org, env):
    """
    Returns the envid based on environment name, passed.
    :param org: string
    :param env: string
    """
    envapi = EnvironmentAPI()

    return envapi.environment_by_name(org, env)["id"]
Exemplo n.º 2
0
def get_env_id(org, env):
    """
    Returns the envid based on environment name, passed.
    :param org: string
    :param env: string
    """
    envapi = EnvironmentAPI()

    return envapi.environment_by_name(org, env)['id']
Exemplo n.º 3
0
def get_environment(orgName, envName=None):
    environment_api = EnvironmentAPI()

    if envName == None:
        env = environment_api.library_by_org(orgName)
        envName = env['name']
    else:
        env = environment_api.environment_by_name(orgName, envName)

    if env == None:
        print >> sys.stderr, _("Could not find environment [ %s ] within organization [ %s ]") % (envName, orgName)
    return env
Exemplo n.º 4
0
def create_data(numorgs, numsystems, numproducts, 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 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"])
Exemplo n.º 5
0
def get_environment(orgName, envName=None):
    environment_api = EnvironmentAPI()

    if envName == None:
        env = environment_api.library_by_org(orgName)
        envName = env['name']
    else:
        env = environment_api.environment_by_name(orgName, envName)

    if env == None:
        raise ApiDataError(_("Could not find environment [ %(envName)s ] within organization [ %(orgName)s ]") %
            {'envName':envName, 'orgName':orgName})
    return env
Exemplo n.º 6
0
def get_environment(orgName, envName=None):
    environment_api = EnvironmentAPI()

    if envName == None:
        env = environment_api.library_by_org(orgName)
        envName = env['name']
    else:
        env = environment_api.environment_by_name(orgName, envName)

    if env == None:
        raise ApiDataError(
            _("Could not find environment [ %s ] within organization [ %s ]") %
            (envName, orgName))
    return env
Exemplo n.º 7
0
def create_data(numorgs, numsystems, numproducts, 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 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"])
Exemplo n.º 8
0
def process_environment(org, env):
    """
    Returns the envid.
    :param org: string
    :param env: string
    """
    envapi = EnvironmentAPI()
    try:
        envid = get_env_id(org, env)
    except Exception, e:
        try:
            lockerid = get_env_id(org, "Library")
            envapi.create(org, env, "Test Environment", lockerid)
            envid = get_env_id(org, env)
        except Exception, e:
            sys.stderr.write("[Error] Failed to find and create requested environment.\n%s\n" % e)
            sys.exit(-1)
Exemplo n.º 9
0
def process_environment(org, env):
    """
    Returns the envid.
    :param org: string
    :param env: string
    """
    envapi = EnvironmentAPI()
    try:
        envid = get_env_id(org, env)
    except Exception, e:
        try:
            lockerid = get_env_id(org, "Library")
            envapi.create(org, env, "Test Environment", lockerid)
            envid = get_env_id(org, env)
        except Exception, e:
            sys.stderr.write(
                '[Error] Failed to find and create requested environment.\n%s\n'
                % e)
            sys.exit(-1)
Exemplo n.º 10
0
class Environment():
    api = EnvironmentAPI()

    def create_environment(self, org, name=None, prior='Library'):

        if name is None:
            name = generate_name()

        if prior:
            prior = self.environment_by_name(org, prior)
            prior_id = prior['id']

        label = "label-%s" % name.replace(' ', '_')
        description = "Generated automatically."

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

    def environment_by_name(self, org, name):
        return self.api.environment_by_name(org['label'], name)
Exemplo n.º 11
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"])
Exemplo n.º 12
0
 def __init__(self):
     super(EnvironmentAction, self).__init__()
     self.api = EnvironmentAPI()
Exemplo n.º 13
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"])