Page MenuHomeDevCentral
Paste P392

roles/router/carp/files/carp-ovh-switch.py
ActivePublic

Authored by dereckson on Sat, Mar 21, 16:04.
#!/usr/bin/env python3
# -------------------------------------------------------------
# Switch CARP MAC at OVH level
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Project: Nasqueron
# Description: Switch MAC address for CARP VIP on router-002 and router-003
# License: BSD-2-Clause
# Source file: roles/router/carp/files/carp-ovh-switch.py
# -------------------------------------------------------------
#
# <auto-generated>
# This file is managed by our rOPS SaltStack repository.
#
# Changes to this file may cause incorrect behavior
# and will be lost if the state is redeployed.
# </auto-generated>
import os
import hvac
import ovh
import sys
from secretsmith.vault.secrets import read_secret
# -------------------------------------------------------------
# Vault - Query OVH API credentials
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CA_PATH="/usr/local/share/certs/nasqueron-vault-ca.crt"
SECRET_MOUNT="apps"
SECRET_PATH="network/carp-hyper-001-switch"
def query_credentials():
client = hvac.Client(verify=CA_PATH)
return read_secret(client, SECRET_MOUNT, SECRET_PATH)
def get_ovh_api_client():
secret = query_credentials()
return ovh.Client(
endpoint="ovh-eu",
application_key=secret["application_key"],
application_secret=secret["application_secret"],
consumer_key=secret["consumer_key"],
)
# -------------------------------------------------------------
# Application entry point
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def run():
client = get_ovh_api_client()
print(client.get('/dedicated/server/ns3173530.ip-51-210-99.eu/virtualMac/00:50:56:09:98:fc/virtualAddress'))
if __name__ == "__main__":
run()

Event Timeline

dereckson added a subscriber: yousra.

Proof of concept to call OVH API from Python to define MAC address to router-002/003.

See T2276.