From c378544597187f67f6a7ae6f6e92382b4e6cb307 Mon Sep 17 00:00:00 2001 From: jharmison Date: Fri, 22 Jan 2021 10:26:10 -0500 Subject: [PATCH] Removed faros-config from monorepo structure (#1) Faros Config now lives in a separate [repository](https://github.com/project-faros/faros-config) in order to enable it to have its own release cycle and separate, dedicated CI and testing. --- Dockerfile | 3 +- app/inventory.py | 13 +---- data.skel/config.yml | 3 ++ pre/faros_config/README.md | 7 --- pre/faros_config/VERSION.txt | 1 - pre/faros_config/example_config.yml | 65 ----------------------- pre/faros_config/faros_config/__init__.py | 22 -------- pre/faros_config/faros_config/bastion.py | 5 -- pre/faros_config/faros_config/cluster.py | 29 ---------- pre/faros_config/faros_config/common.py | 6 --- pre/faros_config/faros_config/network.py | 43 --------------- pre/faros_config/faros_config/proxy.py | 9 ---- pre/faros_config/setup.cfg | 13 ----- pre/faros_config/setup.py | 4 -- pre/faros_config/test_config.py | 11 ---- requirements.txt | 1 + 16 files changed, 7 insertions(+), 228 deletions(-) delete mode 100644 pre/faros_config/README.md delete mode 100644 pre/faros_config/VERSION.txt delete mode 100644 pre/faros_config/example_config.yml delete mode 100644 pre/faros_config/faros_config/__init__.py delete mode 100644 pre/faros_config/faros_config/bastion.py delete mode 100644 pre/faros_config/faros_config/cluster.py delete mode 100644 pre/faros_config/faros_config/common.py delete mode 100644 pre/faros_config/faros_config/network.py delete mode 100644 pre/faros_config/faros_config/proxy.py delete mode 100644 pre/faros_config/setup.cfg delete mode 100644 pre/faros_config/setup.py delete mode 100644 pre/faros_config/test_config.py diff --git a/Dockerfile b/Dockerfile index 785e742..c800372 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,10 +15,11 @@ COPY requirements.txt /deps/python_requirements.txt COPY requirements.yml /deps/ansible_requirements.yml COPY home /root COPY pre /pre + RUN set -ex; \ microdnf update; \ microdnf install python3 jq openssh-clients tar sshpass findutils telnet less; \ - pip3 install --user -r /deps/python_requirements.txt /pre/faros_config; \ + pip3 install --user -r /deps/python_requirements.txt; \ ansible-galaxy collection install -r /deps/ansible_requirements.yml; \ microdnf clean all; \ rpm -i /pre/ilorest-3.0.1-7.x86_64.rpm; \ diff --git a/app/inventory.py b/app/inventory.py index 9cec5c2..69b0a91 100755 --- a/app/inventory.py +++ b/app/inventory.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 import argparse from collections import defaultdict -from faros_config import FarosConfig +from faros_config import FarosConfig, PydanticEncoder import ipaddress import json import os @@ -12,17 +12,6 @@ IP_RESERVATIONS = '/data/ip_addresses' -class PydanticEncoder(json.JSONEncoder): - def default(self, obj): - obj_has_dict = getattr(obj, "dict", False) - if obj_has_dict and callable(obj_has_dict): - return obj.dict(exclude_none=True) - elif isinstance(obj, ipaddress._IPAddressBase): - return str(obj) - else: - return json.JSONEncoder.default(self, obj) - - class InventoryGroup(object): def __init__(self, parent, name): diff --git a/data.skel/config.yml b/data.skel/config.yml index 75cf923..f1862c3 100644 --- a/data.skel/config.yml +++ b/data.skel/config.yml @@ -4,6 +4,9 @@ network: lan: subnet: 192.168.8.0/24 interfaces: [] + dhcp: + ignore_macs: [] + extra_reservations: [] bastion: become_pass: admin cluster: diff --git a/pre/faros_config/README.md b/pre/faros_config/README.md deleted file mode 100644 index 5d87dcf..0000000 --- a/pre/faros_config/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# Faros Config - -This small library is used to validate configuration provided to Project Faros. It contains the necessary parts to load a configuration from the environment, mix it with configuration from a templated YAML file, and provide a single Python object that is easy for the Inventory to work with while generating variables for hosts. - -## NOTE - -This library is not intended to be used outside of Project Faros, or indeed outside of the Project Faros cluster-manager container. diff --git a/pre/faros_config/VERSION.txt b/pre/faros_config/VERSION.txt deleted file mode 100644 index 6e8bf73..0000000 --- a/pre/faros_config/VERSION.txt +++ /dev/null @@ -1 +0,0 @@ -0.1.0 diff --git a/pre/faros_config/example_config.yml b/pre/faros_config/example_config.yml deleted file mode 100644 index bc37659..0000000 --- a/pre/faros_config/example_config.yml +++ /dev/null @@ -1,65 +0,0 @@ -network: - port_forward: - - SSH to Bastion - - HTTPS to Cluster API - - HTTP to Cluster Apps - - HTTPS to Cluster Apps - - HTTPS to Cockpit Panel - lan: - subnet: 192.168.8.0/24 - interfaces: - - eno1 - - eno5 - dns_forward_resolvers: - - 10.1.1.1 - dhcp: - ignore_macs: - - name: node-0-eno1 - mac: da:d5:de:ad:be:ef - - name: node-0-eno2 - mac: da:d5:de:ad:be:ef - - name: node-0-eno3 - mac: da:d5:de:ad:be:ef - extra_reservations: - - name: wifi - mac: da:d5:de:ad:be:ef - ip: 192.168.8.127 - - name: chassis - mac: da:d5:de:ad:be:ef - ip: 192.168.8.50 - - name: bastion-ilo - mac: da:d5:de:ad:be:ef - ip: 192.168.8.51 - - name: client - mac: da:d5:de:ad:be:ef - ip: 192.168.8.52 -bastion: - become_pass: -cluster: - pull_secret: '{"auths":{"cloud.openshift.com":{"auth":"sometoken","email":"some@example.com"}}}' # etc - management: - provider: ilo - user: Administrator - password: - nodes: - - name: node-0 - mac: da:d5:de:ad:be:ef - mgmt_mac: fe:eb:da:ed:5d:ad - - name: node-1 - mac: da:d5:de:ad:be:ef - mgmt_mac: fe:eb:da:ed:5d:ad - - name: node-2 - mac: da:d5:de:ad:be:ef - mgmt_mac: fe:eb:da:ed:5d:ad -proxy: - http: proxy.example.com - https: secure-proxy.example.com - noproxy: - - registry.access.redhat.com - ca: | - # Proxy Server Certificate - -----BEGIN CERTIFICATE----- - MIIGlTCCBH2gAwIBAgIBADANBgkqhkiG9w0BAQsFADCBjjELMAkGA1UEBhMCVVMx - ... - epmW5U8YK4yf - -----END CERTIFICATE---- diff --git a/pre/faros_config/faros_config/__init__.py b/pre/faros_config/faros_config/__init__.py deleted file mode 100644 index 6bd9245..0000000 --- a/pre/faros_config/faros_config/__init__.py +++ /dev/null @@ -1,22 +0,0 @@ -from pydantic import BaseModel -from typing import Optional -import yaml - -from .network import NetworkConfig -from .bastion import BastionConfig -from .cluster import ClusterConfig -from .proxy import ProxyConfig - - -class FarosConfig(BaseModel): - network: NetworkConfig - bastion: BastionConfig - cluster: ClusterConfig - proxy: Optional[ProxyConfig] - - @classmethod - def from_yaml(cls, yaml_file: str) -> 'FarosConfig': - with open(yaml_file) as f: - config = yaml.safe_load(f) - - return cls.parse_obj(config) diff --git a/pre/faros_config/faros_config/bastion.py b/pre/faros_config/faros_config/bastion.py deleted file mode 100644 index b342bc9..0000000 --- a/pre/faros_config/faros_config/bastion.py +++ /dev/null @@ -1,5 +0,0 @@ -from pydantic import BaseModel - - -class BastionConfig(BaseModel): - become_pass: str diff --git a/pre/faros_config/faros_config/cluster.py b/pre/faros_config/faros_config/cluster.py deleted file mode 100644 index 0aa46f6..0000000 --- a/pre/faros_config/faros_config/cluster.py +++ /dev/null @@ -1,29 +0,0 @@ -from pydantic import BaseModel, constr -from typing import List, Optional - -from .common import StrEnum - -MacAddress = constr(regex=r'(([0-9A-Fa-f]{2}[-:]){5}[0-9A-Fa-f]{2})|(([0-9A-Fa-f]{4}\.){2}[0-9A-Fa-f]{4})') # noqa: E501 - - -class ManagementProviderItem(StrEnum): - ILO = "ilo" - - -class ManagementConfig(BaseModel): - provider: ManagementProviderItem - user: str - password: str - - -class NodeConfig(BaseModel): - name: str - mac: MacAddress - mgmt_mac: MacAddress - install_drive: Optional[str] - - -class ClusterConfig(BaseModel): - pull_secret: str - management: ManagementConfig - nodes: List[NodeConfig] diff --git a/pre/faros_config/faros_config/common.py b/pre/faros_config/faros_config/common.py deleted file mode 100644 index 6ba3d8c..0000000 --- a/pre/faros_config/faros_config/common.py +++ /dev/null @@ -1,6 +0,0 @@ -from enum import Enum - - -class StrEnum(str, Enum): - def __str__(self): - return self.value diff --git a/pre/faros_config/faros_config/network.py b/pre/faros_config/faros_config/network.py deleted file mode 100644 index 15e5e0e..0000000 --- a/pre/faros_config/faros_config/network.py +++ /dev/null @@ -1,43 +0,0 @@ -from ipaddress import IPv4Address, IPv6Address, IPv4Network, IPv6Network -from pydantic import BaseModel, constr -from typing import List, Union - -from .common import StrEnum - -MacAddress = constr(regex=r'(([0-9A-Fa-f]{2}[-:]){5}[0-9A-Fa-f]{2})|(([0-9A-Fa-f]{4}\.){2}[0-9A-Fa-f]{4})') # noqa: E501 - - -class PortForwardConfigItem(StrEnum): - SSH_TO_BASTION = "SSH to Bastion" - HTTPS_TO_CLUSTER_API = "HTTPS to Cluster API" - HTTP_TO_CLUSTER_APPS = "HTTP to Cluster Apps" - HTTPS_TO_CLUSTER_APPS = "HTTPS to Cluster Apps" - HTTPS_TO_COCKPIT_PANEL = "HTTPS to Cockpit Panel" - - -class NameMacPair(BaseModel): - name: str - mac: MacAddress - - -class NameMacIpSet(BaseModel): - name: str - mac: MacAddress - ip: Union[IPv4Address, IPv6Address] - - -class DhcpConfig(BaseModel): - ignore_macs: List[NameMacPair] - extra_reservations: List[NameMacIpSet] - - -class LanConfig(BaseModel): - subnet: Union[IPv4Network, IPv6Network] - interfaces: List[str] - dns_forward_resolvers: List[Union[IPv4Address, IPv6Address]] - dhcp: DhcpConfig - - -class NetworkConfig(BaseModel): - port_forward: List[PortForwardConfigItem] - lan: LanConfig diff --git a/pre/faros_config/faros_config/proxy.py b/pre/faros_config/faros_config/proxy.py deleted file mode 100644 index 0a11369..0000000 --- a/pre/faros_config/faros_config/proxy.py +++ /dev/null @@ -1,9 +0,0 @@ -from pydantic import BaseModel -from typing import List - - -class ProxyConfig(BaseModel): - http: str - https: str - noproxy: List[str] - ca: str diff --git a/pre/faros_config/setup.cfg b/pre/faros_config/setup.cfg deleted file mode 100644 index 0236cdf..0000000 --- a/pre/faros_config/setup.cfg +++ /dev/null @@ -1,13 +0,0 @@ -[metadata] -name = faros-config -version = file: VERSION.txt -description = A configuration handler for Project Faros -long_description = file: README.md -long_description_content_type = text/markdown -license = GNU GPL v3 - -[options] -packages = find: -install_requires = - PyYAML==5.3.1 - pydantic==1.7.3 diff --git a/pre/faros_config/setup.py b/pre/faros_config/setup.py deleted file mode 100644 index c823345..0000000 --- a/pre/faros_config/setup.py +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env python -from setuptools import setup - -setup() diff --git a/pre/faros_config/test_config.py b/pre/faros_config/test_config.py deleted file mode 100644 index a559f2d..0000000 --- a/pre/faros_config/test_config.py +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env python3 -# This should grow to be a proper library with actual tests at some point - -from faros_config import FarosConfig - -config = FarosConfig.from_yaml('example_config.yml') - -print(config) -print() -for port in config.network.port_forward: - print(port) diff --git a/requirements.txt b/requirements.txt index 2686fb8..a69f968 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ ansible<2.11 +faros-config==0.1.3 # for management/ilo provider python-hpilo==4.4.2