diff --git a/Pipfile b/Pipfile index 8c2498a..04ae276 100644 --- a/Pipfile +++ b/Pipfile @@ -14,8 +14,8 @@ verify_ssl = true name = "pypi" [packages] -krux-stdlib = "==3.1.0" -marathon = "==0.11.0" +krux-stdlib = "==4.0.1" +marathon = "==0.12.0" [requires] -python_version = "2.7" +python_version = "3.6" diff --git a/Pipfile.lock b/Pipfile.lock index fd89ddb..04a3f81 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,11 +1,11 @@ { "_meta": { "hash": { - "sha256": "69cb866bef5dfa05049a0599b2a8ca0c9b562838d38ade5b0ab660e07b47f08c" + "sha256": "8b1c55c8304994009f4394446892f6d95987c300955c859acf4b84a129110755" }, "pipfile-spec": 6, "requires": { - "python_version": "2.7" + "python_version": "3.6" }, "sources": [ { @@ -26,33 +26,12 @@ ] }, "default": { - "alabaster": { - "hashes": [ - "sha256:446438bdcca0e05bd45ea2de1668c1d9b032e1a9154c2c259092d77031ddd359", - "sha256:a661d72d58e6ea8a57f7a86e37d86716863ee5e92788398526d58b26a4e4dc02" - ], - "version": "==0.7.12" - }, - "argparse": { - "hashes": [ - "sha256:62b089a55be1d8949cd2bc7e0df0bddb9e028faefc8c32038cc84862aefdd6e4", - "sha256:c31647edb69fd3d465a847ea3157d37bed1f95f19760b11a47aa91c04b666314" - ], - "version": "==1.4.0" - }, - "babel": { - "hashes": [ - "sha256:af92e6106cb7c55286b25b38ad7695f8b4efb36a90ba483d7f7a6628c46158ab", - "sha256:e86135ae101e31e2c8ec20a4e0c5220f4eed12487d5cf3f78be7e98d3a57fc28" - ], - "version": "==2.7.0" - }, "certifi": { "hashes": [ - "sha256:59b7658e26ca9c7339e00f8f4636cdfe59d34fa37b9b04f6f9e9926b3cece1a5", - "sha256:b26104d6835d1f5e49452a26eb2ff87fe7090b89dfcaee5ea2212697e1e1d7ae" + "sha256:017c25db2a153ce562900032d5bc68e9f191e44e9a0f762f373977de9df1fbb3", + "sha256:25b64c7da4cd7479594d035c08c2d809eb4aab3a26e5a990ea98cc450c320f1f" ], - "version": "==2019.3.9" + "version": "==2019.11.28" }, "chardet": { "hashes": [ @@ -61,19 +40,11 @@ ], "version": "==3.0.4" }, - "docutils": { - "hashes": [ - "sha256:02aec4bd92ab067f6ff27a38a38a41173bf01bed8f89157768c1573f53e474a6", - "sha256:51e64ef2ebfb29cae1faa133b3710143496eca21c530f3f71424d77687764274", - "sha256:7a4bd47eaf6596e1295ecb11361139febe29b084a87bf005bf899f9a42edc3c6" - ], - "version": "==0.14" - }, "future": { "hashes": [ - "sha256:67045236dcfd6816dc439556d009594abf643e5eb48992e36beac09c2ca659b8" + "sha256:b1bead90b70cf6ec3f0710ae53a525360fa360d306a86583adc6bf83a4db537d" ], - "version": "==0.17.1" + "version": "==0.18.2" }, "idna": { "hashes": [ @@ -82,30 +53,16 @@ ], "version": "==2.8" }, - "imagesize": { - "hashes": [ - "sha256:3f349de3eb99145973fefb7dbe38554414e5c30abd0c8e4b970a7c9d09f3a1d8", - "sha256:f3832918bc3c66617f92e35f5d70729187676313caa60c187eb0f28b8fe5e3b5" - ], - "version": "==1.1.0" - }, - "jinja2": { - "hashes": [ - "sha256:065c4f02ebe7f7cf559e49ee5a95fb800a9e4528727aec6f24402a5374c65013", - "sha256:14dd6caf1527abb21f08f86c784eac40853ba93edb79552aa1e4b8aef1b61c7b" - ], - "version": "==2.10.1" - }, "krux-stdlib": { "hashes": [ - "sha256:d86d5edd4512de06d80fae8e2d0ffb217a8e724d7092688f3fa242d446be8aed" + "sha256:de6a40138d4226c20e100e5102c8d01e46177bfa16cc4e7c3a06856c65097a4e" ], "index": "kruxprop", - "version": "==3.1.0" + "version": "==4.0.1" }, "kruxstatsd": { "hashes": [ - "sha256:1206c661d819d95a26eef8dcf43f3349a5b3d9fe781c75b254a359cc6695bfc9" + "sha256:f91ff258237303a36fffa3564e282e8a6b0c566fc6ddfec9f6d66d0b509cd618" ], "version": "==0.3.6" }, @@ -118,65 +75,11 @@ }, "marathon": { "hashes": [ - "sha256:42b02afe73b229fdb65c1a044d1d8de858b43dce2df00d9bedc431dfdfa9418a", - "sha256:ff14ac817e691520334332c9903c04c09dfbfa097bc60a408027ade4bc8e425b" + "sha256:ebc636d5736feebe165fbeb2e8f3291113e2f866bcf4edd8f33da92e1afcbb66", + "sha256:ec82e4a40669fca0c94ac6450424672e77ccbb2d1d42cca065198d16ac3d869f" ], "index": "kruxprop", - "version": "==0.11.0" - }, - "markupsafe": { - "hashes": [ - "sha256:00bc623926325b26bb9605ae9eae8a215691f33cae5df11ca5424f06f2d1f473", - "sha256:09027a7803a62ca78792ad89403b1b7a73a01c8cb65909cd876f7fcebd79b161", - "sha256:09c4b7f37d6c648cb13f9230d847adf22f8171b1ccc4d5682398e77f40309235", - "sha256:1027c282dad077d0bae18be6794e6b6b8c91d58ed8a8d89a89d59693b9131db5", - "sha256:24982cc2533820871eba85ba648cd53d8623687ff11cbb805be4ff7b4c971aff", - "sha256:29872e92839765e546828bb7754a68c418d927cd064fd4708fab9fe9c8bb116b", - "sha256:43a55c2930bbc139570ac2452adf3d70cdbb3cfe5912c71cdce1c2c6bbd9c5d1", - "sha256:46c99d2de99945ec5cb54f23c8cd5689f6d7177305ebff350a58ce5f8de1669e", - "sha256:500d4957e52ddc3351cabf489e79c91c17f6e0899158447047588650b5e69183", - "sha256:535f6fc4d397c1563d08b88e485c3496cf5784e927af890fb3c3aac7f933ec66", - "sha256:62fe6c95e3ec8a7fad637b7f3d372c15ec1caa01ab47926cfdf7a75b40e0eac1", - "sha256:6dd73240d2af64df90aa7c4e7481e23825ea70af4b4922f8ede5b9e35f78a3b1", - "sha256:717ba8fe3ae9cc0006d7c451f0bb265ee07739daf76355d06366154ee68d221e", - "sha256:79855e1c5b8da654cf486b830bd42c06e8780cea587384cf6545b7d9ac013a0b", - "sha256:7c1699dfe0cf8ff607dbdcc1e9b9af1755371f92a68f706051cc8c37d447c905", - "sha256:88e5fcfb52ee7b911e8bb6d6aa2fd21fbecc674eadd44118a9cc3863f938e735", - "sha256:8defac2f2ccd6805ebf65f5eeb132adcf2ab57aa11fdf4c0dd5169a004710e7d", - "sha256:98c7086708b163d425c67c7a91bad6e466bb99d797aa64f965e9d25c12111a5e", - "sha256:9add70b36c5666a2ed02b43b335fe19002ee5235efd4b8a89bfcf9005bebac0d", - "sha256:9bf40443012702a1d2070043cb6291650a0841ece432556f784f004937f0f32c", - "sha256:ade5e387d2ad0d7ebf59146cc00c8044acbd863725f887353a10df825fc8ae21", - "sha256:b00c1de48212e4cc9603895652c5c410df699856a2853135b3967591e4beebc2", - "sha256:b1282f8c00509d99fef04d8ba936b156d419be841854fe901d8ae224c59f0be5", - "sha256:b2051432115498d3562c084a49bba65d97cf251f5a331c64a12ee7e04dacc51b", - "sha256:ba59edeaa2fc6114428f1637ffff42da1e311e29382d81b339c1817d37ec93c6", - "sha256:c8716a48d94b06bb3b2524c2b77e055fb313aeb4ea620c8dd03a105574ba704f", - "sha256:cd5df75523866410809ca100dc9681e301e3c27567cf498077e8551b6d20e42f", - "sha256:e249096428b3ae81b08327a63a485ad0878de3fb939049038579ac0ef61e17e7" - ], - "version": "==1.1.1" - }, - "packaging": { - "hashes": [ - "sha256:0c98a5d0be38ed775798ece1b9727178c4469d9c3b4ada66e8e6b7849f8732af", - "sha256:9e1cbf8c12b1f1ce0bb5344b8d7ecf66a6f8a6e91bcb0c84593ed6d3ab5c4ab3" - ], - "version": "==19.0" - }, - "pygments": { - "hashes": [ - "sha256:71e430bc85c88a430f000ac1d9b331d2407f681d6f6aec95e8bcfbc3df5b0127", - "sha256:881c4c157e45f30af185c1ffe8d549d48ac9127433f2c380c24b84572ad66297" - ], - "version": "==2.4.2" - }, - "pyparsing": { - "hashes": [ - "sha256:1873c03321fc118f4e9746baf201ff990ceb915f433f23b395f5580d1840cb2a", - "sha256:9b6323ef4ab914af344ba97510e966d64ba91055d6b9afa6b30799340e89cc03" - ], - "version": "==2.4.0" + "version": "==0.12.0" }, "pystache": { "hashes": [ @@ -184,13 +87,6 @@ ], "version": "==0.5.4" }, - "pytz": { - "hashes": [ - "sha256:303879e36b721603cc54604edcac9d20401bdbe31e1e4fdee5b9f98d5d31dfda", - "sha256:d747dd3d23d77ef44c6a3526e274af6efeb0a6f1afd5a69ba4d5be4098c8e141" - ], - "version": "==2019.1" - }, "requests": { "hashes": [ "sha256:11e007a8a2aa0323f5a921e9e6a2d7e4e67d9877e85773fba9ba6419025cbeb4", @@ -205,34 +101,6 @@ ], "version": "==0.9.1" }, - "six": { - "hashes": [ - "sha256:3350809f0555b11f552448330d0b52d5f24c91a322ea4a15ef22629740f3761c", - "sha256:d16a0141ec1a18405cd4ce8b4613101da75da0e9a7aec5bdd4fa804d0e0eba73" - ], - "version": "==1.12.0" - }, - "snowballstemmer": { - "hashes": [ - "sha256:919f26a68b2c17a7634da993d91339e288964f93c274f1343e3bbbe2096e1128", - "sha256:9f3bcd3c401c3e862ec0ebe6d2c069ebc012ce142cce209c098ccb5b09136e89" - ], - "version": "==1.2.1" - }, - "sphinx": { - "hashes": [ - "sha256:9f3e17c64b34afc653d7c5ec95766e03043cc6d80b0de224f59b6b6e19d37c3c", - "sha256:c7658aab75c920288a8cf6f09f244c6cfdae30d82d803ac1634d9f223a80ca08" - ], - "version": "==1.8.5" - }, - "sphinxcontrib-websupport": { - "hashes": [ - "sha256:1501befb0fdf1d1c29a800fdbf4ef5dc5369377300ddbdd16d2cd40e54c6eefc", - "sha256:e02f717baf02d0b6c3dd62cf81232ffca4c9d5c331e03766982e3ff9f1d2bc3f" - ], - "version": "==1.1.2" - }, "statsd": { "hashes": [ "sha256:c610fb80347fca0ef62666d241bce64184bd7cc1efe582f9690e045c25535eaa", @@ -240,28 +108,12 @@ ], "version": "==3.3.0" }, - "subprocess32": { - "hashes": [ - "sha256:88e37c1aac5388df41cc8a8456bb49ebffd321a3ad4d70358e3518176de3a56b", - "sha256:eb2937c80497978d181efa1b839ec2d9622cf9600a039a79d0e108d1f9aec79d" - ], - "version": "==3.5.4" - }, - "typing": { - "hashes": [ - "sha256:4027c5f6127a6267a435201981ba156de91ad0d1d98e9ddc2aa173453453492d", - "sha256:57dcf675a99b74d64dacf6fba08fb17cf7e3d5fdff53d4a30ea2a5e7e52543d4", - "sha256:a4c8473ce11a65999c8f59cb093e70686b6c84c98df58c1dae9b3b196089858a" - ], - "markers": "python_version < '3.5'", - "version": "==3.6.6" - }, "urllib3": { "hashes": [ - "sha256:b246607a25ac80bedac05c6f282e3cdaf3afb65420fd024ac94435cabe6e18d1", - "sha256:dbe59173209418ae49d485b87d1681aefa36252ee85884c31346debd19463232" + "sha256:a8a318824cc77d1fd4b2bec2ded92646630d7fe8619497b142c84a9e6f5a7293", + "sha256:f3c5fd51747d450d4dcf6f923c81f78f811aab8205fda64b0aba34a4e48b0745" ], - "version": "==1.25.3" + "version": "==1.25.7" } }, "develop": {} diff --git a/krux_marathon_api/__init__.py b/krux_marathon_api/__init__.py index 1f6518e..81343d7 100644 --- a/krux_marathon_api/__init__.py +++ b/krux_marathon_api/__init__.py @@ -1 +1 @@ -VERSION = '0.1.0' +VERSION = '0.2.0' diff --git a/krux_marathon_api/cli.py b/krux_marathon_api/cli.py index 9600a10..25bada5 100755 --- a/krux_marathon_api/cli.py +++ b/krux_marathon_api/cli.py @@ -1,26 +1,19 @@ #!/usr/bin/env python -# # Standard libraries -# -from __future__ import absolute_import import json import os import re import sys -# # Third party libraries -# from marathon import MarathonClient from marathon.util import MarathonJsonEncoder from marathon.client import MarathonHttpError -# # Internal libraries -# from krux.cli import Application, get_group import krux_marathon_api.marathonapi @@ -38,8 +31,8 @@ def __init__(self): self.marathon_list_apps = self.args.list_apps self.json = self.args.json if self.args.config_file: - ### Handles files passed via i.e. ~/some-link.json and it will translate - ### to the proper full location + # Handles files passed via i.e. ~/some-link.json and it will translate + # to the proper full location self.marathon_config_file = os.path.realpath( os.path.expanduser(self.args.config_file) ) @@ -113,8 +106,8 @@ def run_app(self): json config file or using the App name from the command line. """ - ### if not a single modifier is specified, show the usage string instead - ### of segfaulting + # if not a single modifier is specified, show the usage string instead + # of segfaulting if not any([ self.args.list_apps, self.args.config_file, @@ -131,14 +124,14 @@ def run_app(self): password=self.marathon_pass, ) - ### validate socket connection with given host and port + # validate socket connection with given host and port if self.api.connect(self.marathon_host, int(self.marathon_port)): self.logger.info('Connection success') else: self.logger.error('Error connecting to Server') raise IOError('Error connecting to Server') - ### list all apps if flag is called + # list all apps if flag is called if self.marathon_list_apps: apps = self.api.get_marathon_apps(marathon_server) if self.json: @@ -157,7 +150,7 @@ def run_app(self): for app in apps: print('{0} => {1}'.format(app.id, app.cmd)) - ### Config file load, only if we passed the variable + # Config file load, only if we passed the variable if self.marathon_config_file and not self.args.delete: config_file_data = self.api.read_config_file(self.marathon_config_file) @@ -172,15 +165,15 @@ def run_app(self): raise ValueError('Input config file appears to be in the wrong format') for app in apps: - ### get a specific marathon app + # get a specific marathon app marathon_app_result = self.api.get_marathon_app(marathon_server, app, app["id"]) self.logger.info('marathon app before updates: ') self.logger.info(marathon_app_result) - ### update local app data variable with config file values + # update local app data variable with config file values changes_in_json, new_marathon_app = self.api.assign_config_data(app, marathon_app_result) - ### update a marathon app if there was a change in the json file + # update a marathon app if there was a change in the json file if changes_in_json: self.logger.info('marathon app after updates: ') self.api.update_marathon_app(marathon_server, app, new_marathon_app) @@ -191,9 +184,9 @@ def run_app(self): marathon_app_result = self.api.get_marathon_app(marathon_server, config_file_data, self.args.get_app) self.logger.info(marathon_app_result) - ### Delete marathon app + # Delete marathon app if self.args.delete: - ### check if the named app exists + # check if the named app exists try: marathon_app_result = marathon_server.get_app(self.args.delete) self.logger.info('Deleting %s', self.args.delete) diff --git a/krux_marathon_api/marathonapi.py b/krux_marathon_api/marathonapi.py index f18f9f2..ac292e3 100755 --- a/krux_marathon_api/marathonapi.py +++ b/krux_marathon_api/marathonapi.py @@ -1,23 +1,16 @@ #!/usr/bin/env python -# # Standard libraries -# -from __future__ import absolute_import import sys import socket import json -# # Third party libraries -# from marathon.models import MarathonApp -# # Internal libraries -# import krux.logging @@ -55,7 +48,7 @@ def read_config_file(self, config_file): exit with a value of 1 if it cannot open or parse the json file. """ self.logger.info("Reading config file and formatting data from config file : " + config_file) - ### open and load json config file + # open and load json config file try: with open(config_file) as data_file: data = json.load(data_file) @@ -65,21 +58,21 @@ def read_config_file(self, config_file): return data def assign_config_data(self, new_data, old_object): - ### value for if there is a change in our json file from server values + # value for if there is a change in our json file from server values changes_in_json = False - ### iterate through the values that are OK to update (according to marathon-python) - ### and if there are changes flip the changes flag + # iterate through the values that are OK to update (according to marathon-python) + # and if there are changes flip the changes flag new_object = MarathonApp().from_json(new_data) check_attrs = MarathonApp.UPDATE_OK_ATTRIBUTES - ### strip the version because that one changes every time + # strip the version because that one changes every time if 'version' in check_attrs: check_attrs.remove('version') - ### Not sure why gpus get defaulted to None, re-setting to 0 + # Not sure why gpus get defaulted to None, re-setting to 0 if not new_object.gpus: new_object.gpus = 0 for k in sorted(check_attrs): - ### Try to fetch attributes from both objects + # Try to fetch attributes from both objects new_attr = getattr(new_object, k) old_attr = getattr(old_object, k) if k in KruxMarathonClient.ATTRIBUTES_TO_SKIP: @@ -88,11 +81,11 @@ def assign_config_data(self, new_data, old_object): self.logger.debug("%s: <<%s>> is equal to <<%s>>" % (k, old_attr, new_attr)) else: self.logger.debug("%s: updating <<%s>> to <<%s>>" % (k, old_attr, new_attr)) - ### if at least one attribute changes, flip the flag + # if at least one attribute changes, flip the flag changes_in_json = True - ### special case for ports: if you send both to the marathon api, it will return a 500, - ### so you gotta pick one over the other. Usually the port_definitions will be more - ### complete, so that's what we're going with. + # special case for ports: if you send both to the marathon api, it will return a 500, + # so you gotta pick one over the other. Usually the port_definitions will be more + # complete, so that's what we're going with. if getattr(new_object, 'port_definitions', None) and getattr(new_object, 'ports', None): self.logger.warn('Both port and port_definitions are set, using port_definitions only') new_object.ports = [] @@ -124,7 +117,7 @@ def get_marathon_app(self, marathon_server, config_file_data, app_id): marathon_app_result = marathon_server.get_app(app_id) except Exception as e: self.logger.warn("App doesn't exist %s. Exception is %s", app_id, e) - ### App doesn't exist; initialize it + # App doesn't exist; initialize it self.create_marathon_app(marathon_server, config_file_data) marathon_app_result = marathon_server.get_app(config_file_data["id"]) else: @@ -141,10 +134,10 @@ def update_marathon_app(self, marathon_server, config_file_data, marathon_app_re values have changed, the App will be updated on the server, otherwise it makes no changes. """ - ### API call to marathon server to update the app if the values have changed - ### The Marathon package and server API does verification of data so no - ### reason to recheck here. - ### An app can be stuck in a scaling state, force=True keeps us from getting hung. + # API call to marathon server to update the app if the values have changed + # The Marathon package and server API does verification of data so no + # reason to recheck here. + # An app can be stuck in a scaling state, force=True keeps us from getting hung. self.logger.info("Update marathon server with updated app data") marathon_server.update_app(config_file_data["id"], marathon_app_result, force=True, minimal=True) @@ -155,7 +148,7 @@ def create_marathon_app(self, marathon_server, config_file_data): self.logger.info("App wasn't found. Creating new marathon app") self.logger.info(config_file_data["id"]) - ### Initialize app creation and name space + # Initialize app creation and name space marathon_server.create_app(config_file_data["id"], MarathonApp(cmd='test', mem=1, cpus=.01)) self.logger.info("Done creating marathon app.") diff --git a/setup.py b/setup.py index cc4d0ab..5ce0a37 100755 --- a/setup.py +++ b/setup.py @@ -5,10 +5,8 @@ """ Package setup for krux-marathon-api """ -###################### # Standard Libraries # -###################### -from __future__ import absolute_import + from setuptools import setup, find_packages from krux_marathon_api import VERSION @@ -39,5 +37,5 @@ ], }, zip_safe=False, # Don't install a single .egg file, it's harder to debug - python_requires='~=2.7, ~=3.6', + python_requires='~=3.6', )