Skip to content
This repository has been archived by the owner on May 7, 2024. It is now read-only.

Commit

Permalink
cli4 can now do maps and regions in Cloudflare Load Balancer
Browse files Browse the repository at this point in the history
  • Loading branch information
mahtin committed Dec 5, 2016
1 parent 957f9b0 commit 734204e
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions cli4/cli4.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,43 @@ def convert_virtual_dns_to_identifier(cf, virtual_dns_name):

exit('cli4: %s - no virtual_dns found' % (virtual_dns_name))

def convert_load_balancers_map_to_identifier(cf, map_name):
"""load balancer map names to numbers"""
try:
maps = cf.user.load_balancers.maps.get()
except CloudFlare.exceptions.CloudFlareAPIError as e:
exit('cli4: %s - %d %s' % (map_name, e, e))
except Exception as e:
exit('cli4: %s - %s' % (map_name, e))

for m in maps:
if map_name == m['description']:
return m['id']

exit('cli4: %s - no maps found' % (map_name))

def convert_load_balancers_map_regions(cf, region_name):
"""load balancer map regions"""
# this will/must go away; however it allows :WNAM etc in path.
regions = {
'WNAM', # Western North America
'ENAM', # Eastern North America
'EU', # Europe
'NSAM', # Northern South America
'SSAM', # Southern South America
'OC', # Oceania
'ME', # Middle East
'NAF', # Northern Africa
'SAF', # Southern Africa
'IN', # India
'SEAS', # Southeast Asia
'NEAS', # Northeast Asia
'CHINA' # China
}
if region_name in regions:
return region_name
exit('cli4: %s - no region found' % (region_name))

def walk(m, s):
"""recursive walk of the tree"""
for n in sorted(dir(m)):
Expand Down Expand Up @@ -280,6 +317,8 @@ def cli4(args):
identifier1 = convert_invites_to_identifier(cf, element)
elif (cmd[0] == 'user') and (cmd[1] == 'virtual_dns'):
identifier1 = convert_virtual_dns_to_identifier(cf, element)
elif (cmd[0] == 'user') and (cmd[1] == 'load_balancers') and (cmd[2] == 'maps'):
identifier1 = convert_load_balancers_map_to_identifier(cf, element)
else:
exit("/%s/%s :NOT CODED YET 1" % ('/'.join(cmd), element))
cmd.append(':' + identifier1)
Expand All @@ -289,6 +328,8 @@ def cli4(args):
identifier2 = element
elif (cmd[0] and cmd[0] == 'zones') and (cmd[2] and cmd[2] == 'dns_records'):
identifier2 = convert_dns_record_to_identifier(cf, identifier1, element)
elif (cmd[0] == 'user') and (cmd[1] == 'load_balancers') and (cmd[2] == 'maps') and (cmd[4] == 'region'):
identifier2 = convert_load_balancers_map_regions(cf, element)
else:
exit("/%s/%s :NOT CODED YET 2" % ('/'.join(cmd), element))
# identifier2 may be an array - this needs to be dealt with later
Expand Down

0 comments on commit 734204e

Please sign in to comment.