removed etc/hosts.yml which shouldn't be checked in. added support for some more commands. got much of the ssh keygen behavior implemented. zone add / remote / list works now.
This commit is contained in:
parent
727c83a5b1
commit
3ff5cc7222
|
@ -1,4 +0,0 @@
|
|||
blue2: {IPAddr: addr, Services: '', Zone: ''}
|
||||
blue3: {IPAddr: addr3, Services: '', Zone: ''}
|
||||
host1: {IPAddr: ip, Services: '', Zone: ''}
|
||||
host2: {IPAddr: ip, Services: '', Zone: ''}
|
|
@ -83,3 +83,12 @@ class Upgrade(Command):
|
|||
|
||||
def take_action(self, parsed_args):
|
||||
self.log.info(_("upgrade"))
|
||||
|
||||
|
||||
class Dump(Command):
|
||||
"Dump"
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
self.log.info(_("dump"))
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
import logging
|
||||
|
||||
from kollaclient.i18n import _
|
||||
from kollaclient.utils import read_etc_yaml
|
||||
from kollaclient.sshutils import ssh_keygen
|
||||
from kollaclient.utils import load_etc_yaml
|
||||
from kollaclient.utils import save_etc_yaml
|
||||
|
||||
from cliff.command import Command
|
||||
|
@ -22,13 +23,13 @@ class HostAdd(Command):
|
|||
def take_action(self, parsed_args):
|
||||
hostname = parsed_args.hostname
|
||||
ipaddr = parsed_args.ipaddress
|
||||
contents = read_etc_yaml('hosts.yml')
|
||||
contents = load_etc_yaml('hosts.yml')
|
||||
for host, hostdata in contents.items():
|
||||
if host == hostname:
|
||||
# TODO(bmace) fix message
|
||||
self.log.info(_("host already exists"))
|
||||
return
|
||||
hostEntry = {hostname: {'Services': '', 'IPAddr':
|
||||
hostEntry = {hostname: {'Services': '', 'IPAddress':
|
||||
ipaddr, 'Zone': ''}}
|
||||
contents.update(hostEntry)
|
||||
save_etc_yaml('hosts.yml', contents)
|
||||
|
@ -47,7 +48,7 @@ class HostRemove(Command):
|
|||
|
||||
def take_action(self, parsed_args):
|
||||
hostname = parsed_args.hostname
|
||||
contents = read_etc_yaml('hosts.yml')
|
||||
contents = load_etc_yaml('hosts.yml')
|
||||
foundHost = False
|
||||
for host, hostdata in contents.items():
|
||||
if host == hostname:
|
||||
|
@ -67,7 +68,7 @@ class HostList(Command):
|
|||
|
||||
def take_action(self, parsed_args):
|
||||
self.log.info(_("host list"))
|
||||
contents = read_etc_yaml('hosts.yml')
|
||||
contents = load_etc_yaml('hosts.yml')
|
||||
# TODO(bmace) fix output format
|
||||
for host, hostdata in contents.items():
|
||||
self.log.info(host)
|
||||
|
@ -102,3 +103,58 @@ class HostRemoveservice(Command):
|
|||
def take_action(self, parsed_args):
|
||||
self.log.info(_("host removeservice"))
|
||||
self.app.stdout.write(parsed_args)
|
||||
|
||||
|
||||
class HostCheck(Command):
|
||||
"Host Check"
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(HostCheck, self).get_parser(prog_name)
|
||||
parser.add_argument('hostname')
|
||||
# TODO(bmace) error if arg missing
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
self.log.info(_("host check"))
|
||||
hostname = parsed_args.hostname
|
||||
contents = load_etc_yaml('hosts.yml')
|
||||
hostFound = False
|
||||
for host, hostdata in contents.items():
|
||||
if host == hostname:
|
||||
# TODO(bmace) fix message
|
||||
hostFound = True
|
||||
self.log.info(hostdata['IPAddress'])
|
||||
return
|
||||
|
||||
if hostFound is False:
|
||||
self.log.info("no host by name (" + hostname + ") found")
|
||||
|
||||
|
||||
class HostInstall(Command):
|
||||
"Host Install"
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(HostInstall, self).get_parser(prog_name)
|
||||
parser.add_argument('hostname')
|
||||
# TODO(bmace) error if arg missing
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
self.log.info(_("host install"))
|
||||
ssh_keygen()
|
||||
hostname = parsed_args.hostname
|
||||
contents = load_etc_yaml('hosts.yml')
|
||||
hostFound = False
|
||||
for host, hostdata in contents.items():
|
||||
if host == hostname:
|
||||
# TODO(bmace) fix message
|
||||
hostFound = True
|
||||
self.log.info(hostdata['IPAddress'])
|
||||
return
|
||||
|
||||
if hostFound is False:
|
||||
self.log.info("no host by name (" + hostname + ") found")
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
import logging
|
||||
import paramiko
|
||||
|
||||
from kollaclient.utils import get_pk_bits
|
||||
from kollaclient.utils import get_pk_file
|
||||
from kollaclient.utils import get_pk_password
|
||||
|
||||
|
||||
def ssh_connect(hostname):
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
log.info("ssh connect " + hostname)
|
||||
# ssh = paramiko.SSHClient()
|
||||
# privateKey = paramiko.RSAKey.from_private_key_file(get_pk_file())
|
||||
# ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
return
|
||||
|
||||
|
||||
def ssh_keygen():
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
try:
|
||||
log.info("keygen")
|
||||
privateKey = paramiko.RSAKey.generate(get_pk_bits())
|
||||
log.info("writekey")
|
||||
privateKey.write_private_key_file(filename=get_pk_file(),
|
||||
password=get_pk_password())
|
||||
log.info("genpubkey")
|
||||
publicKey = paramiko.RSAKey(filename=get_pk_file(),
|
||||
password=get_pk_password())
|
||||
log.info("writepubkey")
|
||||
with open("%s.pub" % get_pk_file(), 'w') as pubFile:
|
||||
pubFile.write("%s %s" % (publicKey.get_name(),
|
||||
publicKey.get_base64()))
|
||||
log.info("donekeygen")
|
||||
except Exception as e:
|
||||
print e
|
||||
print type(e)
|
||||
print e.args
|
|
@ -17,17 +17,35 @@ def get_kolla_etc():
|
|||
return get_env("KOLLA_ETC", "/etc")
|
||||
|
||||
|
||||
def get_client_etc():
|
||||
return get_env("KOLLA_CLIENT_ETC", "/etc/kollaclient/")
|
||||
|
||||
|
||||
def get_client_home():
|
||||
return get_env("KOLLA_CLIENT_HOME", "/opt/kollaclient/")
|
||||
|
||||
|
||||
def read_etc_yaml(fileName):
|
||||
with open(get_client_etc() + fileName, 'r') as f:
|
||||
return yaml.load(f)
|
||||
def get_client_etc():
|
||||
return get_env("KOLLA_CLIENT_ETC", "/etc/kollaclient/etc/")
|
||||
|
||||
|
||||
def get_pk_file():
|
||||
return get_env("KOLLA_CLIENT_PKPATH", "/opt/kollaclient/etc/id_rsa")
|
||||
|
||||
|
||||
def get_pk_password():
|
||||
# TODO(bmace) what to do here? pull from a file?
|
||||
return ""
|
||||
|
||||
|
||||
def get_pk_bits():
|
||||
return 1024
|
||||
|
||||
|
||||
def load_etc_yaml(fileName):
|
||||
try:
|
||||
with open(get_client_etc() + fileName, 'r') as f:
|
||||
return yaml.load(f)
|
||||
except Exception:
|
||||
# TODO(bmace) if file doesn't exist on a load we don't
|
||||
# want to blow up, some better behavior here?
|
||||
return {}
|
||||
|
||||
|
||||
def save_etc_yaml(fileName, contents):
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
import logging
|
||||
|
||||
from kollaclient.i18n import _
|
||||
from kollaclient.util import load_etc_yaml
|
||||
from kollaclient.util import save_etc_yaml
|
||||
|
||||
from cliff.command import Command
|
||||
|
||||
|
@ -10,9 +12,22 @@ class ZoneAdd(Command):
|
|||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(ZoneAdd, self).get_parser(prog_name)
|
||||
parser.add_argument('zonename')
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
self.log.info(_("zone add"))
|
||||
self.app.stdout.write(parsed_args)
|
||||
zonename = parsed_args.zonename
|
||||
contents = load_etc_yaml('zone.yml')
|
||||
for zone in contents:
|
||||
if zone == zonename:
|
||||
# TODO(bmace) fix message
|
||||
self.log.info(_("zone already exists"))
|
||||
return
|
||||
zoneEntry = {zonename: {'': ''}}
|
||||
contents.update(zoneEntry)
|
||||
save_etc_yaml('zone.yml', contents)
|
||||
|
||||
|
||||
class ZoneRemove(Command):
|
||||
|
@ -20,9 +35,24 @@ class ZoneRemove(Command):
|
|||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(ZoneRemove, self).get_parser(prog_name)
|
||||
parser.add_argument('zonename')
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
self.log.info(_("zone remove"))
|
||||
self.app.stdout.write(parsed_args)
|
||||
zonename = parsed_args.zonename
|
||||
contents = load_etc_yaml('zone.yml')
|
||||
foundZone = False
|
||||
for zone in contents.items():
|
||||
if zone == zonename:
|
||||
foundZone = True
|
||||
if foundZone:
|
||||
del contents[zonename]
|
||||
else:
|
||||
# TODO(bmace) fix message
|
||||
self.log.info("no zone iby name (" + zonename + ") found")
|
||||
save_etc_yaml('zone.yml', contents)
|
||||
|
||||
|
||||
class ZoneList(Command):
|
||||
|
@ -32,4 +62,6 @@ class ZoneList(Command):
|
|||
|
||||
def take_action(self, parsed_args):
|
||||
self.log.info(_("zone list"))
|
||||
self.app.stdout.write(parsed_args)
|
||||
contents = load_etc_yaml('zone.yml')
|
||||
for zone in contents:
|
||||
self.log.info(zone)
|
||||
|
|
|
@ -2,6 +2,7 @@ Babel>=1.3
|
|||
cliff>=1.10.0 # Apache-2.0
|
||||
docker-py>=1.3
|
||||
oslo.i18n>=1.5.0 # Apache-2.0
|
||||
paramiko
|
||||
pbr>=0.11,<2.0
|
||||
PyYAML
|
||||
six>=1.9.0
|
||||
|
|
|
@ -37,6 +37,8 @@ kolla.client =
|
|||
host_setzone = kollaclient.host:HostSetzone
|
||||
host_addservice = kollaclient.host:HostAddservice
|
||||
host_removeservice = kollaclient.host:HostRemoveservice
|
||||
host_check = kollaclient.host:HostCheck
|
||||
host_install = kollaclient.host:HostInstall
|
||||
service_activate = kollaclient.service:ServiceEnable
|
||||
service_deactivate = kollaclient.service:ServiceDisable
|
||||
service_autodeploy = kollaclient.service:ServiceAutodeploy
|
||||
|
@ -53,6 +55,7 @@ kolla.client =
|
|||
stop = kollaclient.common:Stop
|
||||
sync = kollaclient.common:Sync
|
||||
upgrade = kollaclient.common:Upgrade
|
||||
dump = kollaclient.common:Dump
|
||||
|
||||
[extract_messages]
|
||||
keywords = _ gettext ngettext l_ lazy_gettext
|
||||
|
|
Loading…
Reference in New Issue