Skip to content

Instantly share code, notes, and snippets.

@chkumar246
Last active September 14, 2018 13:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chkumar246/27a5e9569dc4a6380acec124f2554def to your computer and use it in GitHub Desktop.
Save chkumar246/27a5e9569dc4a6380acec124f2554def to your computer and use it in GitHub Desktop.
host.py
## ToDo
## validation for app_hosts - DONE
## valid fqdn or ip -
## minmal number of hosts is 3
## can handle both space seperated and comma seperated
## Single cluster scenarios : app_hosts == avail_hosts
## Multi cluster : avail_hosts = app_hosts + other_hosts
## All hosts need to be unique
import re
import os
min_hosts = 3
class StorageHosts():
'''
callable methods and validation of the hosts
'''
def __init__(hostname=None, avail_hosts=None, raw_devices=None):
self.app_hosts = app_hosts
self.avail_hosts = avail_hosts
self.raw_devices = raw_devices
def is_valid_hostname(hostname):
if len(hostname) > 255:
return False
def host_not_valid(app_hosts):
for ahosts in app_hosts:
if is_valid_hostname(ahosts) == True:
continue
else:
print "\033[91m %s \033[0m is not valid hostname" % ahosts
exit()
def min_hosts(app_hosts):
if len(app_hosts) < 3:
print "\033[91m Require a minimum of 3 hosts \033[0m"
exit()
def host_in_use(log_hosts):
for lhosts in log_hosts:
if is_valid_hostname(lhosts) == True and lhosts not in app_hosts:
continue
elif is_valid_hostname(lhosts) == True and lhosts in app_hosts:
print "Host: \033[91m %s \033[0m is already used for application hosting" % lhosts
exit()
else:
print "\033[91m %s \033[0m is not valid hostname" % lhosts
exit()
def met_in_use(met_hosts):
for hosts in met_hosts:
if is_valid_hostname(hosts) == True and hosts not in app_hosts:
continue
elif is_valid_hostname(hosts) == True and hosts in app_hosts:
print "Host: \033[91m %s \033[0m is already used for application hosting" % hosts
exit()
else:
print "\033[91m %s \033[0m is not valid hostname" % hosts
exit()
def check_input(no_of_hosts):
hosts_found = re.split(r'[,\s?]', no_of_hosts)
hosts = [host for host in hosts_found if host]
return hosts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment