No description
Find a file
2025-05-09 21:52:10 +02:00
.gitignore infra first commit 2024-04-20 19:05:50 +02:00
boap.sh infra first commit 2024-04-20 19:05:50 +02:00
COPYING initial commit 2024-04-20 19:05:30 +02:00
generic_conf_gandivps.sh formatting 2025-05-09 21:52:10 +02:00
LICENSE initial commit 2024-04-20 19:05:30 +02:00
README.md update command syntax 2025-05-09 21:51:25 +02:00

vm_management

Collection of helper scripts, allowing to easily interact with Gandi's "GandiCloud VPS" infrastructure (via openstack) and OVH's "OVHcloud" infrastructure for VPS ans dedicated servers (via OVH API).


Gandi

Setup

From the GandCloud documentation: https://docs.gandi.net/fr/vps/vps_api/index.html

Create the configuration file and edit it accordingly :

$ cp generic_gandivps.sh ma_conf_gandivps.sh
$ nano ma_conf_gandivps.sh

Then source it :

$ . ./ma_conf_gandivps.sh

Create a VM

  1. Find the network, the image (OS), and the flavor (type of server) :
$ openstack network list
+--------------------------------------+--------+------------------------------------------------------------------------------------------------------------------+
| ID                                   | Name   | Subnets                                                                                                          |
+--------------------------------------+--------+------------------------------------------------------------------------------------------------------------------+
| 4f60516f-5f84-4383-9eb7-3315a997e3fa | public | 85f96b71-ad3e-4c87-93f8-3dc0e5b5fa0a, aa800dcf-1dc0-4654-8404-d2b5642525ea, b6476bbd-6c43-400c-9880-9724ce572afa |
+--------------------------------------+--------+------------------------------------------------------------------------------------------------------------------+
$ openstack image list
+--------------------------------------+---------------------------------------------+--------+
| ID                                   | Name                                        | Status |
+--------------------------------------+---------------------------------------------+--------+
[...]
| 4ff4729d-4035-4443-bbff-bbdc29e3c015 | Debian 10 Buster                            | active |
| 690739ee-80b2-49da-861b-246954d5cbb1 | Debian 11 Bullseye                          | active |
| 9e3642be-cd2d-436a-af8b-a19f4479c33d | Debian 12 Bookworm                          | active |
[...]
$ openstack flavor list 
+--------------------------------------+-------+-------+------+-----------+-------+-----------+
| ID                                   | Name  |   RAM | Disk | Ephemeral | VCPUs | Is Public |
+--------------------------------------+-------+-------+------+-----------+-------+-----------+
| 1069bcb0-c1e0-40cd-abb9-b1bad020ddcb | V-R2  |  2048 |    0 |         0 |     1 | True      |
| 1b020404-5ade-49aa-883d-67bf3e313b41 | V-R16 | 16384 |    0 |         0 |     8 | True      |
| affcaade-36e8-46d0-a9e5-c756a9f13dae | V-R12 | 12288 |    0 |         0 |     6 | True      |
| d73c0d36-e062-4720-b149-b668bd9ff312 | V-R1  |  1024 |    0 |         0 |     1 | True      |
| e94895a7-e30c-4f40-8c56-edf9920c7763 | V-R4  |  4096 |    0 |         0 |     2 | True      |
| f7c6693b-758e-40ab-a861-7269110723cb | V-R8  |  8192 |    0 |         0 |     4 | True      |
+--------------------------------------+-------+-------+------+-----------+-------+-----------+
  1. Create the network port (interface with IP addresses) and the machine :
$ openstack port create --network 4f60516f-5f84-4383-9eb7-3315a997e3fa g01_port
$ openstack server create --flavor V-R1 --image 'Debian 11 Bullseye' --boot-from-volume 5 --port g01_port --key-name id_rsa_vps g01

Note: If you need to create the VM without reinstalling (using an already existing disk), do :

$ openstack server create --flavor V-R1 --image 'Debian 11 Bullseye' --volume ea1a057c-110c-4cee-9526-1991169b3ec9 --port g01_port --key-name id_rsa_vps g01
  1. Get the server characteristics :
