Blame docs/operations/ci/adding_cico_tenant/adding-duffy-tenant.md

a6768b
# SOP to create/migrate Duffy tenant
c14d2e
This SOP covers the process of how to create a duffy tenant
c14d2e
a6768b
## Create new tenant
c14d2e
824c14
### Creating dedicated ssh keypair
a6768b
824c14
!!! note
824c14
    we'll start using the `pkistore` git-crypted git repo for this, so be sure to have that under git control
a6768b
824c14
We'll just create the new ssh keypair directly into the CI pkistore repository :
a6768b
a6768b
```
824c14
project="samba"
824c14
ssh-keygen -f ocp/ssh/${project} -C ${project}@CI
a6768b
a6768b
```
a6768b
824c14
!!! important
824c14
    Don't forget to add and git commit && git push new keys in pkistore/ocp/ssh repo
a6768b
a6768b
824c14
This will create both private and public ssh keys, and  you can now copy the public key to be inserted into Duffy DB (see below)
a6768b
a6768b
a6768b
824c14
### Create new Duffy tenant
824c14
```shell
824c14
ssh duffy.ci.centos.org
a6768b
```
a6768b
824c14
### Change to duffy user
824c14
```shell
824c14
sudo su - duffy
a6768b
```
824c14
### Create tenant with the command below and save api key somewhere safe, it outputs the key as `<tenant name>: <API key>`
824c14
```shell
824c14
duffy admin create-tenant <tenant name> "ssh-rsa <ssh pub-key_created_above>"
824c14
``` 
a6768b
a6768b
c2a162
## Artifacts storage box
c2a162
c2a162
CI tenants are allowed to upload artifacts to one storage box, so we need to allow them to upload/rsync to it.
c2a162
It's all controlled by the `artifacts_projects_list` list in ansible (host_vars) so don't forget to also add project and ssh public keys there too
c2a162
c2a162
a6768b
## Duffy client configuration (external)
a6768b
a6768b
### Connect to the host that will have duffy client
c14d2e
```shell
c14d2e
ssh <host user>@<target host>
c14d2e
```
c14d2e
a6768b
### Install duffy client using `pip`
c14d2e
```shell
c14d2e
pip3.8 install --user duffy[client]
c14d2e
```
c14d2e
a6768b
### In the home path of the user, create `.config` directory if it doesn’t exist and create `.config/duffy` with the following content
c14d2e
```
c14d2e
client:
c14d2e
  url: https://duffy.ci.centos.org/api/v1
c14d2e
  auth:
c14d2e
    name: <tenant name>
c14d2e
    key: <API key>
c14d2e
```
c14d2e
a6768b
### To create a session, the name of the pool is required. Check the pool available executing the command **_(Optional)_**
c14d2e
```shell
c14d2e
duffy client list-pools
c14d2e
```
a6768b
### Request a session
c14d2e
```shell
c14d2e
duffy client request-session pool=<name of the pool>,quantity=<number of sessions wanted>
c14d2e
``` 
c14d2e
c14d2e
By default this command outputs a _json_, but it's possible to change the format to _yaml_ or _flat_ using `--format`. Under "node" key it's possible to find the hostname to be used. Log in to it as `root` user, using `ssh`.
c14d2e
c14d2e
```json
c14d2e
{
c14d2e
...output ommited...
c14d2e
c14d2e
"nodes": [
c14d2e
    {
c14d2e
        "hostname": "<hostname>.ci.centos.org",
c14d2e
        "ipaddr": "<ip address>",
c14d2e
c14d2e
...output ommited...
c14d2e
}
c14d2e
```
c14d2e
a6768b
### When needed to retire the session, connect to your duffy client host and execute the command
c14d2e
```shell
c14d2e
duffy client retire-session <session id>
c14d2e
```
c14d2e
c14d2e
It's possible to check the session id either when the session is requested, in the output under "session" key, or using the following command:
c14d2e
```shell
c14d2e
duffy client list-sessions
c14d2e
```