Skip to content
Snippets Groups Projects
Commit e1427ed8 authored by Attila Farkas's avatar Attila Farkas
Browse files

add flavors support

parent e7458a90
No related branches found
No related tags found
1 merge request!1Devel
csirtmu.tiny1x2 1 2 GB 20 GB
csirtmu.tiny1x4 1 4 GB 20 GB
csirtmu.small2x4 2 4 GB 20 GB
csirtmu.small2x8 2 8 GB 40 GB
csirtmu.medium4x8 4 8 GB 40 GB
csirtmu.medium4x16 4 16 GB 40 GB
csirtmu.large8x16 8 16 GB 80 GB
csirtmu.large8x32 8 32 GB 80 GB
csirtmu.jumbo16x32 16 32 GB 100 GB
csirtmu.jumbo16x64 16 64 GB 100 GB
\ No newline at end of file
......@@ -5,11 +5,14 @@ import yaml
import jinja2
from modules.network_parser import add_networks
from modules.provider import print_prov_attributes
if (len(sys.argv) != 2):
print ("Error: Expecting 1 argument (yml file).")
sys.exit();
# Loading external files
try:
ymlfile = open(str(sys.argv[1]))
yml = yaml.safe_load(ymlfile)
......@@ -17,25 +20,32 @@ except IOError:
print ("Error: file does not exist.")
try:
v_mappings_file = open("name_mapping/vagrant.yml")
vagrant_mappings = yaml.safe_load(v_mappings_file)
mapping_file = open("name_mapping/mapping.yml")
name_mappings = yaml.safe_load(mapping_file)
except IOError:
print ("Error: cannot find mappings.")
try:
flavors_file = open("name_mapping/flavors.yml")
flavors = yaml.safe_load(flavors_file)
except IOError:
print ("Error: cannot find the list of flavors.")
# Converts yaml attribute names to vagrant attribute names.
def do_mapping(name, command_type):
return vagrant_mappings[str(command_type)][name]
return name_mappings[str(command_type)][name]
def add_formated_command(key, value):
if (key in vagrant_mappings['string']):
if (key in name_mappings['string']):
devices[host['name']].append(
'device.' + str(do_mapping(key, 'string'))
+ ' = \"' + str(value) + '\"')
elif (key in vagrant_mappings['integer']):
elif (key in name_mappings['integer']):
devices[host['name']].append(
'device.' + str(do_mapping(key, 'integer'))
+ ' = ' + str(value))
elif (key in vagrant_mappings['boolean']):
elif (key in name_mappings['boolean']):
devices[host['name']].append(
'device.' + str(do_mapping(key, 'boolean'))
+ ' = ' + str(value).lower())
......@@ -50,6 +60,8 @@ for host in yml['hosts']:
if (key != 'name'):
add_formated_command(key, value)
add_networks(host['name'], yml, devices)
print_prov_attributes(host, flavors
, name_mappings['need_provider'], devices)
# Generating output via Jinja2
......
......@@ -23,6 +23,8 @@ def add_networks(hostname, yml, devices):
if (mapping['host'] == hostname):
_add_ip(hostname, yml['net_mappings'], devices)
if (yml['networks']):
_add_netmask(hostname, mapping['network'], yml['networks'], devices)
_add_netmask(
hostname, mapping['network']
, yml['networks'], devices)
def _print_flavor(host, flavors, provider_attributes, devices):
if ('memory' not in host):
devices[host['name']].append(' vb.'
+ provider_attributes['memory'] + ' = '
+ str(flavors[host['flavor']]['memory']))
if ('cpus' not in host):
devices[host['name']].append(' vb.'
+ provider_attributes['cpus'] + ' = '
+ str(flavors[host['flavor']]['cores']))
def _add_params(host, flavors, provider_attributes, devices):
if ('memory' in host):
devices[host['name']].append(' vb.'
+ provider_attributes['memory'] + ' = '
+ str(host['memory']))
if ('cpus' in host):
devices[host['name']].append(' vb.'
+ provider_attributes['cpus'] + ' = '
+ str(host['cpus']))
if ('flavor' in host and host['flavor'] in flavors):
_print_flavor(host, flavors, provider_attributes, devices)
def _need_provider(host, provider_attributes):
for attribute in provider_attributes:
if (attribute in host):
return True
return False
def print_prov_attributes(host, flavors, provider_attributes, devices):
if (_need_provider(host, provider_attributes)):
devices[host['name']].append(
"device.vm.provider \"virtualbox\" do |vb|")
_add_params(host, flavors, provider_attributes, devices)
devices[host['name']].append("end")
csirtmu.tiny1x2:
cores: 1
memory: 2048
hd: 20480
csirtmu.tiny1x4:
cores: 1
memory: 4096
hd: 20480
csirtmu.small2x4:
cores: 2
memory: 4096
hd: 20480
csirtmu.small2x8:
cores: 2
memory: 8192
hd: 40960
csirtmu.medium4x8:
cores: 4
memory: 8192
hd: 40960
csirtmu.medium4x16:
cores: 4
memory: 16384
hd: 40960
csirtmu.large8x16:
cores: 8
memory: 16384
hd: 81920
csirtmu.large8x32:
cores: 8
memory: 32768
hd: 81920
csirtmu.jumbo16x32:
cores: 16
memory: 32768
hd: 102400
csirtmu.jumbo16x64:
cores: 16
memory: 65536
hd: 102400
......@@ -60,7 +60,6 @@ boolean:
other:
box_url: vm.box_url
guest: vm.guest
network: vm.network
provider: vm.provider
provision: vm.provision
synced_folder: vm.synced_folder
......@@ -74,4 +73,9 @@ other:
vagrant_host: vagrant.host
vagrant_plugins: vagrant.plugins
vagrant_sensitive: vagrant.sensitive
need_provider:
flavor: flavor
memory: memory
cpus: cpus
......@@ -4,6 +4,8 @@ name: small-sandbox
hosts:
- name: server
base_box: ubuntu/bionic64
flavor: csirtmu.tiny1x4
cpus: 2
- name: home
base_box: ubuntu/bionic64
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment