Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Update Cloudify Manager Provider Context (4.1.1) - Modify Task Retries/Task Retry Interval/Agent Key Path/etc
# Assuming you are using a Python shell like ipython.
# Create a Virtual env: `mktmpenv`
# Install Cloudify: `pip install cloudify`
# Open ipython: `ipython`.
from cloudify_rest_client import CloudifyClient
from copy import deepcopy
import json
manager_ip = '106.105.105.105' # Set your own value here.
tenant = 'default_tenant'
username = 'admin' # Set your own value here.
password = 'admin' # Set your own value here.
client = CloudifyClient(host=manager_ip, tenant=tenant, username=username, password=password)
provider_context = client.manager.get_context()
cloudify_context = provider_context.get('context', {}).get('cloudify', {})
# If you want to update the Task Retries/Task Retry Interval
new_task_retries = 5 # The default is 60.
new_task_retry_interval = 1 # The default is 15.
cloudify_context['workflows']['task_retries'] = new_task_retries
cloudify_context['workflows']['task_retry_interval'] = new_task_retry_interval
# If you want to delete the agent_key_path from Cloudify Agent
agent_key_path_exists = 'agent_key_path' in cloudify_context.get('cloudify_agent', {}).keys() # Make sure the path is there before running del.
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.
if agent_key_path_exists and old_agent_key_path == None or old_agent_key_path == '':
del cloudify_context['cloudify_agent']['agent_key_path']
# Get the current context in case it has changed since you last got it.
current_provider_context = client.manager.get_context()
# Make a copy and store it in case you screwed up. See below for instructions to restore.
current_provider_context_copy = deepcopy(current_provider_context)
backup_file_name = 'backup_provider_context.json'
with open(backup_file_name, 'w') as outfile:
json.dump(current_provider_context_copy, outfile)
# Add your changes to the current context.
current_provider_context['context']['cloudify'] = cloudify_context # This has all of your changes.
# Update the context on the Manager
client.manager.update_context(name='provider', context=current_provider_context['context'])
# Roll-back if you screwed up
with open(backup_file_name, 'r') as infile:
current_provider_context_backup = json.load(infile)
# Update the context on the Manager
client.manager.update_context(name='provider', context=current_provider_context_backup['context'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.