Skip to content

Commit

Permalink
Merge pull request #26 from jazz-jack/master
Browse files Browse the repository at this point in the history
Сonfirm k8s config file overwrite
  • Loading branch information
ToxicWar authored Nov 25, 2017
2 parents 8bceccd + 3444977 commit d4f754d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
27 changes: 24 additions & 3 deletions apsconnectcli/apsconnect.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
from shutil import copyfile
from xml.etree import ElementTree as xml_et
from datetime import datetime, timedelta
from distutils.util import strtobool
from six.moves import input

import fire
import yaml
Expand Down Expand Up @@ -133,6 +135,11 @@ def init_cluster(self, cluster_endpoint, user, pwd, ca_cert):
os.mkdir(KUBE_DIR_PATH)
print("Created directory [{}]".format(KUBE_DIR_PATH))

if os.path.isfile(KUBE_FILE_PATH):
if not _confirm("Kubernetes configuration file already exists. Overwrite? "):
print("{} configuration update was declined.".format(KUBE_FILE_PATH))
return

with open(KUBE_FILE_PATH, 'w+') as fd:
yaml.safe_dump(auth_template, fd)
print("Config saved [{}]".format(KUBE_FILE_PATH))
Expand Down Expand Up @@ -176,8 +183,8 @@ def check_backend(self):

lbs = core_v1.list_service_for_all_namespaces(label_selector='app=nginx-ingress,'
'component=controller')
if not lbs:
print("Unable to find suitable nginx ingress service."
if not lbs or not lbs.items:
print("Unable to find suitable nginx ingress service. "
"Details https://github.com/jetstack/kube-lego/tree/master/examples/nginx")
sys.exit(1)
if len(lbs.items) > 1:
Expand Down Expand Up @@ -963,7 +970,7 @@ def _check_connector_backend_access(url, timeout=120):

while True:
try:
response = get(url=url, verify=False, timeout=10)
response = get(url=url, timeout=10)

if response.status_code == 200:
print()
Expand Down Expand Up @@ -1026,6 +1033,20 @@ def _get_properties(schema_path):
return properties


def _confirm(prompt):
answer = False
while True:
try:
answer = strtobool(input(prompt))
except ValueError:
continue
except EOFError:
sys.exit(1)
else:
break
return answer


def _check_binding(check_config, get_config_info):
state_not_initiated = "\tNot initiated"
state_is_ready = "\thost: {}\n\tuser: {}"
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ future==0.16.0
osaapi==0.3.12
requests==2.13.0
PyYAML==3.12
kubernetes==1.0.0
kubernetes==1.0.0
six==1.11.0
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
setup(
name='apsconnectcli',
author='Ingram Micro',
version='1.7.13',
version='1.7.14',
keywords='aps apsconnect connector automation',
extras_require={
':python_version<="2.7"': ['backports.tempfile==1.0rc1']},
Expand Down

0 comments on commit d4f754d

Please sign in to comment.