-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #136 from ccamacho/agentui
feat: add simple agent skeleton
- Loading branch information
Showing
15 changed files
with
586 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
include *.py | ||
include *.yaml | ||
include requirements.txt | ||
recursive-include kubeinit * | ||
global-exclude *pyc | ||
global-exclude .project | ||
global-exclude .pydevproject |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/env python | ||
|
||
""" | ||
Copyright 2019 Kubeinit (kubeinit.com). | ||
Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
not use this file except in compliance with the License. You may obtain | ||
a copy of the License at: | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
License for the specific language governing permissions and limitations | ||
under the License. | ||
""" | ||
|
||
from pkg_resources import get_distribution | ||
|
||
__version__ = get_distribution('kubeinit').version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
#!/usr/bin/env python | ||
|
||
""" | ||
Copyright 2019 Kubeinit (kubeinit.com). | ||
Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
not use this file except in compliance with the License. You may obtain | ||
a copy of the License at: | ||
http://www.apache.com/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
License for the specific language governing permissions and limitations | ||
under the License. | ||
""" | ||
|
||
|
||
import logging | ||
import logging.handlers | ||
import os | ||
import threading | ||
from argparse import ArgumentParser | ||
|
||
from kubeinit import __version__ | ||
from kubeinit.const import KUBEINIT_LOG_FILE | ||
from kubeinit.get_banner import get_banner | ||
from kubeinit.lib import connect_to_aas, connect_to_aas2 | ||
|
||
|
||
kubeinit_version = __version__ | ||
|
||
t1_stop = threading.Event() | ||
t2_stop = threading.Event() | ||
|
||
handler = logging.handlers.WatchedFileHandler( | ||
KUBEINIT_LOG_FILE) | ||
formatter = logging.Formatter(logging.BASIC_FORMAT) | ||
handler.setFormatter(formatter) | ||
root = logging.getLogger() | ||
root.setLevel(os.environ.get("LOGLEVEL", "INFO")) | ||
root.addHandler(handler) | ||
|
||
|
||
def main(): | ||
""" | ||
Application's entry point. | ||
Here, application's settings are read from the command line, | ||
environment variables and CRD. Then, retrieving and processing | ||
of Kubernetes events are initiated. | ||
""" | ||
parser = ArgumentParser( | ||
description='Kubeinit - CLI', | ||
prog='kubeinit' | ||
) | ||
|
||
parser.add_argument( | ||
'-v', | ||
'--version', | ||
action='version', | ||
version='%(prog)s ' + kubeinit_version | ||
) | ||
|
||
parser.add_argument( | ||
'-b', | ||
'--banner', | ||
action='store_true', | ||
help='Print Kubeinit.com banner' | ||
) | ||
|
||
subparsers = parser.add_subparsers(title="Kubeinit subcommands", | ||
dest="command", | ||
help=("These are the options " | ||
"supported: \n" | ||
"The listen option will " | ||
"watch for CRD events. " | ||
"The run option will " | ||
"execute the Kubeinit " | ||
"actions against the cluster.")) | ||
|
||
parser_connect = subparsers.add_parser('connect', help=("CLI options to run the " | ||
"Kubeinit actions.")) | ||
|
||
parser_connect.add_argument( | ||
'-k', | ||
'--key', | ||
default="", | ||
type=str, | ||
help=("The connection key:" | ||
"--extra-vars thisisakey" | ||
"Defaults to: empty")) | ||
|
||
subparsers.add_parser('status', help=("Show the connections status.")) | ||
|
||
parser_show = subparsers.add_parser('show', | ||
help=("Get info from a connection.")) | ||
|
||
parser_show.add_argument( | ||
"connection", | ||
nargs='?', | ||
default='', | ||
type=str, | ||
help=("Specify the connection to fetch details")) | ||
|
||
args = parser.parse_args() | ||
|
||
# print("Kubeinit called with the folowing parameters") | ||
# print(parser.parse_args()) | ||
|
||
if args.banner: | ||
print(get_banner()) | ||
exit() | ||
|
||
try: | ||
if (args.command == 'connect'): | ||
print("We will watch for objects to process") | ||
try: | ||
print(args.key) | ||
t1 = threading.Thread(target=connect_to_aas, | ||
args=(t1_stop,)) | ||
t1.start() | ||
t2 = threading.Thread(target=connect_to_aas2, | ||
args=(t2_stop,)) | ||
t2.start() | ||
except Exception as err: | ||
print("Error: unable to start thread: " + err) | ||
elif (args.command == 'status'): | ||
print(u"\U0001F4DA" + " Listing the deployed actions" | ||
" from the cluster.") | ||
print(u"\U0001F4A1" + " For further information use:" | ||
" kubeinit get <action_name> [--debug]") | ||
exit() | ||
elif (args.command == 'show'): | ||
print(u"\U0001F4E4" + " Getting the details from" | ||
" an specific action.") | ||
print(args.connection) | ||
exit() | ||
|
||
except KeyboardInterrupt: | ||
pass | ||
except Exception as err: | ||
raise RuntimeError('There is something wrong...' + err) | ||
|
||
while not t2_stop.is_set() or not t1_stop.is_set(): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/usr/bin/env python | ||
|
||
""" | ||
Copyright 2019 Kubeinit (kubeinit.com). | ||
Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
not use this file except in compliance with the License. You may obtain | ||
a copy of the License at: | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
License for the specific language governing permissions and limitations | ||
under the License. | ||
""" | ||
|
||
import os | ||
import tempfile | ||
|
||
# Main logging file | ||
KUBEINIT_LOG_FOLDER = tempfile.gettempdir() | ||
KUBEINIT_LOG_FILE = os.path.join(KUBEINIT_LOG_FOLDER, '/tmp/kubeinit.log') | ||
|
||
# Current branch | ||
KUBEINIT_BRANCH = 'master' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/usr/bin/env python | ||
|
||
""" | ||
Copyright 2019 Kubeinit (kubeinit.com). | ||
Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
not use this file except in compliance with the License. You may obtain | ||
a copy of the License at: | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
License for the specific language governing permissions and limitations | ||
under the License. | ||
""" | ||
|
||
from kubeinit import __version__ | ||
|
||
kubeinit_version = __version__ | ||
|
||
|
||
def get_banner(): | ||
""" | ||
Get banner method. | ||
This method prints | ||
the kubeinit.com banner. | ||
""" | ||
banner = """ | ||
888 d8P 888 8888888 d8b 888 | ||
888 d8P 888 888 Y8P 888 | ||
888 d8P 888 888 888 | ||
888d88K 888 888 88888b. .d88b. 888 88888b. 888 888888 | ||
8888888b 888 888 888 "88b d8P Y8b 888 888 "88b 888 888 | ||
888 Y88b 888 888 888 888 88888888 888 888 888 888 888 | ||
888 Y88b Y88b 888 888 d88P Y8b. 888 888 888 888 Y88b. | ||
888 Y88b "Y88888 88888P" "Y8888 8888888 888 888 888 "Y888 | ||
(kubeinit.com) agent version {} | ||
""".format(kubeinit_version) | ||
return banner |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/usr/bin/env python | ||
|
||
""" | ||
Copyright 2019 Kubeinit (kubeinit.com). | ||
Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
not use this file except in compliance with the License. You may obtain | ||
a copy of the License at: | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
License for the specific language governing permissions and limitations | ||
under the License. | ||
""" | ||
|
||
|
||
def connect_to_aas(stop, | ||
api_client=None): | ||
""" | ||
Watch for action with timeouts. | ||
This method will listen for custom objects | ||
that times out. | ||
""" | ||
while True: | ||
return True | ||
|
||
|
||
def connect_to_aas2(stop, | ||
api_client=None): | ||
""" | ||
Watch for action with timeouts. | ||
This method will listen for custom objects | ||
that times out. | ||
""" | ||
while True: | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#!/usr/bin/env python | ||
|
||
""" | ||
Copyright 2019 Kubeinit (kubeinit.com). | ||
Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
not use this file except in compliance with the License. You may obtain | ||
a copy of the License at: | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
License for the specific language governing permissions and limitations | ||
under the License. | ||
""" | ||
|
||
import logging | ||
import sys | ||
from logging.handlers import TimedRotatingFileHandler | ||
|
||
from kubeinit.const import KUBEINIT_LOG_FILE | ||
|
||
FORMATTER = logging.Formatter("%(asctime)s - %(name)s - " | ||
"%(levelname)s - %(message)s") | ||
|
||
|
||
def get_console_handler(): | ||
""" | ||
Get logger console handler. | ||
This is a main component of the input for the controller | ||
""" | ||
console_handler = logging.StreamHandler(sys.stdout) | ||
console_handler.setFormatter(FORMATTER) | ||
return console_handler | ||
|
||
|
||
def get_file_handler(): | ||
""" | ||
Get logger file handler. | ||
This is a main component of the input for the controller | ||
""" | ||
file_handler = TimedRotatingFileHandler( | ||
KUBEINIT_LOG_FILE, when='midnight') | ||
file_handler.setFormatter(FORMATTER) | ||
return file_handler | ||
|
||
|
||
def get_logger(logger_name): | ||
""" | ||
Get logger. | ||
This is a main component of the input for the controller | ||
""" | ||
logger = logging.getLogger(logger_name) | ||
logger.setLevel(logging.DEBUG) | ||
# We do not want to print in the console | ||
# logger.addHandler(get_console_handler()) | ||
logger.addHandler(get_file_handler()) | ||
logger.propagate = False | ||
return logger |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
pyyaml | ||
requests | ||
ansible | ||
openshift | ||
j2cli | ||
jinja2 | ||
kubernetes | ||
setuptools | ||
PTable | ||
rich | ||
google-cloud | ||
google-cloud-storage | ||
google-cloud-firestore | ||
|
Oops, something went wrong.