Skip to content

Commit

Permalink
Merge pull request #4947 from wazuh/enhancement/4862-dtt1-iteration-3…
Browse files Browse the repository at this point in the history
…-allocation-module-improve-sizes-and-os-for-vagrant-provider

Added support for multiple  OSes for vagrant
  • Loading branch information
teddytpc1 authored Feb 14, 2024
2 parents 371ace5 + aba7e9b commit 63cf760
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 40 deletions.
76 changes: 41 additions & 35 deletions deployability/modules/allocation/static/specs/os.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,23 @@ vagrant:
linux-oracle-9-amd64:
box: generic/oracle9
box_version: 4.3.12
# Suse Linux
linux-suse-15-amd64:
# openSUSE Linux
linux-opensuse-15-amd64:
box: generic/opensuse15
box_version: 4.3.8
linux-opensuse-tumbleweed-amd64:
box: opensuse/Tumbleweed.x86_64
box_version: 1.0.20240207
# Centos
linux-centos-7-amd64:
box: centos/7
box_version: 2004.01
box: generic/centos7
box_version: 4.3.8
linux-centos-8-amd64:
box: centos/stream8
box_version: 20230710.0
box: generic/centos8
box_version: 4.3.8
linux-centos-9-amd64:
box: centos/stream9
box_version: 20230807.1
box: generic/centos9s
box_version: 4.3.12
# Redhat
linux-redhat-7-amd64:
box: generic/rhel7
Expand All @@ -58,7 +61,7 @@ vagrant:
box_version: 3.6.8
linux-redhat-9-amd64:
box: generic/rhel9
box_version: 3.6.8
box_version: 4.3.12
# Amazon
linux-amazon-2-amd64:
box: bento/amazonlinux-2
Expand All @@ -81,40 +84,43 @@ vagrant:
box_version: 4.3.8
linux-fedora-38-amd64:
box: alvistack/fedora-38
box_version: 4.3.8
box_version: 20240206.1.1
# Rocky Linux
linux-rocky-8-amd64:
box: generic/rocky8
box_version: 4.3.12
linux-rocky-9-amd64:
box: rockylinux/9
box_version: 3.0.0
box: generic/rocky9
box_version: 4.3.12
# # Macos
# macos-ventura-13.04-amd64:
# box: logantbond/ventura
# box_version: 1.0.4
# macos-sonoma-14.2-amd64:
# box: barindersingh/sonoma
# box_version: 1.0.6
# # Windows
# windows-desktop-10-amd64:
# box: gusztavvargadr/windows-10
# box_version: 2202.0.2312
# windows-desktop-11-amd64:
# box: gusztavvargadr/windows-11
# box_version: 2302.0.2312
# windows-server-2012-amd64:
# box: jborean93/WindowsServer2012
# box_version: 1.2.0
# windows-server-2012r2-amd64:
# box: devopsgroup-io/windows_server-2012r2-standard-amd64-nocm
# box_version: 1.67.0
# windows-server-2016-amd64:
# box: mwrock/Windows2016
# box_version: 0.3.0
# windows-server-2019-amd64:
# box: gusztavvargadr/windows-server-2019-standard
# box_version: 1809.0.2310
# windows-server-2022-amd64:
# box: gusztavvargadr/windows-server-2022-standard
# box_version: 2102.0.2312
# Windows
windows-desktop-10-amd64:
box: gusztavvargadr/windows-10
box_version: 2202.0.2312
windows-desktop-11-amd64:
box: gusztavvargadr/windows-11
box_version: 2302.0.2312
windows-server-2012-amd64:
box: jborean93/WindowsServer2012
box_version: 1.2.0
windows-server-2012r2-amd64:
box: addle/windows-server-2012-r2
box_version: 1.20170205.1
windows-server-2016-amd64:
box: mwrock/Windows2016
box_version: 0.3.0
windows-server-2019-amd64:
box: gusztavvargadr/windows-server-2019-standard
box_version: 1809.0.2310
windows-server-2022-amd64:
box: gusztavvargadr/windows-server-2022-standard
box_version: 2102.0.2312

aws:
# Ubuntu
Expand Down Expand Up @@ -215,7 +221,7 @@ aws:
zone: us-east-1
user: ec2-user
linux-fedora-38-amd64:
ami: ami-081f29ca9a2a16cec
ami:
zone: us-east-1
user: ec2-user
# Rocky Linux
Expand Down
5 changes: 3 additions & 2 deletions deployability/modules/allocation/static/templates/vagrant.j2
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ Vagrant.configure("2") do |config|

# VirtualBox specific settings
config.vm.provider "virtualbox" do |v|
v.memory = {{ config.memory }}
v.cpus = {{ config.cpu }}
v.memory = "{{ config.memory }}"
v.cpus = "{{ config.cpu }}"
v.name = "{{ config.name }}"
end

# Network settings
Expand Down
2 changes: 1 addition & 1 deletion deployability/modules/allocation/vagrant/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def ssh_connection_info(self) -> ConnectionInfo:
"""
if not 'running' in self.status():
logger.debug(f"Instance {self.identifier} is not running.\
Starting it.")
Starting it.")
self.start()
output = self.__run_vagrant_command('ssh-config')
patterns = {'hostname': r'HostName (.*)',
Expand Down
1 change: 1 addition & 0 deletions deployability/modules/allocation/vagrant/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class VagrantConfig(ProviderConfig):
box_version: str
private_key: str
public_key: str
name: str

@field_validator('public_key', mode='before')
@classmethod
Expand Down
5 changes: 3 additions & 2 deletions deployability/modules/allocation/vagrant/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def _create_instance(cls, base_dir: Path, params: CreationPayload, config: Vagra
# Generate the credentials.
credentials.generate(instance_dir, 'instance_key')
# Parse the config if it is not provided.
config = cls.__parse_config(params, credentials)
config = cls.__parse_config(params, credentials, instance_id)
else:
logger.debug(f"Using provided config")
credentials.load(config.public_key)
Expand Down Expand Up @@ -119,7 +119,7 @@ def __render_vagrantfile(cls, config: VagrantConfig) -> str:
return template.render(config=config)

@classmethod
def __parse_config(cls, params: CreationPayload, credentials: VagrantCredentials) -> VagrantConfig:
def __parse_config(cls, params: CreationPayload, credentials: VagrantCredentials, instance_id: str) -> VagrantConfig:
"""
Parses the configuration for a Vagrant instance.
Expand All @@ -142,6 +142,7 @@ def __parse_config(cls, params: CreationPayload, credentials: VagrantCredentials
config['public_key'] = str(credentials.key_path.with_suffix('.pub'))
config['cpu'] = size_specs['cpu']
config['memory'] = size_specs['memory']
config['name'] = instance_id

return VagrantConfig(**config)

Expand Down

0 comments on commit 63cf760

Please sign in to comment.