|
5 | 5 | from ansible.module_utils.basic import AnsibleModule
|
6 | 6 |
|
7 | 7 |
|
8 |
| -def get_macsec_profile(module, macsec_profile): |
| 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): |
9 | 26 | with open('/tmp/profile.json') as f:
|
10 | 27 | macsec_profiles = json.load(f)
|
11 | 28 |
|
12 | 29 | profile = macsec_profiles.get(macsec_profile)
|
13 | 30 | if profile:
|
14 | 31 | profile['macsec_profile'] = macsec_profile
|
15 | 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 | + |
16 | 39 | return profile
|
17 | 40 |
|
18 | 41 |
|
19 | 42 | def main():
|
20 |
| - module = AnsibleModule(argument_spec=dict(macsec_profile=dict(required=True, type='str'))) |
| 43 | + module = AnsibleModule(argument_spec=dict( |
| 44 | + macsec_profile=dict(required=True, type='str'), |
| 45 | + vm_type=dict(required=True, type='str'))) |
21 | 46 |
|
22 | 47 | macsec_profile = module.params['macsec_profile']
|
23 |
| - module.exit_json(profile=get_macsec_profile(module, macsec_profile), changed=False) |
| 48 | + vm_type = module.params['vm_type'] |
| 49 | + module.exit_json(profile=get_macsec_profile(module, macsec_profile, vm_type), changed=False) |
24 | 50 |
|
25 | 51 |
|
26 | 52 | if __name__ == "__main__":
|
|
0 commit comments