def client():
    url = 'http://localhost:8088/v1-catalog/schemas'
    catalogs = cattle.from_env(url=url, headers=DEFAULT_HEADERS).list_catalog()
    wait_for(
        lambda: len(catalogs) > 0
    )
    return cattle.from_env(url=url, headers=DEFAULT_HEADERS)
def client():
    url = 'http://localhost:8088/v1-catalog/schemas'
    templates = cattle.from_env(url=url).list_template(catalogId='qa-catalog')
    wait_for(
        lambda: len(templates) > 0
    )
    return cattle.from_env(url=url)
Beispiel #3
0
def _get_super_client(request):
    global _SUPER_CLIENT

    if _SUPER_CLIENT is not None:
        return _SUPER_CLIENT

    l = open('/tmp/cattle-api.lock', 'w')
    fcntl.flock(l, fcntl.LOCK_EX)

    client = cattle.from_env(url=cattle_url(),
                             cache=False,
                             access_key='superadmin',
                             secret_key='superadminpass')

    if _is_valid_super_client(client):
        _SUPER_CLIENT = client
        if request is not None:
            request.addfinalizer(
                lambda: delete_sim_instances(client))
        fcntl.flock(l, fcntl.LOCK_UN)
        return client

    super_admin = find_one(client.list_account, name='superadmin')
    super_admin = activate_resource(client, super_admin)

    creds = client.list_api_key(_role='superadmin',
                                accountId=super_admin.id)

    cred = None
    for i in creds:
        if i.removed is None:
            cred = i
            break

    if cred is None:
        cred = client.create_api_key(_role='superadmin',
                                     accountId=super_admin.id,
                                     publicValue='superadmin',
                                     secretValue='superadminpass')
        client.wait_success(cred)

    fcntl.flock(l, fcntl.LOCK_UN)

    client = cattle.from_env(url=cattle_url(),
                             cache=False,
                             access_key=cred.publicValue,
                             secret_key=cred.secretValue)

    assert _is_valid_super_client(client)
    _SUPER_CLIENT = client

    if request is not None:
        request.addfinalizer(
            lambda: delete_sim_instances(client))

    return client
Beispiel #4
0
def _get_super_client(request):
    global _SUPER_CLIENT

    if _SUPER_CLIENT is not None:
        return _SUPER_CLIENT

    l = open('/tmp/cattle-api.lock', 'w')
    fcntl.flock(l, fcntl.LOCK_EX)

    client = cattle.from_env(url=cattle_url(),
                             cache=False,
                             access_key='superadmin',
                             secret_key='superadminpass')

    if _is_valid_super_client(client):
        _SUPER_CLIENT = client
        if request is not None:
            request.addfinalizer(
                lambda: delete_sim_instances(client))
        fcntl.flock(l, fcntl.LOCK_UN)
        return client

    super_admin = find_one(client.list_account, name='superadmin')
    super_admin = activate_resource(client, super_admin)

    creds = client.list_api_key(_role='superadmin',
                                accountId=super_admin.id)

    cred = None
    for i in creds:
        if i.removed is None:
            cred = i
            break

    if cred is None:
        cred = client.create_api_key(_role='superadmin',
                                     accountId=super_admin.id,
                                     publicValue='superadmin',
                                     secretValue='superadminpass')
        client.wait_success(cred)

    fcntl.flock(l, fcntl.LOCK_UN)

    client = cattle.from_env(url=cattle_url(),
                             cache=False,
                             access_key=cred.publicValue,
                             secret_key=cred.secretValue)

    assert _is_valid_super_client(client)
    _SUPER_CLIENT = client

    if request is not None:
        request.addfinalizer(
            lambda: delete_sim_instances(client))

    return client
Beispiel #5
0
def controller_client(request):
    url = 'http://localhost:9501/v1/schemas'
    c = cattle.from_env(url=url)
    request.addfinalizer(lambda: cleanup_controller(c))
    c = cleanup_controller(c)
    assert c.list_volume()[0].replicaCount == 0
    return c
