Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def connect(module):
''' Connects to CVP device using user provided credentials from playbook.
:param module: Ansible module with parameters and client connection.
:return: CvpClient object with connection instantiated.
'''
client = CvpClient()
try:
client.connect([module.params['host']],
module.params['username'],
module.params['password'],
protocol=module.params['protocol'],
port=module.params['port'])
except CvpLoginError as e:
module.fail_json(msg=str(e))
return client
# Path for git workspace (include trailing /)
gitTempPath = '/tmp/GitConfiglets/'
gitRepo = 'https://github.com/terensapp/cvpbackup'
gitBranch = 'master'
# Relative path within the repo to the configlet directory, leave blank if they reside in the root
configletPath = ''
ignoreConfiglets = ['.git','.md']
# cvpNodes can be a single item or a list of the cluster
cvpNodes = ['54.193.119.19']
cvpUsername = 'arista'
cvpPassword = 'arista'
# Initialize the client
cvpClient = CvpClient()
# Attempt to connect to CVP, if it's not available wait 60 seconds
attempts = 0
while 1:
try:
cvpClient.connect(cvpNodes, cvpUsername, cvpPassword)
if cvpClient.api.get_cvp_info()['version']:
break
except:
attempts += 1
print "Cannot connect to CVP waiting 1 minute attempt",attempts
time.sleep(60)
# Function to sync configlet to CVP
def syncConfiglet(cvpClient,configletName,configletConfig):
if module.params['auto_run'] and module.params['action'] != 'show':
task_id = configlet_update_task(module)
if task_id:
result['taskId'] = task_id
note = ('Update config on %s with %s action from Ansible.'
% (module.params['switch_name'],
module.params['action']))
module.client.api.add_note_to_task(task_id, note)
module.client.api.execute_task(task_id)
result['taskExecuted'] = True
task_completed = wait_for_task_completion(module, task_id)
if task_completed:
result['taskCompleted'] = True
else:
result['taskCreated'] = False
except CvpApiError as e:
module.fail_json(msg=str(e))
module.exit_json(**result)
def connect(module):
''' Connects to CVP device using user provided credentials from playbook.
:param module: Ansible module with parameters and client connection.
:return: CvpClient object with connection instantiated.
'''
client = CvpClient()
try:
client.connect([module.params['host']],
module.params['username'],
module.params['password'],
protocol=module.params['protocol'],
port=module.params['port'])
except CvpLoginError as e:
module.fail_json(msg=str(e))
return client