|
| 1 | +#!/usr/bin/python |
| 2 | +# -*- coding: utf-8 -*- |
| 3 | + |
| 4 | +import json |
| 5 | +from ansible.module_utils.basic import AnsibleModule |
| 6 | + |
| 7 | + |
| 8 | +def convert_to_eos(cipher_name): |
| 9 | + # Set the cipher suite as 256 xpn by default |
| 10 | + eos_cipher_name = 'aes256-gcm-xpn' |
| 11 | + |
| 12 | + if cipher_name == 'GCM-AES-XPN-256': |
| 13 | + eos_cipher_name = 'aes256-gcm-xpn' |
| 14 | + elif cipher_name == 'GCM-AES-128': |
| 15 | + eos_cipher_name = 'aes128-gcm' |
| 16 | + elif cipher_name == 'GCM-AES-256': |
| 17 | + eos_cipher_name = 'aes256-gcm' |
| 18 | + elif cipher_name == 'GCM-AES-XPN-128': |
| 19 | + eos_cipher_name = 'aes128-gcm-xpn' |
| 20 | + |
| 21 | + return eos_cipher_name |
| 22 | + |
| 23 | + |
| 24 | +# This API support EoS based templates now |
| 25 | +def get_macsec_profile(module, macsec_profile, vm_type): |
| 26 | + with open('/tmp/profile.json') as f: |
| 27 | + macsec_profiles = json.load(f) |
| 28 | + |
| 29 | + profile = macsec_profiles.get(macsec_profile) |
| 30 | + if profile: |
| 31 | + profile['macsec_profile'] = macsec_profile |
| 32 | + |
| 33 | + # Currently handling ceos, add more cases for vsonic etc |
| 34 | + if vm_type == 'ceos': |
| 35 | + # Get the cipher suite in eos terminology |
| 36 | + eos_cipher_suite_name = convert_to_eos(profile['cipher_suite']) |
| 37 | + profile['cipher_suite'] = eos_cipher_suite_name |
| 38 | + |
| 39 | + return profile |
| 40 | + |
| 41 | + |
| 42 | +def main(): |
| 43 | + module = AnsibleModule(argument_spec=dict( |
| 44 | + macsec_profile=dict(required=True, type='str'), |
| 45 | + vm_type=dict(required=True, type='str'))) |
| 46 | + |
| 47 | + macsec_profile = module.params['macsec_profile'] |
| 48 | + vm_type = module.params['vm_type'] |
| 49 | + module.exit_json(profile=get_macsec_profile(module, macsec_profile, vm_type), changed=False) |
| 50 | + |
| 51 | + |
| 52 | +if __name__ == "__main__": |
| 53 | + main() |
0 commit comments