Beispiel #6
0
def make_user_and_client(admin_user_client, name_base='user '):
    account = admin_user_client.create_account(name=name_base + random_str(),
                                               kind="user")
    admin_user_client.wait_success(account)

    username = name_base + random_str()
    password = '******' + random_str()
    login = admin_user_client.create_password(publicValue=username,
                                              secretValue=password,
                                              accountId=account.id)
    admin_user_client.wait_success(login)

    key = admin_user_client.create_apiKey()
    admin_user_client.wait_success(key)
    start_client = from_env(url=cattle_url(),
                            access_key=key.publicValue,
                            secret_key=key.secretValue)

    token = requests.post(base_url() + 'token',
                          {'code': username + ':' + password})

    token = token.json()

    assert token['type'] != 'error'

    token = token['jwt']
    start_client._auth = LocalAuth(token)
    start_client.valid()
    identities = start_client.list_identity()

    assert len(identities) == 1
    assert identities[0].externalId == account.id

    return start_client, account, username, password
Beispiel #7
0
def _admin_client():
    access_key = os.environ.get("CATTLE_ACCESS_KEY", 'admin')
    secret_key = os.environ.get("CATTLE_SECRET_KEY", 'adminpass')
    return from_env(url=cattle_url(),
                    cache=False,
                    access_key=access_key,
                    secret_key=secret_key)
Beispiel #8
0
def create_catalog(name, url, branch=None, headers=DEFAULT_HEADERS):
    schemas_url = 'http://localhost:8088/v1-catalog/schemas'
    client = cattle.from_env(url=schemas_url, headers=headers)

    original_catalogs = client.list_catalog()
    assert len(original_catalogs) > 0
    original_templates = client.list_template()
    assert len(original_templates) > 0

    data = {
        'name': name,
        'url': url,
    }
    if branch:
        data['branch'] = branch

    api_url = 'http://localhost:8088/v1-catalog/catalogs'
    response = requests.post(api_url, data=json.dumps(data), headers=headers)
    assert response.status_code == 200
    resp = response.json()
    assert resp['name'] == name
    assert resp['url'] == url
    if branch:
        assert resp['branch'] == branch

    api_url = 'http://localhost:8088/v1-catalog/templates?action=refresh'
    response = requests.post(api_url, headers=headers)
    assert response.status_code == 204

    templates = client.list_template()
    catalogs = client.list_catalog()
    assert len(catalogs) == len(original_catalogs) + 1
    assert len(templates) > len(original_templates)

    return resp
Beispiel #9
0
def make_client(admin_user_client, account, username, password):
    key = admin_user_client.create_apiKey()
    admin_user_client.wait_success(key)
    start_client = from_env(url=cattle_url(),
                            access_key=key.publicValue,
                            secret_key=key.secretValue)

    token = requests.post(base_url() + 'token', {
        'code': username + ':' + password
    })

    token = token.json()

    assert token['type'] != 'error'

    jwt = token['jwt']
    user = token['userIdentity']
    assert user['login'] == username
    start_client._auth = LocalAuth(jwt)
    start_client.valid()
    identities = start_client.list_identity()

    assert len(identities) == 1
    assert identities[0].externalId == account.id
    return start_client
Beispiel #10
0
def test_account_delete(super_client, random_str, admin_client):

    cred = create_user(admin_client, random_str, kind='user')

    test_user_client = from_env(url=cattle_url(),
                                cache=False,
                                access_key=cred[0],
                                secret_key=cred[1])

    user_account = cred[2]

    sim_context = create_sim_context(super_client,
                                     random_str,
                                     ip='192.168.11.6',
                                     account=user_account)

    host = super_client.wait_success(sim_context['host'])
    assert host.state == 'active'
    assert host.accountId == user_account.id
    account = test_user_client.wait_success(user_account.deactivate())
    account = test_user_client.delete(account)
    account = test_user_client.wait_success(account)
    account = test_user_client.wait_success(account.purge())
    host = admin_client.wait_success(sim_context["host"])
    assert host.state == 'removed'
Beispiel #11
0
def create_images():
    client = from_env()

    for name, base in URLS.items():
        version, hash, url = get_version(base)
        if url is not None:
            save_image(client, name, version, hash, url)
Beispiel #12
0
def controller_client(request):
    url = 'http://localhost:9501/v1/schemas'
    c = cattle.from_env(url=url)
    request.addfinalizer(lambda: cleanup_controller(c))
    c = cleanup_controller(c)
    assert c.list_volume()[0].replicaCount == 0
    return c
Beispiel #13
0
def test_account_delete(super_client, random_str, admin_client):

    cred = create_user(admin_client,
                       random_str,
                       kind='user')

    test_user_client = from_env(url=cattle_url(),
                                cache=False,
                                access_key=cred[0],
                                secret_key=cred[1])

    user_account = cred[2]

    sim_context = create_sim_context(super_client,
                                     random_str,
                                     ip='192.168.11.6',
                                     account=user_account)

    host = super_client.wait_success(sim_context['host'])
    assert host.state == 'active'
    assert host.accountId == user_account.id
    account = test_user_client.wait_success(user_account.deactivate())
    account = test_user_client.delete(account)
    account = test_user_client.wait_success(account)
    account = test_user_client.wait_success(account.purge())
    host = admin_client.wait_success(sim_context["host"])
    assert host.state == 'removed'
Beispiel #14
0
def controller_no_frontend_client(request):
    url = CONTROLLER_NO_FRONTEND_SCHEMA
    c = cattle.from_env(url=url)
    request.addfinalizer(lambda: cleanup_controller(c))
    c = cleanup_controller(c)
    assert c.list_volume()[0].replicaCount == 0
    return c
Beispiel #15
0
def create_images():
    client = from_env()

    for name, base in URLS.items():
        version, hash, url = get_version(base)
        if url is not None:
            save_image(client, name, version, hash, url)
def client_for_project(project):
    access_key = random_str()
    secret_key = random_str()
    admin_client = _admin_client()
    active_cred = None
    account = project
    for cred in account.credentials():
        if cred.kind == 'apiKey' and cred.publicValue == access_key:
            active_cred = cred
            break

    if active_cred is None:
        active_cred = admin_client.create_api_key({
            'accountId': account.id,
            'publicValue': access_key,
            'secretValue': secret_key
        })

    active_cred = wait_success(admin_client, active_cred)
    if active_cred.state != 'active':
        wait_success(admin_client, active_cred.activate())

    return from_env(url=cattle_url(),
                    cache=False,
                    access_key=access_key,
                    secret_key=secret_key)
def _admin_client():
    access_key = os.environ.get("CATTLE_ACCESS_KEY", 'admin')
    secret_key = os.environ.get("CATTLE_SECRET_KEY", 'adminpass')
    return from_env(url=cattle_url(),
                    cache=False,
                    access_key=access_key,
                    secret_key=secret_key)
Beispiel #18
0
def client_for_project(project):
    access_key = random_str()
    secret_key = random_str()
    admin_client = _admin_client()
    active_cred = None
    account = project
    for cred in account.credentials():
        if cred.kind == 'apiKey' and cred.publicValue == access_key\
                and cred.secretValue == secret_key:
            active_cred = cred
            break

    if active_cred is None:
        active_cred = admin_client.create_api_key({
            'accountId': account.id,
            'publicValue': access_key,
            'secretValue': secret_key
        })

    active_cred = wait_success(admin_client, active_cred)
    if active_cred.state != 'active':
        wait_success(admin_client, active_cred.activate())

    return cattle.from_env(url=cattle_url(),
                           cache=False,
                           access_key=access_key,
                           secret_key=secret_key)
Beispiel #19
0
def make_user_and_client(admin_user_client, name_base="user "):
    account = admin_user_client.create_account(name=name_base + random_str(), kind="user")
    admin_user_client.wait_success(account)

    username = name_base + random_str()
    password = "******" + random_str()
    login = admin_user_client.create_password(publicValue=username, secretValue=password, accountId=account.id)
    admin_user_client.wait_success(login)

    key = admin_user_client.create_apiKey()
    admin_user_client.wait_success(key)
    start_client = from_env(url=cattle_url(), access_key=key.publicValue, secret_key=key.secretValue)

    token = requests.post(base_url() + "token", {"code": username + ":" + password})

    token = token.json()

    assert token["type"] != "error"

    token = token["jwt"]
    start_client._auth = LocalAuth(token)
    start_client.valid()
    identities = start_client.list_identity()

    assert len(identities) == 1
    assert identities[0].externalId == account.id

    return start_client, account, username, password
def client(admin_user_client, request):
    try:
        return cattle.from_env(url=os.environ['RANCHER_URL'],
                               access_key=os.environ['RANCHER_ACCESS_KEY'],
                               secret_key=os.environ['RANCHER_SECRET_KEY'])
    except KeyError:
        pass

    try:
        config = ConfigParser.ConfigParser()
        config.read(path.join(_base(), '../../tox.ini'))
        return cattle.from_env(url=config.get('rancher', 'url'),
                               access_key=config.get('rancher', 'access-key'),
                               secret_key=config.get('rancher', 'secret-key'))
    except ConfigParser.NoOptionError:
        pass

    return new_context(admin_user_client, request).client
