Advertisement
Guest User

Untitled

a guest
Aug 30th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. # Assuming you are using a Python shell like ipython.
  2. # Create a Virtual env: `mktmpenv`
  3. # Install Cloudify: `pip install cloudify`
  4. # Open ipython: `ipython`.
  5.  
  6. from cloudify_rest_client import CloudifyClient
  7. from copy import deepcopy
  8. import json
  9.  
  10. manager_ip = '106.105.105.105' # Set your own value here.
  11. tenant = 'default_tenant'
  12. username = 'admin' # Set your own value here.
  13. password = 'admin' # Set your own value here.
  14.  
  15. client = CloudifyClient(host=manager_ip, tenant=tenant, username=username, password=password)
  16. provider_context = client.manager.get_context()
  17. cloudify_context = provider_context.get('context', {}).get('cloudify', {})
  18.  
  19. # If you want to update the Task Retries/Task Retry Interval
  20. new_task_retries = 5 # The default is 60.
  21. new_task_retry_interval = 1 # The default is 15.
  22. cloudify_context['workflows']['task_retries'] = new_task_retries
  23. cloudify_context['workflows']['task_retry_interval'] = new_task_retry_interval
  24.  
  25. # If you want to delete the agent_key_path from Cloudify Agent
  26. agent_key_path_exists = 'agent_key_path' in cloudify_context.get('cloudify_agent', {}).keys() # Make sure the path is there before running del.
  27. old_agent_key_path = cloudify_context.get('cloudify_agent', {}).get('agent_key_path') # Make sure that the path is not a real value, otherwise you can screw over your partners.
  28. if agent_key_path_exists and old_agent_key_path == None or old_agent_key_path == '':
  29. del cloudify_context['cloudify_agent']['agent_key_path']
  30.  
  31. # Get the current context in case it has changed since you last got it.
  32. current_provider_context = client.manager.get_context()
  33.  
  34. # Make a copy and store it in case you screwed up. See below for instructions to restore.
  35. current_provider_context_copy = deepcopy(current_provider_context)
  36. backup_file_name = 'backup_provider_context.json'
  37. with open(backup_file_name, 'w') as outfile:
  38. json.dump(current_provider_context_copy, outfile)
  39.  
  40. # Add your changes to the current context.
  41. current_provider_context['context']['cloudify'] = cloudify_context # This has all of your changes.
  42.  
  43. # Update the context on the Manager
  44. client.manager.update_context(name='provider', context=current_provider_context['context'])
  45.  
  46. # Roll-back if you screwed up
  47. with open(backup_file_name, 'r') as infile:
  48. current_provider_context_backup = json.load(infile)
  49.  
  50. # Update the context on the Manager
  51. client.manager.update_context(name='provider', context=current_provider_context_backup['context'])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement