-
-
Save drucko/4116948 to your computer and use it in GitHub Desktop.
A fabric script file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from fabric.api import * | |
import agi_config | |
import fab_lib | |
# these lists are populated with 'username@hostname' strings by prep_hosts() | |
ast_hostnames_as_root = [] | |
ast_hostnames_as_tyger = [] | |
agi_hostnames_as_root = [] | |
agi_hostnames_as_tyger = [] | |
# these lists are populated with host data hashes. | |
agi_hosts = [] | |
ast_hosts = [] | |
# populates above arrays. Note becuase it has a safety valve, | |
# you can call this method as many times as you want. | |
prepped = False | |
def prep_hosts(): | |
global prepped, agi_hosts, ast_hosts, ast_hostnames_as_root, ast_hostnames_as_tyger, agi_hostnames_as_root, agi_hostnames_as_tyger | |
if prepped: | |
return | |
agi_config.config_context('dev_server') | |
agi_hosts = fab_lib.get_service_data('agihost') | |
for h in agi_hosts: | |
agi_hostnames_as_root.append('root@' + h['hostname']) | |
agi_hostnames_as_tyger.append('tyger@' + h['hostname']) | |
ast_hosts = fab_lib.get_service_data('asthost') | |
for h in ast_hosts: | |
ast_hostnames_as_root.append('root@' + h['hostname']) | |
ast_hostnames_as_tyger.append('tyger@' + h['hostname']) | |
prepped = True | |
# runs the same shutdown routine on all agi hosts-should be executed on each asterisk server | |
# expects an agi_host array from the web service | |
def switch_agi_server_down(agi_host): | |
global agi_hosts | |
prep_hosts() | |
for ud_agi_host in agi_hosts: | |
env.hosts = ['tyger@' + ud_agi_host['hostname']] | |
if agi_host['id'] == ud_agi_host['id']: | |
command = fab_lib.switch_agi_server(ud_agi_host, 'down') | |
else: | |
command = fab_lib.switch_agi_server(ud_agi_host, 'up') | |
print 'switch agi server: ', command | |
run(command) | |
def point_fab_to_asterisk_servers(user): | |
global ast_hostnames_as_tyger, ast_hostnames_as_root | |
print 'point_fab_to_asterisk_servers: start' | |
prep_hosts() | |
if user == 'tyger': | |
env.hosts = ast_hostnames_as_tyger | |
print 'setting asterisk hosts to ', ast_hostnames_as_tyger | |
elif user == 'root': | |
env.hosts = ast_hostnames_as_root | |
print 'setting asterisk hosts to ', ast_hostnames_as_root | |
else: | |
raise Exception('unknown user for asterisk point') | |
print 'point_fab_to_asterisk_servers: hosts = ', env.hosts | |
def agi_status(): | |
global ast_hosts, ast_hostnames_as_root,env | |
prep_hosts() | |
point_fab_to_asterisk_servers('root') | |
env.hosts = ast_hostnames_as_root | |
command = fab_lib.get_agi_status() | |
print'running ', command, 'on hosts ', env.hosts | |
print run(command, True) | |
# turns down a specific asterisk host from the perspective of each agi server | |
def shut_down_agi_server(agi_host=False): | |
prep_hosts() | |
# for test purposes, we are shutting down the first agi server by default | |
if False == agi_host: | |
agi_host = agi_hosts[0] | |
point_fab_to_asterisk_servers('root'); | |
switch_agi_server_down(agi_host) | |
# @TODO: validate against expected results | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment