Skip to content

Instantly share code, notes, and snippets.

@benasse
Created July 18, 2022 15:26
Show Gist options
  • Select an option

  • Save benasse/06e120589ff787fc7ae5d199f0afcba4 to your computer and use it in GitHub Desktop.

Select an option

Save benasse/06e120589ff787fc7ae5d199f0afcba4 to your computer and use it in GitHub Desktop.
lanch amid action on wazo
#!/usr/bin/env python
import logging
import os
import string
import sys
from wazo_auth_client import Client as AuthClient
from xivo.chain_map import ChainMap
from xivo.config_helper import read_config_file_hierarchy, parse_config_file
from wazo_amid_client import Client as AmidClient
logger = logging.getLogger('launch_ami_action')
logging.basicConfig(level=logging.INFO)
_DEFAULT_CONFIG = {
'config_file': '/etc/wazo-upgrade/config.yml',
'auth': {
'key_file': '/var/lib/wazo-auth-keys/wazo-upgrade-key.yml'
}
}
def load_config():
file_config = read_config_file_hierarchy(_DEFAULT_CONFIG)
key_config = _load_key_file(ChainMap(file_config, _DEFAULT_CONFIG))
return ChainMap(key_config, file_config, _DEFAULT_CONFIG)
def _load_key_file(config):
key_file = parse_config_file(config['auth']['key_file'])
return {'auth': {'username': key_file['service_id'],
'password': key_file['service_key']}}
config = load_config()
auth_client = AuthClient(**config['auth'])
token_data = auth_client.token.new(expiration=300)
logger.info("Connecting to amid...")
amid_client = AmidClient(token=token_data['token'],**config['amid'])
results = amid_client.action('PJSIPShowRegistrationInboundContactStatuses')
print(results)
logger.info("Done.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment