mirror of
https://github.com/yavook/kiwi-scp.git
synced 2024-11-21 20:33:00 +00:00
remove need for kiwi_default.yml
This commit is contained in:
parent
af02c410e5
commit
e42b426f2e
5 changed files with 32 additions and 36 deletions
|
@ -2,17 +2,17 @@
|
||||||
# kiwi-scp instance configuration #
|
# kiwi-scp instance configuration #
|
||||||
###################################
|
###################################
|
||||||
|
|
||||||
version: '0.1.7'
|
version: '0.2.0'
|
||||||
|
|
||||||
runtime:
|
shells:
|
||||||
storage: /tmp/kiwi
|
|
||||||
shells:
|
|
||||||
- /bin/bash
|
- /bin/bash
|
||||||
env: null
|
|
||||||
|
|
||||||
markers:
|
projects:
|
||||||
project: .project
|
- name: hello-world.project
|
||||||
disabled: .disabled
|
enabled: true
|
||||||
|
|
||||||
|
storage:
|
||||||
|
directory: /var/local/kiwi
|
||||||
|
|
||||||
network:
|
network:
|
||||||
name: kiwi_hub
|
name: kiwi_hub
|
||||||
|
|
|
@ -11,7 +11,7 @@ _RE_NUMBER: str = r"[0-9]|[1-9][0-9]*"
|
||||||
RE_SEMVER = rf"^{_RE_NUMBER}(?:\.{_RE_NUMBER}(?:\.{_RE_NUMBER})?)?$"
|
RE_SEMVER = rf"^{_RE_NUMBER}(?:\.{_RE_NUMBER}(?:\.{_RE_NUMBER})?)?$"
|
||||||
|
|
||||||
# regex for a lowercase variable name
|
# regex for a lowercase variable name
|
||||||
RE_VARNAME = r"^[A-Za-z](?:[A-Za-z0-9_-]*[A-Za-z0-9])$"
|
RE_VARNAME = r"^[A-Za-z](?:[A-Za-z0-9\._-]*[A-Za-z0-9])$"
|
||||||
|
|
||||||
#############
|
#############
|
||||||
# ENVIRONMENT
|
# ENVIRONMENT
|
||||||
|
|
|
@ -49,29 +49,35 @@ class _Project(BaseModel):
|
||||||
class _Network(BaseModel):
|
class _Network(BaseModel):
|
||||||
"""a network subsection"""
|
"""a network subsection"""
|
||||||
|
|
||||||
name: constr(
|
name: constr(to_lower=True, regex=RE_VARNAME)
|
||||||
to_lower=True,
|
|
||||||
regex=RE_VARNAME
|
|
||||||
)
|
|
||||||
cidr: IPv4Network
|
cidr: IPv4Network
|
||||||
|
|
||||||
|
|
||||||
class Config(BaseModel):
|
class Config(BaseModel):
|
||||||
"""represents a kiwi.yml"""
|
"""represents a kiwi.yml"""
|
||||||
|
|
||||||
version: constr(
|
version: constr(regex=RE_SEMVER) = "0.2.0"
|
||||||
regex=RE_SEMVER
|
|
||||||
)
|
shells: Optional[List[str]] = [
|
||||||
shells: Optional[List[str]]
|
"/bin/bash",
|
||||||
environment: Optional[Dict[str, Optional[str]]]
|
]
|
||||||
|
|
||||||
|
environment: Dict[str, Optional[str]] = {}
|
||||||
|
|
||||||
projects: Optional[List[_Project]]
|
projects: Optional[List[_Project]]
|
||||||
storage: _Storage
|
|
||||||
network: _Network
|
storage: _Storage = _Storage.parse_obj({
|
||||||
|
"directory": "/var/local/kiwi",
|
||||||
|
})
|
||||||
|
|
||||||
|
network: _Network = _Network.parse_obj({
|
||||||
|
"name": "kiwi_hub",
|
||||||
|
"cidr": "10.22.46.0/24",
|
||||||
|
})
|
||||||
|
|
||||||
@validator("environment", pre=True)
|
@validator("environment", pre=True)
|
||||||
@classmethod
|
@classmethod
|
||||||
def unify_environment(cls, value) -> Optional[Dict[str, Optional[str]]]:
|
def unify_environment(cls, value) -> Dict[str, Optional[str]]:
|
||||||
"""parse different environment notations"""
|
"""parse different environment notations"""
|
||||||
|
|
||||||
def parse_str(var_val: str) -> (str, Optional[str]):
|
def parse_str(var_val: str) -> (str, Optional[str]):
|
||||||
|
@ -87,7 +93,7 @@ class Config(BaseModel):
|
||||||
|
|
||||||
if value is None:
|
if value is None:
|
||||||
# empty environment
|
# empty environment
|
||||||
return None
|
return {}
|
||||||
|
|
||||||
elif isinstance(value, dict):
|
elif isinstance(value, dict):
|
||||||
# native dict format
|
# native dict format
|
||||||
|
|
|
@ -1,13 +0,0 @@
|
||||||
version: 0.2.0
|
|
||||||
shells:
|
|
||||||
- /bin/bash
|
|
||||||
projects:
|
|
||||||
- name: admin
|
|
||||||
enabled: true
|
|
||||||
- Test:
|
|
||||||
- test2: false
|
|
||||||
storage:
|
|
||||||
directory: /var/local/kiwi
|
|
||||||
network:
|
|
||||||
name: kiwi_hub
|
|
||||||
cidr: 10.22.46.0/24
|
|
|
@ -3,12 +3,15 @@ import yaml
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
with open("./kiwi_scp/data/etc/kiwi_default.yml") as kc:
|
with open("./example/kiwi.yml") as kc:
|
||||||
yml = yaml.safe_load(kc)
|
yml = yaml.safe_load(kc)
|
||||||
kiwi = Config(**yml)
|
kiwi = Config(**yml)
|
||||||
|
|
||||||
print(repr(kiwi))
|
print(repr(kiwi))
|
||||||
|
|
||||||
|
kiwi = Config()
|
||||||
|
print(repr(kiwi))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Reference in a new issue