Beispiel #21
0
def client(admin_user_client, request):
    try:
        return cattle.from_env(url=os.environ['RANCHER_URL'],
                               access_key=os.environ['RANCHER_ACCESS_KEY'],
                               secret_key=os.environ['RANCHER_SECRET_KEY'])
    except KeyError:
        pass

    try:
        config = ConfigParser.ConfigParser()
        config.read(path.join(_base(), '../../tox.ini'))
        return cattle.from_env(url=config.get('rancher', 'url'),
                               access_key=config.get('rancher', 'access-key'),
                               secret_key=config.get('rancher', 'secret-key'))
    except ConfigParser.NoOptionError:
        pass

    return new_context(admin_user_client, request).client
Beispiel #22
0
def setup_data():
    client = from_env()
    registration_url(client)

    data = first(client.list_data(name=DATA_NAME))

    if data is None or data.value != str(DATA_VERSION):
        defaults(client)

        if data is None:
            client.create_data(name=DATA_NAME, value=DATA_VERSION)
        else:
            client.update(data, value=DATA_VERSION)

        print 'Done with data version', DATA_VERSION
def setup_data():
    client = from_env()
    registration_url(client)

    data = first(client.list_data(name=DATA_NAME))

    if data is None or data.value != str(DATA_VERSION):
        defaults(client)

        if data is None:
            client.create_data(name=DATA_NAME, value=DATA_VERSION)
        else:
            client.update(data, value=DATA_VERSION)

        print 'Done with data version', DATA_VERSION
Beispiel #24
0
def delete_catalog(name, headers=DEFAULT_HEADERS):
    schemas_url = 'http://localhost:8088/v1-catalog/schemas'
    client = cattle.from_env(url=schemas_url, headers=headers)

    original_catalogs = client.list_catalog()
    assert len(original_catalogs) > 0
    original_templates = client.list_template()
    assert len(original_templates) > 0

    url = 'http://localhost:8088/v1-catalog/catalogs/' + name
    response = requests.delete(url, headers=headers)
    assert response.status_code == 204

    templates = client.list_template()
    catalogs = client.list_catalog()
    assert len(catalogs) == len(original_catalogs) - 1
    assert len(templates) < len(original_templates)
Beispiel #25
0
def create_duplicate_catalog(name, url, branch=None, headers=DEFAULT_HEADERS):
    schemas_url = 'http://localhost:8088/v1-catalog/schemas'
    client = cattle.from_env(url=schemas_url, headers=headers)

    original_catalogs = client.list_catalog()
    assert len(original_catalogs) > 0
    original_templates = client.list_template()
    assert len(original_templates) > 0

    data = {
        'name': name,
        'url': url,
    }
    if branch:
        data['branch'] = branch

    api_url = 'http://localhost:8088/v1-catalog/catalogs'
    response = requests.post(api_url, data=json.dumps(data), headers=headers)
    assert response.status_code == 422
Beispiel #26
0
def make_client(admin_user_client, account, username, password):
    key = admin_user_client.create_apiKey()
    admin_user_client.wait_success(key)
    start_client = from_env(url=cattle_url(),
                            access_key=key.publicValue,
                            secret_key=key.secretValue)

    token = requests.post(base_url() + 'token', {
        'code': username + ':' + password
    })

    token = token.json()

    assert token['type'] != 'error'

    jwt = token['jwt']
    user = token['userIdentity']
    assert user['login'] == username
    assert token['user'] == username
    start_client._auth = LocalAuth(jwt)
    start_client._access_key = None
    start_client._secret_key = None
    start_client.reload_schema()
    start_client.valid()
    identities = start_client.list_identity()

    assert len(identities) == 1
    assert identities[0].externalId == account.id
    assert identities[0].login == username

    projects = start_client.list_project()
    assert len(projects) == 1
    members = projects[0].projectMembers()
    assert len(members) == 1
    member = get_plain_member(members[0])
    assert member['externalId'] == identities[0].externalId
    assert member['externalIdType'] == identities[0].externalIdType
    assert member['role'] == 'owner'

    return start_client
Beispiel #27
0
def make_client(admin_user_client, account, username, password):
    key = admin_user_client.create_apiKey()
    admin_user_client.wait_success(key)
    start_client = from_env(url=cattle_url(),
                            access_key=key.publicValue,
                            secret_key=key.secretValue)

    token = requests.post(base_url() + 'token', {
        'code': username + ':' + password
    })

    token = token.json()

    assert token['type'] != 'error'

    jwt = token['jwt']
    user = token['userIdentity']
    assert user['login'] == username
    assert token['user'] == username
    start_client._auth = LocalAuth(jwt)
    start_client._access_key = None
    start_client._secret_key = None
    start_client.reload_schema()
    start_client.valid()
    identities = start_client.list_identity()

    assert len(identities) == 1
    assert identities[0].externalId == account.id
    assert identities[0].login == username

    projects = start_client.list_project()
    assert len(projects) == 1
    members = projects[0].projectMembers()
    assert len(members) == 1
    member = get_plain_member(members[0])
    assert member['externalId'] == identities[0].externalId
    assert member['externalIdType'] == identities[0].externalIdType
    assert member['role'] == 'owner'

    return start_client
Beispiel #28
0
def make_client(admin_user_client, account, username, password):
    key = admin_user_client.create_apiKey()
    admin_user_client.wait_success(key)
    start_client = from_env(url=cattle_url(),
                            access_key=key.publicValue,
                            secret_key=key.secretValue)

    token = requests.post(base_url() + 'token', {
        'code': username + ':' + password
    })

    token = token.json()

    assert token['type'] != 'error'

    token = token['jwt']
    start_client._auth = LocalAuth(token)
    start_client.valid()
    identities = start_client.list_identity()

    assert len(identities) == 1
    assert identities[0].externalId == account.id
    return start_client
Beispiel #29
0
def run(count=50000, batch=1, interval=1.000):
    client = from_env(url=URL)
    unmanaged_network = client.list_network(uuid='unmanaged')[0]
    #network = client.list_network(uuid='managed-docker0')[0]

    remaining = count
    while remaining > 0:
        start = time.time()
        current_batch = min(batch, remaining)

        try:
            cs = client.create_container(
                imageUuid='docker:ibuildthecloud/helloworld',
                count=current_batch,
                networkIds=[unmanaged_network.id],
                #networkIds=[network.id],
                instanceTriggeredStop='restart',
                command='sleep 1000000')

            if cs.type == 'collection':
                for c in cs:
                    print 'Created', remaining, c.id, c.uuid
                    queue.put(c.id)
            else:
                print 'Created', remaining, cs.id, cs.uuid
                queue.put(cs.id)
        except Exception, e:
            print e

        remaining -= current_batch

        wait = interval - (time.time() - start)
        if wait > 0:
            print 'Sleep', wait
            time.sleep(wait)
        else:
            print 'Fall behind', wait
Beispiel #30
0
def make_client(admin_user_client, account, username, password):
    key = admin_user_client.create_apiKey()
    admin_user_client.wait_success(key)
    start_client = from_env(url=cattle_url(), access_key=key.publicValue, secret_key=key.secretValue)

    token = requests.post(base_url() + "token", {"code": username + ":" + password})

    token = token.json()

    assert token["type"] != "error"

    jwt = token["jwt"]
    user = token["userIdentity"]
    assert user["login"] == username
    assert token["user"] == username
    start_client._auth = LocalAuth(jwt)
    start_client._access_key = None
    start_client._secret_key = None
    start_client.reload_schema()
    start_client.valid()
    identities = start_client.list_identity()

    assert len(identities) == 1
    assert identities[0].externalId == account.id
    assert identities[0].login == username

    projects = start_client.list_project()
    assert len(projects) == 1
    members = projects[0].projectMembers()
    assert len(members) == 1
    member = get_plain_member(members[0])
    assert member["externalId"] == identities[0].externalId
    assert member["externalIdType"] == identities[0].externalIdType
    assert member["role"] == "owner"

    return start_client
Beispiel #31
0
def run(count=50000, batch=1, interval=1.000):
    client = from_env(url=URL)
    unmanaged_network = client.list_network(uuid='unmanaged')[0]
    #network = client.list_network(uuid='managed-docker0')[0]

    remaining = count
    while remaining > 0:
        start = time.time()
        current_batch = min(batch, remaining)

        try:
            cs = client.create_container(imageUuid='docker:ibuildthecloud/helloworld',
                                         count=current_batch,
                                         networkIds=[unmanaged_network.id],
                                         #networkIds=[network.id],
                                         instanceTriggeredStop='restart',
                                         command='sleep 1000000')

            if cs.type == 'collection':
                for c in cs:
                    print 'Created', remaining, c.id, c.uuid
                    queue.put(c.id)
            else:
                print 'Created', remaining, cs.id, cs.uuid
                queue.put(cs.id)
        except Exception, e:
            print e

        remaining -= current_batch

        wait = interval - (time.time() - start)
        if wait > 0:
            print 'Sleep', wait
            time.sleep(wait)
        else:
            print 'Fall behind', wait
