Create a Custom Environment

import sys

from utils.rc.client.requests import Requests
from utils.rc.client.auth import AuthClient

from utils.rc.dtos.env import Env
from utils.rc.dtos.env import EnvType

import logging
logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.INFO)
#Requests.setRootHost("http://staging.dev.rapidcanvas.net/api/")
AuthClient.setToken(token="")

Available configurations

A custom environment allows you to choose the infrastructure you need to execute your project. Here are the available custom environments and their usage guidelines

SMALL: 1 Core, 2GB Memmory
MEDIUM: 2 Cores, 4GB Memmory
LARGE: 4 Cores, 8GB Memmory
CPU_LARGE: 8 Cores, 16GB Memmory
MAX_LARGE: 12 Cores, 32GB Memmory
EXTRA_MAX_LARGE: 12 Cores, 48GB Memmory
env = Env.createEnv(
    name="new_custom_env", #pick a name for your env
    description="env for my projects",
    envType=EnvType.SMALL, #pick one of the predefined configs
    requirements="jq==1.2.2 yq==3.0.2" #additional packages to be installed for your custom environment
)
env.id

Parameters

Parameters

Parameter name

Parameter description

Data type

Required

Example

name

The name of the environment.

String

Yes

new_custom_env1

description

The description for the environment.

String

No

env for my projects

envType

The hardware requirements for the environment. Possible values:

  • SMALL

  • MEDIUM

  • LARGE

  • CPU_LARGE

  • MAX_LARGE

  • EXTRA_MAX_LARGE

String

Yes

If you are selecting the hardware requirement as SMALL: 1 core, 2GB memory, then you must enter EnvType.SMALL.

requirements

The additional packages to install for the custom environment.

No

jq==1.2.2 yq==3.0.2

Deleting an environment

The following code block must be used to delete an environment.

Env.deleteEnvById('envId')

Example code block for deleting an environment:

Env.deleteEnvById('4e8a8033-db43-4720-9309-ac0fce9163be')

Editing the environment details

Use this code block to modify environment details of a specific environment. You must pass the environment ID for which you want to modify the environment details.

Sample code:

env = Env.updateEnv(
        envId='4dae540d-1717-4b87-8c1e-e60357c7f7f4',
        description="env for my projects4353",
        envType=EnvType.SMALL, #pick one of the pre-defined configs
        requirements="jq==1.2.2 yq==3.0.2" #additional packages to be installed for your custom env
)

Example response:

INFO:Updating environment, this may take few minutes
INFO:Environment is updated.

Fetching all environments in a tenant

The following code block can be used to fetch all environments.

Env.getAllEnvs()

Example response:

{'new_custom_env1232eddd': <utils.rc.dtos.env.Env at 0x7f295d722e60>,
 'new_custom_env12234': <utils.rc.dtos.env.Env at 0x7f295d721000>,
 'new_custom_env1': <utils.rc.dtos.env.Env at 0x7f296e9970a0>,
 'new_custom_envtest1': <utils.rc.dtos.env.Env at 0x7f2929159000>,
 'new_custom_env12': <utils.rc.dtos.env.Env at 0x7f292915b460>,
 'new_custom_env': <utils.rc.dtos.env.Env at 0x7f2929159600>,
 'test_max_large': <utils.rc.dtos.env.Env at 0x7f2929305060>,
 'new_custom_env122': <utils.rc.dtos.env.Env at 0x7f2929304730>,
 'new_custom_envtest': <utils.rc.dtos.env.Env at 0x7f2929305150>}

Searching for an environment by name or ID

Use this code to search for an environment by its name.

env.getEnvByName('name')

Example code:

env.getEnvByName('new_custom_env12')

Use this code to search for an environment by its ID.

env.getEnvById('envId')

Example code:

env.getEnvById('4dae540d-1717-4b87-8c1e-e60357c7f7f4')

Viewing the list of supported environments

Use this code to fetch the list of supported environment types.

env.getEnvTypeInfo()

Example response:

{<EnvType.EXTRA_SMALL: 'EXTRA_SMALL'>: {'cores': 1, 'memory': 1},
 <EnvType.SMALL: 'SMALL'>: {'cores': 1, 'memory': 2},
 <EnvType.MEDIUM: 'MEDIUM'>: {'cores': 2, 'memory': 4},
 <EnvType.LARGE: 'LARGE'>: {'cores': 4, 'memory': 8},
 <EnvType.CPU_LARGE: 'CPU_LARGE'>: {'cores': 8, 'memory': 16},
 <EnvType.MAX_LARGE: 'MAX_LARGE'>: {'cores': 12, 'memory': 32},
 <EnvType.EXTRA_MAX_LARGE: 'EXTRA_MAX_LARGE'>: {'cores': 12, 'memory': 48},
 <EnvType.SUPER_LARGE: 'SUPER_LARGE'>: {'cores': 12, 'memory': 96}}

Fetching resources from a specific environment type

Use this code to fetch the resources such as cores and memory in a specific environment type.

env.getResourcesFromEnvType(envType)

Example code:

env.getResourcesFromEnvType('CPU_LARGE')

Example response: (8, 16)