Skip to content
Snippets Groups Projects
Commit 8f7441ea authored by kevineri.bonga's avatar kevineri.bonga
Browse files

Merge remote-tracking branch 'origin/main'

# Conflicts:
#	labs/labo4_k8s/datas.py
parents 1c164473 95f72eed
No related branches found
No related tags found
No related merge requests found
File added
File added
File added
File added
File added
...@@ -4,3 +4,7 @@ IMAGE="55f428fa-042f-4591-933d-8b336f136a7b" # From: https://engines.switch.ch/h ...@@ -4,3 +4,7 @@ IMAGE="55f428fa-042f-4591-933d-8b336f136a7b" # From: https://engines.switch.ch/h
FLAVOR="11d87870-2b1f-47ca-a4 00-0fcaaa1272ac" # = c1.large. Use: openstack --os-cloud <cloud-name/normally is engines> flavor list FLAVOR="11d87870-2b1f-47ca-a4 00-0fcaaa1272ac" # = c1.large. Use: openstack --os-cloud <cloud-name/normally is engines> flavor list
NETWORKS=[{"uuid": "c34c17a4-341e-463e-ab52-eed4817387ad"}] # From: https://engines.switch.ch/horizon/project/networks/, select the network you want to use, and retrieve the ID NETWORKS=[{"uuid": "c34c17a4-341e-463e-ab52-eed4817387ad"}] # From: https://engines.switch.ch/horizon/project/networks/, select the network you want to use, and retrieve the ID
FIP = "86.119.44.63" # Floating IP FIP = "86.119.44.63" # Floating IP
# TERRAFORM DATAS
TERRAFORM_IMAGE = "54ee4d6e-9155-4698-ab2b-45d9067e8e8e" #DEBIAN 11 bullseye
TERRAFORM_FLAVOR = "m1.small"
\ No newline at end of file
...@@ -5,3 +5,4 @@ NETWORKS=[{"uuid": "c34c17a4-341e-463e-ab52-eed4817387ad"}] # From: https://engi ...@@ -5,3 +5,4 @@ NETWORKS=[{"uuid": "c34c17a4-341e-463e-ab52-eed4817387ad"}] # From: https://engi
SECURITY_GROUPS=[{"name": "sec_grp"}] # From: https://engines.switch.ch/horizon/project/security_groups/ SECURITY_GROUPS=[{"name": "sec_grp"}] # From: https://engines.switch.ch/horizon/project/security_groups/
FIP = "86.119.44.8" # Floating IP FIP = "86.119.44.8" # Floating IP
KEY_PATH = "../.scred/kexs_key.pem" # Path to the key pair KEY_PATH = "../.scred/kexs_key.pem" # Path to the key pair
KEY_NAME = "kexs_key" # Name of the key pair
\ No newline at end of file
...@@ -4,6 +4,7 @@ import datas ...@@ -4,6 +4,7 @@ import datas
import paramiko import paramiko
logger = utils.setup_logging() logger = utils.setup_logging()
conn = utils.create_connection() # todo: get rid of it
def install_docker(remote_ip, key_path): def install_docker(remote_ip, key_path):
try: try:
...@@ -55,10 +56,14 @@ if __name__ == "__main__": ...@@ -55,10 +56,14 @@ if __name__ == "__main__":
if command == "create": if command == "create":
vm_id, fip = utils.create_vm() vm_id, fip = utils.create_vm()
install_docker(fip, datas.KEY_PATH) #install_docker(fip, datas.KEY_PATH)
logger.info(f"VM created with ID: {vm_id}") logger.info(f"VM created with ID: {vm_id}")
elif command == "list": elif command == "list":
utils.list_instances() utils.list_instances()
#elif command == "test":
# server = conn.compute.find_server(vm_id)
# print(server.addresses) # Voir si des adresses IP sont listées
elif command == "docker": elif command == "docker":
if len(sys.argv) < 3: if len(sys.argv) < 3:
logger.error("Please provide a VM ID to install docker.") logger.error("Please provide a VM ID to install docker.")
...@@ -68,5 +73,5 @@ if __name__ == "__main__": ...@@ -68,5 +73,5 @@ if __name__ == "__main__":
install_docker(fip, datas.KEY_PATH) install_docker(fip, datas.KEY_PATH)
logger.info(f"Docker installed on VM with ID: {vm_id}") logger.info(f"Docker installed on VM with ID: {vm_id}")
else: else:
logger.error(f"Unknown command: {command}. Use 'create','list'") logger.error(f"Unknown command: {command}. Use 'create','list',''docker'")
sys.exit(1) sys.exit(1)
\ No newline at end of file
from idlelib.editor import keynames
import openstack import openstack
import logging import logging
import sys import sys
...@@ -8,6 +10,19 @@ import random ...@@ -8,6 +10,19 @@ import random
def create_connection(): def create_connection():
return openstack.connect(engine='engines') return openstack.connect(engine='engines')
#CREATING AN OPENSTACK CONNECTION v.2
def create_connection_with_credentials():
conn = openstack.connect(
auth_url="https://keystone.cloud.switch.ch:5000/v3",
project_name=dt.PROJECT_NAME,
username="kevin-eric.bonga@etu.hesge.ch",
password="Hakyomaru672",
region_name="ZH",
domain_name='default',
version='2'
)
return conn
def get_server(vm_id): def get_server(vm_id):
conn = create_connection() conn = create_connection()
return conn.compute.find_server(vm_id) return conn.compute.find_server(vm_id)
...@@ -52,9 +67,11 @@ def create_vm(): ...@@ -52,9 +67,11 @@ def create_vm():
image_id=dt.IMAGE, image_id=dt.IMAGE,
flavor_id=dt.FLAVOR, flavor_id=dt.FLAVOR,
security_groups=dt.SECURITY_GROUPS, security_groups=dt.SECURITY_GROUPS,
networks=dt.NETWORKS networks=dt.NETWORKS,
keynames=dt.KEY_NAME
) )
fip = associate_floating_ip(vm_id) server = conn.compute.get_server(vm_id)
fip = associate_floating_ip(server)
logger.debug(f"Generated VM ID: {vm_id}") logger.debug(f"Generated VM ID: {vm_id}")
return vm_id, fip return vm_id, fip
...@@ -98,16 +115,12 @@ def destroy_vm(vm_id): ...@@ -98,16 +115,12 @@ def destroy_vm(vm_id):
# todo # todo
def associate_floating_ip(vm_id): def associate_floating_ip(vm_id):
conn = create_connection() # todo: get rid of it conn = create_connection() # todo: get rid of it
server = conn.compute.find_server(vm_id) server = conn.compute.get_server(vm_id)
if server is None: if server is None:
logger.error(f"Server with ID {vm_id} not found.") logger.error(f"Server with ID {vm_id} not found.")
return return
print(f"adding floating ip address to {server.name} server...") print(f"adding floating ip address to {server.name} server...")
# Ensure the server has a network port
ports = list(conn.network.ports(device_id=vm_id))
if not ports:
logger.error(f"No network ports found for server {vm_id}. Ensure the server is connected to a network.")
return
conn.add_auto_ip(server) conn.add_auto_ip(server)
# Refresh server details to get the updated information # Refresh server details to get the updated information
......
# The mandatory header block that specifies what providers have to be used
terraform {
required_providers {
openstack = {
...
}
}
...
}
# A "provider" block
provider "openstack" {
...
}
# A "resource" block with a name
resource "openstack_compute_instance_v2" "app_server" {
...
}
bcrypt==4.2.0
boto3==1.35.39
botocore==1.35.39
certifi==2024.8.30
cffi==1.17.1
charset-normalizer==3.4.0
cryptography==43.0.1
decorator==5.1.1
dogpile.cache==1.3.3
idna==3.10
iso8601==2.1.0
jmespath==1.0.1
jsonpatch==1.33
jsonpointer==3.0.0
keystoneauth1==5.8.0
netifaces==0.11.0
openstacksdk==4.0.0
os-service-types==1.7.0
paramiko==3.5.0
pbr==6.1.0
platformdirs==4.3.6
pycparser==2.22
PyNaCl==1.5.0
python-dateutil==2.9.0.post0
PyYAML==6.0.2
requests==2.32.3
requestsexceptions==1.4.0
s3transfer==0.10.3
six==1.16.0
stevedore==5.3.0
typing_extensions==4.12.2
urllib3==1.26.20
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment