Introduce namestandard flavors
This commit is contained in:
parent
4a8c25923d
commit
1fe899744d
|
@ -2,6 +2,7 @@
|
||||||
import argparse
|
import argparse
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import shlex
|
import shlex
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
|
@ -112,6 +113,12 @@ def get_options() -> dict:
|
||||||
choices=['bind', 'json', 'shell', 'table', 'value', 'yaml'],
|
choices=['bind', 'json', 'shell', 'table', 'value', 'yaml'],
|
||||||
default="json",
|
default="json",
|
||||||
)
|
)
|
||||||
|
create_parser.add_argument(
|
||||||
|
"--namestandard",
|
||||||
|
help="Name of name standard",
|
||||||
|
default='default',
|
||||||
|
dest='namestandard',
|
||||||
|
)
|
||||||
|
|
||||||
delete_parser = subparsers.add_parser("delete")
|
delete_parser = subparsers.add_parser("delete")
|
||||||
delete_parser.add_argument(
|
delete_parser.add_argument(
|
||||||
|
@ -140,6 +147,12 @@ def get_options() -> dict:
|
||||||
help="Keep the configured disk in openstack",
|
help="Keep the configured disk in openstack",
|
||||||
default=False,
|
default=False,
|
||||||
)
|
)
|
||||||
|
delete_parser.add_argument(
|
||||||
|
"--namestandard",
|
||||||
|
help="Name of name standard",
|
||||||
|
default='default',
|
||||||
|
dest='namestandard',
|
||||||
|
)
|
||||||
show_parser = subparsers.add_parser("show")
|
show_parser = subparsers.add_parser("show")
|
||||||
show_parser.add_argument(
|
show_parser.add_argument(
|
||||||
'--format',
|
'--format',
|
||||||
|
@ -157,6 +170,12 @@ def get_options() -> dict:
|
||||||
help="fqdn of server, MUST follow name standard",
|
help="fqdn of server, MUST follow name standard",
|
||||||
required=True,
|
required=True,
|
||||||
)
|
)
|
||||||
|
show_parser.add_argument(
|
||||||
|
"--namestandard",
|
||||||
|
help="Name of name standard",
|
||||||
|
default='default',
|
||||||
|
dest='namestandard',
|
||||||
|
)
|
||||||
|
|
||||||
argcomplete.autocomplete(parser)
|
argcomplete.autocomplete(parser)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
@ -164,7 +183,7 @@ def get_options() -> dict:
|
||||||
# This is an opinionated name standard that we follow, and WILL rely on for various automation tasks
|
# This is an opinionated name standard that we follow, and WILL rely on for various automation tasks
|
||||||
fqdn = args.fqdn
|
fqdn = args.fqdn
|
||||||
domain, environment, function, hostname, instance, location, number, service = parse_fqdn(
|
domain, environment, function, hostname, instance, location, number, service = parse_fqdn(
|
||||||
fqdn)
|
fqdn, args.namestandard)
|
||||||
|
|
||||||
# We will allways put a server in i server group, you can override the default with the --sgroup switch
|
# We will allways put a server in i server group, you can override the default with the --sgroup switch
|
||||||
if ('sgroup' not in args) or (args.sgroup == ""):
|
if ('sgroup' not in args) or (args.sgroup == ""):
|
||||||
|
@ -183,6 +202,7 @@ def get_options() -> dict:
|
||||||
'hostname': hostname,
|
'hostname': hostname,
|
||||||
'instance': instance,
|
'instance': instance,
|
||||||
'location': location,
|
'location': location,
|
||||||
|
'namestandard': args.namestandard,
|
||||||
'number': number,
|
'number': number,
|
||||||
'service': service,
|
'service': service,
|
||||||
'sgroup': sgroup
|
'sgroup': sgroup
|
||||||
|
@ -204,8 +224,13 @@ def get_options() -> dict:
|
||||||
|
|
||||||
return options
|
return options
|
||||||
|
|
||||||
|
def parse_fqdn(fqdn: str, namestandard: str) -> tuple:
|
||||||
|
if namestandard == 'drive':
|
||||||
|
return parse_drive_fqdn(fqdn)
|
||||||
|
else:
|
||||||
|
return parse_default_fqdn(fqdn)
|
||||||
|
|
||||||
def parse_fqdn(fqdn: str) -> tuple:
|
def parse_default_fqdn(fqdn: str) -> tuple:
|
||||||
domain = '.'.join([x for x in fqdn.split('.')[:1]])
|
domain = '.'.join([x for x in fqdn.split('.')[:1]])
|
||||||
hostname = fqdn.split('.')[0]
|
hostname = fqdn.split('.')[0]
|
||||||
instance, location, environment, function, number = hostname.split('-')
|
instance, location, environment, function, number = hostname.split('-')
|
||||||
|
@ -213,6 +238,41 @@ def parse_fqdn(fqdn: str) -> tuple:
|
||||||
return domain, environment, function, hostname, instance, location, number, service
|
return domain, environment, function, hostname, instance, location, number, service
|
||||||
|
|
||||||
|
|
||||||
|
def parse_drive_fqdn(fqdn: str) -> tuple:
|
||||||
|
type_regex = r'-*[1-9]*\..*'
|
||||||
|
server_type = re.sub(type_regex, '', fqdn)
|
||||||
|
|
||||||
|
env_regex = r'.*(pilot|test).*'
|
||||||
|
environment = re.sub(env_regex, r'\1', fqdn)
|
||||||
|
domain = f'drive.{environment}.sunet.se'
|
||||||
|
customer = 'common'
|
||||||
|
|
||||||
|
if environment not in ['pilot', 'test']:
|
||||||
|
environment = 'prod'
|
||||||
|
domain = 'drive.sunet.se'
|
||||||
|
|
||||||
|
if server_type in ["backup", "intern-db", "node", "redis", "script"]:
|
||||||
|
customer = fqdn.split('.')[1]
|
||||||
|
if customer == 'drive':
|
||||||
|
customer = 'common'
|
||||||
|
elif server_type in ['gss', 'lookup']:
|
||||||
|
customer = server_type
|
||||||
|
elif server_type == 'gssbackup':
|
||||||
|
customer = 'gss'
|
||||||
|
elif server_type == 'lookupbackup':
|
||||||
|
customer = 'lookup'
|
||||||
|
else:
|
||||||
|
customer = 'common'
|
||||||
|
hostname = fqdn.split('.')[0]
|
||||||
|
number = re.sub(r'[a-z.]', '', hostname)
|
||||||
|
location = 'sto4'
|
||||||
|
if number == '3':
|
||||||
|
location = 'sto3'
|
||||||
|
if number == '1':
|
||||||
|
location = 'dco'
|
||||||
|
return domain, environment, server_type, hostname, customer, location, number, 'drive'
|
||||||
|
|
||||||
|
|
||||||
def run_in_openstack(outer_command: list[str], rc_file: str) -> tuple:
|
def run_in_openstack(outer_command: list[str], rc_file: str) -> tuple:
|
||||||
|
|
||||||
# This function runs the specified command with openstack cli using tsocks.
|
# This function runs the specified command with openstack cli using tsocks.
|
||||||
|
|
Loading…
Reference in a new issue