diff --git a/cli/dcoscli/marathon/main.py b/cli/dcoscli/marathon/main.py index 343c266..30a8581 100644 --- a/cli/dcoscli/marathon/main.py +++ b/cli/dcoscli/marathon/main.py @@ -322,15 +322,18 @@ def _add(app_resource): :rtype: int """ application_resource = _get_resource(app_resource) - schema = _app_schema() + + # Add application to marathon + client = marathon.create_client() + + schema = client.get_app_schema() + if schema is None: + schema = _app_schema() errs = util.validate_json(application_resource, schema) if errs: raise DCOSException(util.list_to_err(errs)) - # Add application to marathon - client = marathon.create_client() - # Check that the application doesn't exist app_id = client.normalize_app_id(application_resource['id']) diff --git a/dcos/marathon.py b/dcos/marathon.py index e3bda5c..4d8056c 100644 --- a/dcos/marathon.py +++ b/dcos/marathon.py @@ -81,6 +81,7 @@ class Client(object): min_version = "0.8.1" version = LooseVersion(self.get_about()["version"]) + self._version = version if version < LooseVersion(min_version): msg = ("The configured Marathon with version {0} is outdated. " + "Please use version {1} or later.").format( @@ -98,6 +99,14 @@ class Client(object): return urllib.parse.urljoin(self._base_uri, path) + def get_version(self): + """Get marathon version + :returns: marathon version + rtype: LooseVersion + """ + + return self._version + def get_about(self): """Returns info about Marathon instance @@ -556,6 +565,23 @@ class Client(object): return task + def get_app_schema(self): + """Returns app json schema + + :returns: application json schema + :rtype: json schema or None if endpoint doesn't exist + """ + + version = self.get_version() + schema_version = LooseVersion("0.9.0") + if version < schema_version: + return None + + url = self._create_url('v2/schemas/app') + response = http.get(url) + + return response.json() + def normalize_app_id(self, app_id): """Normalizes the application id.