default.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/usr/bin/env python
  2. """
  3. Licensed to the Apache Software Foundation (ASF) under one
  4. or more contributor license agreements. See the NOTICE file
  5. distributed with this work for additional information
  6. regarding copyright ownership. The ASF licenses this file
  7. to you under the Apache License, Version 2.0 (the
  8. "License"); you may not use this file except in compliance
  9. with the License. You may obtain a copy of the License at
  10. http://www.apache.org/licenses/LICENSE-2.0
  11. Unless required by applicable law or agreed to in writing, software
  12. distributed under the License is distributed on an "AS IS" BASIS,
  13. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. See the License for the specific language governing permissions and
  15. limitations under the License.
  16. Ambari Agent
  17. """
  18. __all__ = ["default"]
  19. from resource_management.libraries.script import Script
  20. from resource_management.libraries.script.config_dictionary import UnknownConfiguration
  21. from resource_management.core.logger import Logger
  22. default_subdict='/configurations/global'
  23. def default(name, default_value):
  24. subdicts = filter(None, name.split('/'))
  25. if not name.startswith('/'):
  26. subdicts = filter(None, default_subdict.split('/')) + subdicts
  27. curr_dict = Script.get_config()
  28. for x in subdicts:
  29. if x in curr_dict:
  30. curr_dict = curr_dict[x]
  31. else:
  32. if not isinstance(default_value, UnknownConfiguration):
  33. Logger.debug("Cannot find configuration: '%s'. Using '%s' value as default" % (name, default_value))
  34. return default_value
  35. return curr_dict