Beispiel #32
0
def replica_client2(request):
    url = 'http://localhost:9505/v1/schemas'
    c = cattle.from_env(url=url)
    request.addfinalizer(lambda: cleanup_replica(c))
    return cleanup_replica(c)
Beispiel #33
0
 def fin():
     admin_user_client.create_localAuthConfig(enabled=None, username=username, password=password)
     assert from_env().valid()
Beispiel #34
0
url = sys.argv[1]

r = requests.get(url)

if r.status_code == 200 and r.text.startswith('#!/bin/sh'):
    print url
    sys.exit(0)

r = requests.get(sys.argv[1])
try:
    url = r.headers['X-API-Schemas']
except KeyError:
    url = sys.argv[1]

client = from_env(url=url)

if not client.valid():
    print 'Invalid client'
    sys.exit(1)

if 'POST' not in client.schema.types['registrationToken'].collectionMethods:
    projects = client.list_project(uuid='adminProject')
    if len(projects) == 0:
        print 'Failed to find admin resource group'
        sys.exit(1)

    client = from_env(url=projects[0].links['schemas'])
    if not client.valid():
        print 'Invalid client'
        sys.exit(1)
Beispiel #35
0
 def fin():
     admin_user_client.create_localAuthConfig(enabled=None,
                                              username=username,
                                              password=password)
     assert from_env().valid()
Beispiel #36
0
 def fin():
     admin_user_client.create_localAuthConfig(enabled=None, username=username, password=password)
     # Proves auth is off because keys are invalid and would be reject
     assert from_env(access_key="bad_key", secret_key="bad_key2").valid()
Beispiel #37
0
    if detail or is_running(pi):
        for pe in pi.processExecutions():
            for x in pe.log.executions:
                print_pe(x, prefix=' ')


def print_pe(pe, prefix=''):
    print prefix, print_time(pe), 'PROCESS:', pe.name, \
        '{}:{}'.format(pe.resourceType, pe.resourceId), pe.exitReason
    for phe in pe.processHandlerExecutions:
        print_phe(phe, prefix=prefix + '  ')


def print_phe(phe, prefix=''):
    print prefix, print_time(phe), 'HANDLER:', phe.name
    for child in phe.children:
        for pe in child.executions:
            print_pe(pe, prefix=prefix + '  ')


if __name__ == '__main__':
    import sys
    client = from_env(headers={'X-API-Project-Id': 'USER'})
    if len(sys.argv) == 1:
        for pi in client.list_process_instance(sort='startTime', order='desc',
                                               limit=30):
            print_pi(pi)
    else:
        pi = client.by_id_process_instance(sys.argv[1])
        print_pi(pi, detail=True)
Beispiel #38
0
def replica_client2(request):
    url = 'http://localhost:9505/v1/schemas'
    c = cattle.from_env(url=url)
    request.addfinalizer(lambda: cleanup_replica(c))
    return cleanup_replica(c)
Beispiel #39
0
def replica_client(request, url):
    c = cattle.from_env(url=url)
    request.addfinalizer(lambda: cleanup_replica(c))
    return cleanup_replica(c)
Beispiel #40
0
def _admin_client():
    return cattle.from_env(url=cattle_url(),
                           cache=False,
                           access_key='admin',
                           secret_key='adminpass')
Beispiel #41
0
def _client_for_user(name, accounts):
    return cattle.from_env(url=cattle_url(),
                           cache=False,
                           access_key=accounts[name][0],
                           secret_key=accounts[name][1])
Beispiel #42
0
# Discovery Token
token = requests.get("https://discovery.etcd.io/new").text

userdata = """#cloud-config
coreos:
    units:
      - name: etcd.service
        command: start
      - name: fleet.service
        command: start
    etcd:
        discovery: %s
        addr: $private_ipv4:4001
        peer-addr: $private_ipv4:7001""" % token

client = cattle.from_env()

cred = client.list_ssh_key(uuid='defaultSshKey')[0]
image = client.list_image(uuid_like='coreos-stable-%')[0]

for i in range(3):
    c = client.create_virtual_machine(imageId=image.id,
                                      name='CoreOS {0}'.format(i+1),
                                      credentialIds=[cred.id],
                                      userdata=userdata,
                                      memoryMb=512)

    print 'Created Name: {}, ID: {}, Image: {}'.format(c.name,
                                                       c.id,
                                                       c.image().name)
Beispiel #43
0
def _client_for_user(name, accounts):
    return cattle.from_env(access_key=accounts[name][0],
                           secret_key=accounts[name][1])
Beispiel #44
0
def _admin_client():
    return cattle.from_env(access_key='admin', secrect_key='adminpass')
Beispiel #45
0
def api_client(access_key, secret_key, project_id=None):
    return cattle.from_env(url=cattle_url(project_id),
                           cache=False,
                           access_key=access_key,
                           secret_key=secret_key)
Beispiel #46
0
def api_client(access_key, secret_key):
    return cattle.from_env(url=cattle_url(),
                           cache=False,
                           access_key=access_key,
                           secret_key=secret_key)
Beispiel #47
0
    if detail or is_running(pi):
        for pe in pi.processExecutions():
            for x in pe.log.executions:
                print_pe(x, prefix=' ')


def print_pe(pe, prefix=''):
    print prefix, print_time(pe), 'PROCESS:', pe.name, \
        '{}:{}'.format(pe.resourceType, pe.resourceId), pe.exitReason
    for phe in pe.processHandlerExecutions:
        print_phe(phe, prefix=prefix + '  ')


def print_phe(phe, prefix=''):
    print prefix, print_time(phe), 'HANDLER:', phe.name
    for child in phe.children:
        for pe in child.executions:
            print_pe(pe, prefix=prefix + '  ')


if __name__ == '__main__':
    import sys
    client = from_env()
    if len(sys.argv) == 1:
        for pi in client.list_process_instance(sort='startTime', order='desc',
                                               limit=30):
            print_pi(pi)
    else:
        pi = client.by_id_process_instance(sys.argv[1])
        print_pi(pi, detail=True)
Beispiel #48
0
from multiprocessing import Queue, Process
#from Queue import Queue
#from threading import Thread as Process
from cattle import from_env
import time


URL = 'http://mgmt1:8080/v1/schemas'
queue = Queue()
client = from_env(url=URL)
start = time.time()


def progress():
    done_count = 0
    error_count = 0

    while True:
        id = queue.get()
        if id is None:
            break

        c = client.by_id_container(id)
        c = client.wait_transitioning(c, timeout=10000)
        if c.state == 'running':
            print (c.firstRunningTS - c.createdTS)/1000, c.id, c.hosts()[0].name
            done_count += 1
        else:
            error_count += 1

        print time.time(), 'Done:', done_count, 'Error:',\
Beispiel #49
0
def client():
    url = 'http://localhost:8088/v1-catalog/schemas'
    return cattle.from_env(url=url)
Beispiel #50
0
 def fin():
     admin_user_client.create_localAuthConfig(enabled=None,
                                              username=username,
                                              password=password)
     # Proves auth is off because keys are invalid and would be reject
     assert from_env(access_key='bad_key', secret_key='bad_key2').valid()
Beispiel #51
0
def admin_client():
    from_env(url=URL)
    assert client.valid()
    return client
Beispiel #52
0
def client():
    client = from_env(url=URL)
    assert client.valid()
    return client
def api_client(access_key, secret_key):
    return cattle.from_env(url=cattle_url(),
                           cache=False,
                           access_key=access_key,
                           secret_key=secret_key)
Beispiel #54
0
 def __init__(self, volume):
     url = 'http://localhost:9414/v1/schemas'
     c = cattle.from_env(url=url)
     dev = c.list_volume()[0]
     assert dev.name == volume
     self.dev = dev
Beispiel #55
0
def api_client(access_key, secret_key, project_id=None):
    return cattle.from_env(url=cattle_url(project_id),
                           cache=False,
                           access_key=access_key,
                           secret_key=secret_key)
Beispiel #56
0
def client(request):
    url = 'http://localhost:9502/v1/schemas'
    c = cattle.from_env(url=url)
    request.addfinalizer(lambda: cleanup(c))
    return cleanup(c)