# Core Infra SDK

### Overview

The **Krutrim Python SDK** enables developers to interact programmatically with Krutrim Cloud services, including Compute, Networking, Storage, Security, and AI Pods.\
With a single unified client, you can create and manage resources such as VMs, VPCs, Volumes, Buckets, Security Groups, and AI workloads.

[https://github.com/ola-krutrim/Krutrim-client-python](<https://github.com/ola-krutrim/Krutrim-client-python&#xA;>)

***

### Installation

```bash
bashCopyEditpip uninstall krutrim-client-python  # optional: remove previous version
pip install krutrim-client-python    # install from PyPI
```

> **Note:** If installing from source:

```bash
bashCopyEditpython setup.py bdist_wheel
pip install dist/krutrim_client_python-<version>-py3-none-any.whl
```

***

### Authentication

```python
pythonCopyEditimport requests

url = "https://cloud.olakrutrim.com/iam/v1/signInAsRootUser"
payload = {
    "email": "<your_email>",
    "password": "<your_password>"
}
response = requests.post(url, json=payload)
access_token = response.json()["access_token"]
```

Tokens refresh every **5 minutes**.\
You should implement a token refresh mechanism for long-running scripts.

***

### Initializing the Client

```python
pythonCopyEditfrom krutrim_client_python import KrutrimClient

client = KrutrimClient(api_key=access_token)
```

***

### Services & Methods

#### 1. Networking – VPC & Subnets

| Method                                                                          | Parameters                                                                                                                                                                                                                                    | Description                     |
| ------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------- |
| `create_vpc(vpc_data: dict, x_region: str)`                                     | <p><strong>vpc\_data</strong> – dict containing <code>network</code>, <code>security\_group</code>, <code>subnet</code> details.<br><strong>x\_region</strong> – region name (<code>In-Bangalore-1</code> / <code>In-Hyderabad-1</code>).</p> | Create a new VPC.               |
| `get_vpc_task_status(task_id: str, x_region: str)`                              | <p><strong>task\_id</strong> – ID of the task.<br><strong>x\_region</strong> – region name.</p>                                                                                                                                               | Check the status of a VPC task. |
| `retrieve_vpc(vpc_id: str, x_region: str, vpc_name: str = None)`                | <p><strong>vpc\_id</strong> – VPC ID.<br><strong>x\_region</strong> – region name.<br><strong>vpc\_name</strong> – optional name filter.</p>                                                                                                  | Get VPC details.                |
| `list_vpcs(x_region: str)`                                                      | **x\_region** – region name.                                                                                                                                                                                                                  | List all VPCs.                  |
| `delete_vpc(vpc_id: str, x_region: str)`                                        | <p><strong>vpc\_id</strong> – VPC ID.<br><strong>x\_region</strong> – region name.</p>                                                                                                                                                        | Delete a VPC.                   |
| `create_subnet(subnet_data: dict, vpc_id: str, router_krn: str, x_region: str)` | <p><strong>subnet\_data</strong> – subnet configuration.<br><strong>vpc\_id</strong> – VPC ID.<br><strong>router\_krn</strong> – router KRN.<br><strong>x\_region</strong> – region name.</p>                                                 | Create a subnet in a VPC.       |

***

#### 2. Security Groups

| Method                                                                                                                                       | Parameters                                                                                                                                                                          | Description                        |
| -------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------- |
| `create_security_group(name: str, description: str, vpcid: str, x_region: str)`                                                              | <p><strong>name</strong> – security group name.<br><strong>description</strong> – description.<br><strong>vpcid</strong> – VPC ID.<br><strong>x\_region</strong> – region name.</p> | Create a new security group.       |
| `list_by_vpc(vpc_krn_identifier: str, x_region: str)`                                                                                        | <p><strong>vpc\_krn\_identifier</strong> – VPC KRN.<br><strong>x\_region</strong> – region name.</p>                                                                                | List all security groups in a VPC. |
| `create_rule(direction: str, ethertype: str, protocol: str, port_range_min: int, port_range_max: int, remote_ip_prefix: str, x_region: str)` | Standard rule parameters + region.                                                                                                                                                  | Create an inbound/outbound rule.   |
| `attach_rule(ruleid: str, securityid: str, vpcid: str, x_region: str)`                                                                       | IDs + region name.                                                                                                                                                                  | Attach a rule.                     |
| `detach_rule(ruleid: str, securityid: str, vpcid: str, x_region: str)`                                                                       | IDs + region name.                                                                                                                                                                  | Detach a rule.                     |
| `delete_rule(securitygroupruleid: str, x_region: str)`                                                                                       | Rule ID + region name.                                                                                                                                                              | Delete a rule.                     |
| `delete_security_group(securitygroupid: str, x_region: str)`                                                                                 | Security group ID + region.                                                                                                                                                         | Delete a security group.           |

***

#### 3. Compute – Instances (VMs)

| Method                                                                                                                                 | Parameters                                                                                                                                                                                                                                                                                                                                            | Description                  |
| -------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------- |
| `create_instance(instanceName: str, imageKrn: str, instanceType: str, subnetId: str, sshKeyName: str, volumeSize: int, x_region: str)` | <p><strong>instanceName</strong> – name of VM.<br><strong>imageKrn</strong> – image KRN.<br><strong>instanceType</strong> – e.g., <code>"cpu-standard-4"</code>.<br><strong>subnetId</strong> – subnet ID.<br><strong>sshKeyName</strong> – name of SSH key.<br><strong>volumeSize</strong> – in GB.<br><strong>x\_region</strong> – region name.</p> | Launch a new VM.             |
| `search_instances(filters: dict)`                                                                                                      | Filter dictionary.                                                                                                                                                                                                                                                                                                                                    | Search for instances.        |
| `retrieve_instance(krn: str, x_region: str)`                                                                                           | <p><strong>krn</strong> – instance KRN.<br><strong>x\_region</strong> – region name.</p>                                                                                                                                                                                                                                                              | Retrieve VM details.         |
| `list_instance_info(vpc_krn: str, x_region: str)`                                                                                      | <p><strong>vpc\_krn</strong> – VPC KRN.<br><strong>x\_region</strong> – region name.</p>                                                                                                                                                                                                                                                              | List VM info in a VPC.       |
| `perform_action(instance_krn: str, action: str, x_region: str)`                                                                        | <p><strong>instance\_krn</strong> – instance KRN.<br><strong>action</strong> – <code>"start"</code>, <code>"stop"</code>, <code>"reboot"</code>.<br><strong>x\_region</strong> – region name.</p>                                                                                                                                                     | Start, stop, or reboot a VM. |
| `delete_instance(instanceKrn: str, deleteVolume: bool, x_region: str)`                                                                 | <p><strong>instanceKrn</strong> – VM KRN.<br><strong>deleteVolume</strong> – whether to delete attached volume.<br><strong>x\_region</strong> – region name.</p>                                                                                                                                                                                      | Delete a VM.                 |

***

#### 4. Block Storage

| Method                                                                                             | Parameters                                                | Description            |
| -------------------------------------------------------------------------------------------------- | --------------------------------------------------------- | ---------------------- |
| `create_volume(volumeName: str, size: int, volumeType: str, availabilityZone: str, x_region: str)` | Name, size (GB), type (`"standard"`/`"ssd"`), AZ, region. | Create a block volume. |
| `retrieve_volume(volumeId: str, x_region: str)`                                                    | Volume ID, region.                                        | Get volume details.    |
| `delete_volume(volumeId: str, x_region: str)`                                                      | Volume ID, region.                                        | Delete a volume.       |

***

#### 5. Object Storage

| Method                                                  | Parameters             | Description                  |
| ------------------------------------------------------- | ---------------------- | ---------------------------- |
| `create_access_keys(key_name: str, x_region: str)`      | Key name, region.      | Create a storage access key. |
| `list_access_keys()`                                    | None.                  | List all keys.               |
| `delete_access_keys(access_key_id: str, x_region: str)` | Access key ID, region. | Delete an access key.        |
| `create_bucket(bucketName: str, region: str)`           | Name, region.          | Create a bucket.             |
| `list_buckets()`                                        | None.                  | List buckets.                |
| `delete_bucket(bucketName: str, region: str)`           | Name, region.          | Delete a bucket.             |

***

#### 6. AI Pods

| Method                                                                                                             | Parameters                                                    | Description          |
| ------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------- | -------------------- |
| `kpod.pod.create(podName: str, imageKrn: str, instanceType: str, sshKeyName: str, volumeSize: int, x_region: str)` | Name, image KRN, instance type, SSH key, volume size, region. | Create an AI Pod.    |
| `kpod.pod.update(kpod_krn: str, action: str)`                                                                      | Pod KRN, action (`"start"`, `"stop"`, `"restart"`).           | Update AI Pod state. |
| `kpod.pod.delete(kpod_krn: str)`                                                                                   | Pod KRN.                                                      | Delete AI Pod.       |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.cloud.olakrutrim.com/sdk-guide/core-infra-sdk.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
