Skip to content
This repository was archived by the owner on Nov 22, 2024. It is now read-only.

Commit 734204e

Browse files
committed
cli4 can now do maps and regions in Cloudflare Load Balancer
1 parent 957f9b0 commit 734204e

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

cli4/cli4.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,43 @@ def convert_virtual_dns_to_identifier(cf, virtual_dns_name):
111111

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

114+
def convert_load_balancers_map_to_identifier(cf, map_name):
115+
"""load balancer map names to numbers"""
116+
try:
117+
maps = cf.user.load_balancers.maps.get()
118+
except CloudFlare.exceptions.CloudFlareAPIError as e:
119+
exit('cli4: %s - %d %s' % (map_name, e, e))
120+
except Exception as e:
121+
exit('cli4: %s - %s' % (map_name, e))
122+
123+
for m in maps:
124+
if map_name == m['description']:
125+
return m['id']
126+
127+
exit('cli4: %s - no maps found' % (map_name))
128+
129+
def convert_load_balancers_map_regions(cf, region_name):
130+
"""load balancer map regions"""
131+
# this will/must go away; however it allows :WNAM etc in path.
132+
regions = {
133+
'WNAM', # Western North America
134+
'ENAM', # Eastern North America
135+
'EU', # Europe
136+
'NSAM', # Northern South America
137+
'SSAM', # Southern South America
138+
'OC', # Oceania
139+
'ME', # Middle East
140+
'NAF', # Northern Africa
141+
'SAF', # Southern Africa
142+
'IN', # India
143+
'SEAS', # Southeast Asia
144+
'NEAS', # Northeast Asia
145+
'CHINA' # China
146+
}
147+
if region_name in regions:
148+
return region_name
149+
exit('cli4: %s - no region found' % (region_name))
150+
114151
def walk(m, s):
115152
"""recursive walk of the tree"""
116153
for n in sorted(dir(m)):
@@ -280,6 +317,8 @@ def cli4(args):
280317
identifier1 = convert_invites_to_identifier(cf, element)
281318
elif (cmd[0] == 'user') and (cmd[1] == 'virtual_dns'):
282319
identifier1 = convert_virtual_dns_to_identifier(cf, element)
320+
elif (cmd[0] == 'user') and (cmd[1] == 'load_balancers') and (cmd[2] == 'maps'):
321+
identifier1 = convert_load_balancers_map_to_identifier(cf, element)
283322
else:
284323
exit("/%s/%s :NOT CODED YET 1" % ('/'.join(cmd), element))
285324
cmd.append(':' + identifier1)
@@ -289,6 +328,8 @@ def cli4(args):
289328
identifier2 = element
290329
elif (cmd[0] and cmd[0] == 'zones') and (cmd[2] and cmd[2] == 'dns_records'):
291330
identifier2 = convert_dns_record_to_identifier(cf, identifier1, element)
331+
elif (cmd[0] == 'user') and (cmd[1] == 'load_balancers') and (cmd[2] == 'maps') and (cmd[4] == 'region'):
332+
identifier2 = convert_load_balancers_map_regions(cf, element)
292333
else:
293334
exit("/%s/%s :NOT CODED YET 2" % ('/'.join(cmd), element))
294335
# identifier2 may be an array - this needs to be dealt with later

0 commit comments

Comments
 (0)