- ### NODE Selection ###
- # Infrastructure info
- # nodes dict with
- # uuid -> node uuid
- # computational capabilities -> cpu, ram, and disk available
- # hypervisors -> list of available hypervisors (eg. KVM, LXD, BARE)
- #
- #
-
- # UPDATING AVAILABLE INFRASTRUCTURE
-
- if len(self.nodes) == 0:
- nodes_id = self.fos_api.node.list()
- else:
- nodes_id = self.nodes
- nodes = []
- for n in nodes_id:
- n_info = self.fos_api.node.info(n)
- if n_info is None:
- continue
- n_plugs = []
- for p in self.fos_api.node.plugins(n):
- n_plugs.append(self.fos_api.plugin.info(n,p))
-
- n_cpu_number = len(n_info.get('cpu'))
- n_cpu_arch = n_info.get('cpu')[0].get('arch')
- n_cpu_freq = n_info.get('cpu')[0].get('frequency')
- n_ram = n_info.get('ram').get('size')
- n_disk_size = sorted(list(filter(lambda x: 'sda' in x['local_address'], n_info.get('disks'))), key= lambda k: k['dimension'])[-1].get('dimension')
-
- hvs = []
- for p in n_plugs:
- if p.get('type') == 'runtime':
- hvs.append(p.get('name'))
-
- ni = {
- 'uuid':n,
- 'computational_capabilities':{
- 'cpu_count':n_cpu_number,
- 'cpu_arch':n_cpu_arch,
- 'cpu_freq':n_cpu_freq,
- 'ram_size':n_ram,
- 'disk_size':n_disk_size
- },
- 'hypervisors':hvs
- }
- nodes.append(ni)
-
- # NODE SELECTION
- compatible_nodes = []
- for n in nodes:
- if fdu_desc.get('hypervisor') in n.get('hypervisors'):
- n_comp = n.get('computational_capabilities')
- f_comp = fdu_desc.get('computation_requirements')
- if f_comp.get('cpu_arch') == n_comp.get('cpu_arch'):
- if f_comp.get('cpu_min_count') <= n_comp.get('cpu_count') and f_comp.get('ram_size_mb') <= n_comp.get('ram_size'):
- if f_comp.get('disk_size_gb') <= n_comp.get('disk_size'):
- compatible_nodes.append(n)
-
- if len(compatible_nodes) == 0:
- raise vimconn.vimconnConflictException("No available nodes at VIM")
- selected_node = random.choice(compatible_nodes)