def prepare_monitor(tenant=tenant,
                    user=user,
                    password=password,
                    organization=organization,
                    zone_name=zone_name):
    """
    :param tenant: tenant url
    :param user: user's email
    :param password: user's password
    :param zone_name: (optional) zone_name
    :return:
    """
    router = PrivatePath(tenant, verify_codes=False)

    payload = {
        "firstName": "AllSeeingEye",
        "lastName": "Monitor",
        "email": user,
        "password": password,
        "accept": "true"
    }
    try:
        router.post_quick_sign_up(data=payload)
    except exceptions.ApiUnauthorizedError:
        pass

    platform = QubellPlatform.connect(tenant=tenant,
                                      user=user,
                                      password=password)
    org = platform.organization(name=organization)
    if zone_name:
        zone = org.zones[zone_name]
    else:
        zone = org.zone
    env = org.environment(name="Monitor for " + zone.name, zone=zone.id)
    env.init_common_services(with_cloud_account=False, zone_name=zone_name)

    # todo: move to env
    policy_name = lambda policy: "{}.{}".format(policy.get('action'),
                                                policy.get('parameter'))
    env_data = env.json()
    key_id = [
        p for p in env_data['policies']
        if 'provisionVms.publicKeyId' == policy_name(p)
    ][0].get('value')

    with env as envbulk:
        envbulk.add_marker('monitor')
        envbulk.add_property('publicKeyId', 'string', key_id)

    monitor = Manifest(file=os.path.join(os.path.dirname(__file__),
                                         './monitor_manifests/monitor.yml'))
    monitor_child = Manifest(file=os.path.join(
        os.path.dirname(__file__), './monitor_manifests/monitor_child.yml'))

    org.application(manifest=monitor_child, name='monitor-child')
    app = org.application(manifest=monitor, name='monitor')

    return platform, org.id, app.id, env.id
 def register_user(cls, creds):
     email, password = creds
     payload = {"firstName": "Tester", "lastName": "Qubell", "email": email, "password": password,
                "accept": "true"}
     try:
         router = PrivatePath(cls.platform._router.base_url, verify_codes=False)
         router.post_quick_sign_up(data=payload)
     except exceptions.ApiUnauthorizedError:
         pass
 def register_user(cls, creds):
     email, password = creds
     payload = {
         "firstName": "Tester",
         "lastName": "Qubell",
         "email": email,
         "password": password,
         "accept": "true"
     }
     try:
         router = PrivatePath(cls.platform._router.base_url,
                              verify_codes=False)
         router.post_quick_sign_up(data=payload)
     except exceptions.ApiUnauthorizedError:
         pass
Example #4
0
def prepare_monitor(tenant, user, password, organization, zone_name=None):
    """
    :param tenant: tenant url
    :param user: user's email
    :param password: user's password
    :param zone_name: (optional) zone_name
    :return:
    """
    router = PrivatePath(tenant, verify_codes=False)

    payload = {
        "firstName": "AllSeeingEye",
        "lastName": "Monitor",
        "email": user,
        "password": password,
        "accept": "true"
    }
    try:
        router.post_quick_sign_up(data=payload)
    except exceptions.ApiUnauthorizedError:
        pass

    platform = QubellPlatform.connect(tenant=tenant, user=user, password=password)
    org = platform.organization(name=organization)
    if zone_name:
        zone = org.zones[zone_name]
    else:
        zone = org.zone
    env = org.environment(name="Monitor for "+zone.name, zone=zone.id)
    env.init_common_services(with_cloud_account=False, zone_name=zone_name)

    # todo: move to env
    policy_name = lambda policy: "{}.{}".format(policy.get('action'), policy.get('parameter'))
    env_data = env.json()
    key_id = [p for p in env_data['policies'] if 'provisionVms.publicKeyId' == policy_name(p)][0].get('value')

    with env as envbulk:
        envbulk.add_marker('monitor')
        envbulk.add_property('publicKeyId', 'string', key_id)

    monitor = Manifest(file=os.path.join(os.path.dirname(__file__), './monitor_manifests/monitor.yml'))
    monitor_child = Manifest(file=os.path.join(os.path.dirname(__file__), './monitor_manifests/monitor_child.yml'))

    org.application(manifest=monitor_child, name='monitor-child')
    app = org.application(manifest=monitor, name='monitor')

    return platform, org.id, app.id, env.id
 def connect(tenant=None, user=None, password=None, is_public=False):
     """
     Authenticates user and returns new platform to user.
     This is an entry point to start working with Qubell Api.
     :rtype: QubellPlatform
     :param str tenant: url to tenant, default taken from 'QUBELL_TENANT'
     :param str user: user email, default taken from 'QUBELL_USER'
     :param str password: user password, default taken from 'QUBELL_PASSWORD'
     :param bool is_public: either to use public or private api (public is not fully supported use with caution)
     :return: New Platform instance
     """
     if not is_public:
         router = PrivatePath(tenant)
     else:
         router = PublicPath(tenant)
         router.public_api_in_use = is_public
     router.connect(user, password)
     return QubellPlatform().init_router(router)
    def connect(tenant=None,
                user=None,
                password=None,
                token=None,
                is_public=False):
        """
        Authenticates user and returns new platform to user.
        This is an entry point to start working with Qubell Api.
        :rtype: QubellPlatform
        :param str tenant: url to tenant, default taken from 'QUBELL_TENANT'
        :param str user: user email, default taken from 'QUBELL_USER'
        :param str password: user password, default taken from 'QUBELL_PASSWORD'
        :param str token: session token, default taken from 'QUBELL_TOKEN'
        :param bool is_public: either to use public or private api (public is not fully supported use with caution)
        :return: New Platform instance
        """
        if not is_public:
            router = PrivatePath(tenant)
        else:
            router = PublicPath(tenant)
            router.public_api_in_use = is_public

        if token or (user and password):
            router.connect(user, password, token)

        return QubellPlatform().init_router(router)