# Documentation: Ocore and Oggui

## Scenario

There is a need to deploy an image that has been previously created using a model machine, to a client or group of clients.  
The image is hosted in the image repository and is in the **Successfully created** state.

This is the scenario used for this demonstration:

- **Center**:
    - Name: `Centro Demo`

- **Classroom**:
    - Name: `Aula Demo`
    - Router IP: `192.168.2.1`
    - Netmask: `255.255.255.0`

- **Model computer**:
    - MAC Address: `08:00:27:4F:BE:38`
    - Name: `modelo`
    - IP Address: `192.168.2.2`

- **Computer on which the image will be deployed**:
    - MAC Address: `08:00:27:0b:88:be`
    - Name: `pc1`
    - IP Address: `192.168.2.3`

- **Subnet**:
    - Address: `192.168.2.0`
    - Netmask: `255.2555.255.0`

- **Image**:
    - Name: `image-test`
    - Description: `reference image`
    - Type: `Linux`
    - Version: `Ubuntu 24.04`
    - Architecture: `x86_64`

- **Repository**:
    - Path: `/opt/opengnsys/ogrepository/images`
    - IP: `192.168.68.55`

- **ogAgent**:
    - version: `1.4.5~pre7-1 all`

The goal is to deploy the `image-test` image to the `pc1` client with the specified characteristics. As a preliminary step, there must be a connection to the target client, and an ogLive operating system must be installed.

An essential requirement is that the target machine is formatted and has a partition on which the image will be deployed. This machine must have at least two partitions, one of them named CACHE.

In the following screenshots, the arrangement of groups and clients is shown in the ogGui graphical interface.

![General groups](../../assets/images/screenshots/groups_general_1.png "Groups general")
![Groups clients](../../assets/images/screenshots/groups_clients_1.png "Groups clients")

The ogGgui/ogCore tool provides us with a graphical interface through which we can perform the image deployment. In the current version, we will do this via the "Clients" tab within the Group Administration pane.

## Deploy a UNICAST image

1. **Select client**. Using the **Clients** tab in the Group Administration pane, we access the client options by clicking on the "View" button (the one with the eye icon).  
   This gives us access to the client panel where its general information and partition status appear. In the top right, there is a button with all available actions.

![Client actions](../../assets/images/screenshots/client_actions_1.png "Client actions")

2. **Deploy image**. We click on the "Deploy image" button and fill out the form with the corresponding data. In this case, the data are as follows:
    - **Type**: `deploy-image`
    - **Select image**: We select the image we want to deploy. Here we see the list of images available in the repository. If there is any corrupt or erroneous image, it will not appear in the list.
    - **Method**: `UNICAST`
    - **Select partition**: We select the desired partition.

![Client deploy image](../../assets/images/screenshots/client_deploy_image.png "Client deploy image")

If everything went well, the graphical interface returns a green confirmation message in the bottom right corner.  
This means that ogAgent has correctly received the API call and is working on the deployment.

## Traces

For the system to function properly, communication between the **ogCore**
, **ogAgent** and **ogRepository** components must be asynchronous. For this, traces are used that allow us to see the status of requests and responses.

We can access the system traces via the button with a **bell** icon in the top menu of the graphical interface.  
We are presented with a list of all system traces. We can use the provided filters if necessary.

![Traces](../../assets/images/screenshots/traces_1.png "Traces")

For the demonstration example, we see 1 trace:
- **deploy-image**: the trace informs us of the agent's status regarding the image deployment. This action takes a few minutes to complete.

## Verify the image deployment

1. Once we get the **Completed successfully** message in the trace, we can verify that the image has been deployed correctly on the client. To do this, we must change the client's boot configuration to boot from disk. In the case presented, since we are using VB, this would be an example:

![Configuration](../../assets/images/screenshots/vb_configuration.png "Configuration")

2. We restart the client and verify that it boots correctly with the deployed image.

![Traces](../../assets/images/screenshots/vb_deploy_client.png "Traces")

3. We check statuses. If we run `ip a` in a terminal and make sure that the IP is the one our DHCP assigned, in this case `192.168.2.3`

![Client IP](../../assets/images/screenshots/vb_client_ip.png "Client IP")

4. Finally, now in our web console, the client should have changed its status to **LINUX**, and when a session is started, **LINUX_SESSION**

![Groups client](../../assets/images/screenshots/groups_clients.png "Client IP")

## API calls to the different components

1. **ogAgent**: This is the call that ogCore makes to ogAgent to deploy the image. It returns a **job_id** that will be the one shown in the interface trace related to the creation of this image.

````
curl -X POST --data '{"dsk":"1", "par":"2", "cpt":"83", "ifs": "1", idi":"01936caf-facb-72ad-9446-97e7dbf2b96a", "nci":"image-test", "ipr":"192.168.68.55", "nfn":"RestaurarImagen", "method": "unicast", ids":"0"}' 
https://192.168.2.2:8000/CloningEngine/RestaurarImagen
{"job_id": "RestaurarImagen-dfa42888"}
````

These calls communicate their statuses to ogCore via **webhooks**, and ogCore takes care of processing the response and changing the status when necessary.