$ openstack server list
+--------------------------------------+------+--------+-------------------------------------------------------------+--------------------------+--------+
| ID                                   | Name | Status | Networks                                                    | Image                    | Flavor |
+--------------------------------------+------+--------+-------------------------------------------------------------+--------------------------+--------+
| 72c0e53b-5ea3-40bc-a4b9-22dcfa92933f | g01  | ACTIVE | public=2001:4b98:dc0:43:f816:3eff:feba:ca1d, 92.243.24.54   | N/A (booted from volume) | V-R1   |
[...]
$ openstack server show g01
+-----------------------------+-----------------------------------------------------------+
| Field                       | Value                                                     |
+-----------------------------+-----------------------------------------------------------+
[...]
| addresses                   | public=2001:4b98:dc0:43:f816:3eff:feba:ca1d, 92.243.24.54 |
[...]
| flavor                      | V-R1 (d73c0d36-e062-4720-b149-b668bd9ff312)               |
| hostId                      | dade4f7a26b92bd1462b262ef89b1f760221bbb1e1e692a54d2da569  |
| id                          | 72c0e53b-5ea3-40bc-a4b9-22dcfa92933f                      |
| image                       | N/A (booted from volume)                                  |
| key_name                    | id_rsa_vps                                                |
| name                        | g01                                                       |
[...]
| status                      | ACTIVE                                                    |
[...]
| volumes_attached            | id='ea1a057c-110c-4cee-9526-1991169b3ec9'                 |
+-----------------------------+-----------------------------------------------------------+
$ openstack port list  
+--------------------------------------+----------+-------------------+-----------------------------------------------------------------------------------------------------+--------+
| ID                                   | Name     | MAC Address       | Fixed IP Addresses                                                                                  | Status |
+--------------------------------------+----------+-------------------+-----------------------------------------------------------------------------------------------------+--------+
| fa632526-ea43-4520-b493-c43d2bc60b5f | g01_port | fa:16:3e:ba:ca:1d | ip_address='2001:4b98:dc0:43:f816:3eff:feba:ca1d', subnet_id='b6476bbd-6c43-400c-9880-9724ce572afa' | ACTIVE |
|                                      |          |                   | ip_address='92.243.24.54', subnet_id='85f96b71-ad3e-4c87-93f8-3dc0e5b5fa0a'                         |        |
[...]
$ openstack volume list
+--------------------------------------+------+--------+------+-------------------------------+
| ID                                   | Name | Status | Size | Attached to                   |
+--------------------------------------+------+--------+------+-------------------------------+
| ea1a057c-110c-4cee-9526-1991169b3ec9 |      | in-use |    5 | Attached to g01 on /dev/xvda  |
[...]

Now that you have the IP addresses, you can update the DNS zone accordingly.

  1. Update the reverse :
$ openstack port set --dns-domain 'rhizogen.es.eu.org.' --dns-name 'g01' fa632526-ea43-4520-b493-c43d2bc60b5f

Stop/Start/Reboot a VM

$ openstack server stop g01
$ openstack server start g01
$ openstack server reboot g01

Delete a VM, its volume and its network interface

$ openstack server delete g01
$ openstack volume delete ea1a057c-110c-4cee-9526-1991169b3ec9
$ openstack port delete g01_port

Reinstall a VM

  1. Optional: backup data from the old VM

  2. Delete old VM

$ openstack server delete g01
  1. Create new VM
$ openstack server create --flavor V-R1 --image 'Debian 11 Bullseye' --boot-from-volume 5 --port g01_port --key-name id_rsa_vps g01
  1. Push configurations (see configs ansible repo for details)

  2. Optional: restore data

If you choose to do it from the old volume, attach it :

$ openstack server add volume g01 ea1a057c-110c-4cee-9526-1991169b3ec9

then mount it, restore the data, and unmount it. The detach it from the VM :

$ openstack volume attachment list
$ openstack volume attachment delete ea1a057c-110c-4cee-9526-1991169b3ec9
  1. Once everything is validated, destroy the old volume :
$ openstack volume destroy ea1a057c-110c-4cee-9526-1991169b3ec9

OVH

Setup

Create a personal token:

https://www.ovh.com/auth/api/createToken?GET=/&PUT=/&POST=/&DELETE=/

Application name: my_infra
Application description: rhizogenes infra
Application key: XXXXXX
Application secret: XXXXXX
Consumer key: XXXXXX
$ ./boap.sh vps_list
vps-4b79317f.vps.ovh.net
vps519815.ovh.net
$ ./boap.sh vps_info vps-4b79317f.vps.ovh.net | grep 'displayName:'
    "displayName": "ov2.rhizogen.es.eu.org"

Create a VM

Stop/Start/Reboot a VM

$ ./boap.sh vps_reboot vps-4b79317f.vps.ovh.net

Destroy a VM

Reinstall a VM

$ ./boap.sh vps_images vps-4b79317f.vps.ovh.net | grep -B1 'Debian'
    "id": "e0c79590-ba22-4b18-a025-f35864910fee"
    "name": "Debian 10"
--
    "id": "207b1563-1f81-497c-bcca-fe2706d7033f"
    "name": "Debian 11"
--
    "id": "62872c46-ad2a-4708-a1a6-ff3a0a504269"
    "name": "Debian 12"
$ ./boap.sh vps_rebuild vps-4b79317f.vps.ovh.net 207b1563-1f81-497c-bcca-fe2706d7033f