diff --git a/spyglass_plugin_xls/cli.py b/spyglass_plugin_xls/cli.py index fda9787..7076ce9 100644 --- a/spyglass_plugin_xls/cli.py +++ b/spyglass_plugin_xls/cli.py @@ -159,5 +159,6 @@ def generate_manifests_and_intermediary(*args, **kwargs): LOG.info("Generating site Manifests") processor_engine = SiteProcessor( - intermediary_yaml, kwargs['manifest_dir'], kwargs['force']) + intermediary_yaml.dict_from_class(), kwargs['manifest_dir'], + kwargs['force']) processor_engine.render_template(kwargs['template_dir']) diff --git a/spyglass_plugin_xls/excel.py b/spyglass_plugin_xls/excel.py index 8757ee1..7bcd0f5 100644 --- a/spyglass_plugin_xls/excel.py +++ b/spyglass_plugin_xls/excel.py @@ -17,6 +17,7 @@ import logging import pprint import re from spyglass.data_extractor.base import BaseDataSourcePlugin +from spyglass.data_extractor import models from spyglass_plugin_xls.excel_parser import ExcelParser LOG = logging.getLogger(__name__) @@ -25,6 +26,7 @@ LOG = logging.getLogger(__name__) class ExcelPlugin(BaseDataSourcePlugin): def __init__(self, region): + super().__init__(region) LOG.info("Excel Plugin Initializing") self.source_type = "excel" self.source_name = "spyglass-plugin-xls" @@ -33,9 +35,6 @@ class ExcelPlugin(BaseDataSourcePlugin): self.excel_path = None self.excel_spec = None - # Site related data - self.region = region - # Raw data from excel self.parsed_xl_data = None @@ -81,39 +80,47 @@ class ExcelPlugin(BaseDataSourcePlugin): } return plugin_conf - def get_hosts(self, region, rack=None): - """Return list of hosts in the region + def get_racks(self, region): + """Return list of racks in the region :param string region: Region name - :param string rack: Rack name - :returns: list of hosts information - :rtype: list of dict - Example: [ - { - 'name': 'host01', - 'type': 'controller', - 'host_profile': 'hp_01' - }, - { - 'name': 'host02', - 'type': 'compute', - 'host_profile': 'hp_02'} - ] + :returns: list of Rack objects + :rtype: list """ LOG.info("Get Host Information") ipmi_data = self.parsed_xl_data["ipmi_data"][0] rackwise_hosts = self._get_rackwise_hosts() - host_list = [] + baremetal_racks = [] for rack in rackwise_hosts.keys(): - for host in rackwise_hosts[rack]: - host_list.append( - { - "rack_name": rack, - "name": host, - "host_profile": ipmi_data[host]["host_profile"], - }) - return host_list + host_list = [] + for host_data in rackwise_hosts[rack]: + host = models.Host( + host_data, + rack_name=rack, + host_profile=ipmi_data[host_data]["host_profile"]) + host_list.append(host) + baremetal_racks.append(models.Rack(rack, host_list)) + return baremetal_racks + + def get_hosts(self, region, rack=None): + """Return list of hosts in the region + + :param string region: Region name + :param string rack: Rack name + :returns: list of Host objects containing a rack's host data + :rtype: list of models.Host + """ + racks = self.get_racks(region) + if rack: + for _rack in racks: + if rack == _rack.name: + return _rack.hosts + else: + host_list = [] + for _rack in racks: + host_list.extend(_rack.hosts) + return host_list def get_networks(self, region): """Extracts vlan network info from raw network data from excel""" @@ -149,12 +156,9 @@ class ExcelPlugin(BaseDataSourcePlugin): tmp_vlan["subnet"] = net_val.get("subnet", "#CHANGE_ME") tmp_vlan["gateway"] = net_val.get("gateway", "#CHANGE_ME") else: - tmp_vlan["name"] = "ingress" + tmp_vlan["name"] = net_type tmp_vlan["subnet"] = net_val - vlan_list.append(tmp_vlan) - LOG.debug( - "vlan list extracted from spyglass-plugin-xls:\n{}".format( - pprint.pformat(vlan_list))) + vlan_list.append(models.VLANNetworkData(**tmp_vlan)) return vlan_list def get_ips(self, region, host=None): @@ -171,16 +175,16 @@ class ExcelPlugin(BaseDataSourcePlugin): DHCP or internally generated n the next steps by the design rules. """ - ip_ = {} ipmi_data = self.parsed_xl_data["ipmi_data"][0] - ip_[host] = { - "oob": ipmi_data[host].get("ipmi_address", "#CHANGE_ME"), - "oam": ipmi_data[host].get("oam", "#CHANGE_ME"), - "calico": ipmi_data[host].get("calico", "#CHANGE_ME"), - "overlay": ipmi_data[host].get("overlay", "#CHANGE_ME"), - "pxe": ipmi_data[host].get("pxe", "#CHANGE_ME"), - "storage": ipmi_data[host].get("storage", "#CHANGE_ME"), - } + ip_ = models.IPList( + **{ + "oob": ipmi_data[host].get("ipmi_address", "#CHANGE_ME"), + "oam": ipmi_data[host].get("oam", "#CHANGE_ME"), + "calico": ipmi_data[host].get("calico", "#CHANGE_ME"), + "overlay": ipmi_data[host].get("overlay", "#CHANGE_ME"), + "pxe": ipmi_data[host].get("pxe", "#CHANGE_ME"), + "storage": ipmi_data[host].get("storage", "#CHANGE_ME"), + }) return ip_ def get_ldap_information(self, region): @@ -244,10 +248,14 @@ class ExcelPlugin(BaseDataSourcePlugin): "corridor": "c{}".format(corridor_number), } - def get_racks(self, region): - # This function is not required since the excel plugin - # already provide rack information. - pass + def get_site_info(self, region): + """Retrieve general site information as SiteInfo object""" + data_dict = {} + data_dict.update(self.get_location_information(region)) + data_dict['dns'] = self.get_dns_servers(region) + data_dict['ntp'] = self.get_ntp_servers(region) + data_dict['ldap'] = self.get_ldap_information(region) + return models.SiteInfo(region, **data_dict) def _get_excel_obj(self): """Creation of an ExcelParser object to store site information. @@ -319,7 +327,7 @@ class ExcelPlugin(BaseDataSourcePlugin): for data in server_list: if "(" not in data: servers.append(data) - formatted_server_list = ",".join(servers) + formatted_server_list = models.ServerList(servers) return formatted_server_list def _get_rack(self, host): diff --git a/spyglass_plugin_xls/excel_parser.py b/spyglass_plugin_xls/excel_parser.py index f3703f1..fc5c368 100644 --- a/spyglass_plugin_xls/excel_parser.py +++ b/spyglass_plugin_xls/excel_parser.py @@ -35,7 +35,7 @@ class ExcelParser(object): with open(excel_specs, "r") as f: spec_raw_data = f.read() self.excel_specs = yaml.safe_load(spec_raw_data) - # A combined design spec, returns a workbok object after combining + # A combined design spec, returns a workbook object after combining # all the inputs excel specs combined_design_spec = self.combine_excel_design_specs(file_name) self.wb_combined = combined_design_spec @@ -124,7 +124,6 @@ class ExcelParser(object): "ipmi_address": ipmi_address, "ipmi_gateway": ipmi_gateway, "host_profile": host_profile, - "type": type, } row += 1 LOG.debug( @@ -230,8 +229,10 @@ class ExcelParser(object): "vlan": ws.cell(row=oam_row, column=oam_vlan_col).value, }, "ingress": ws.cell(row=ingress_row, column=oam_col).value, + "oob": { + "subnet": [] + } } - network_data["oob"] = {"subnet": []} while col <= end_col: cell_value = ws.cell(row=oob_row, column=col).value if cell_value: