177
178
network_gateways_path = "/network-gateways"
178
179
network_gateway_path = "/network-gateways/%s"
181
DHCP_NETS = '/dhcp-networks'
182
DHCP_AGENTS = '/dhcp-agents'
183
L3_ROUTERS = '/l3-routers'
184
L3_AGENTS = '/l3-agents'
180
185
# API has no way to report plurals, so we have to hard code them
181
186
EXTED_PLURALS = {'routers': 'router',
182
187
'floatingips': 'floatingip',
241
246
return self.get(self.ext_path % ext_alias, params=_params)
244
def list_ports(self, **_params):
249
def list_ports(self, retrieve_all=True, **_params):
246
251
Fetches a list of all networks for a tenant
248
253
# Pass filters in "params" argument to do_request
249
return self.get(self.ports_path, params=_params)
254
return self.list('ports', self.ports_path, retrieve_all,
252
258
def show_port(self, port, **_params):
277
283
return self.delete(self.port_path % (port))
280
def list_networks(self, **_params):
286
def list_networks(self, retrieve_all=True, **_params):
282
288
Fetches a list of all networks for a tenant
284
290
# Pass filters in "params" argument to do_request
285
return self.get(self.networks_path, params=_params)
291
return self.list('networks', self.networks_path, retrieve_all,
288
295
def show_network(self, network, **_params):
313
320
return self.delete(self.network_path % (network))
316
def list_subnets(self, **_params):
323
def list_subnets(self, retrieve_all=True, **_params):
318
325
Fetches a list of all networks for a tenant
320
return self.get(self.subnets_path, params=_params)
327
return self.list('subnets', self.subnets_path, retrieve_all,
323
331
def show_subnet(self, subnet, **_params):
348
356
return self.delete(self.subnet_path % (subnet))
351
def list_routers(self, **_params):
359
def list_routers(self, retrieve_all=True, **_params):
353
361
Fetches a list of all routers for a tenant
355
363
# Pass filters in "params" argument to do_request
356
return self.get(self.routers_path, params=_params)
364
return self.list('routers', self.routers_path, retrieve_all,
359
368
def show_router(self, router, **_params):
416
425
body={'router': {'external_gateway_info': {}}})
419
def list_floatingips(self, **_params):
428
def list_floatingips(self, retrieve_all=True, **_params):
421
430
Fetches a list of all floatingips for a tenant
423
432
# Pass filters in "params" argument to do_request
424
return self.get(self.floatingips_path, params=_params)
433
return self.list('floatingips', self.floatingips_path, retrieve_all,
427
437
def show_floatingip(self, floatingip, **_params):
459
469
return self.post(self.security_groups_path, body=body)
462
def list_security_groups(self, **_params):
472
def list_security_groups(self, retrieve_all=True, **_params):
464
474
Fetches a list of all security groups for a tenant
466
return self.get(self.security_groups_path, params=_params)
476
return self.list('security_groups', self.security_groups_path,
477
retrieve_all, **_params)
469
480
def show_security_group(self, security_group, **_params):
496
507
(security_group_rule))
499
def list_security_group_rules(self, **_params):
510
def list_security_group_rules(self, retrieve_all=True, **_params):
501
512
Fetches a list of all security group rules for a tenant
503
return self.get(self.security_group_rules_path, params=_params)
514
return self.list('security_group_rules',
515
self.security_group_rules_path,
516
retrieve_all, **_params)
506
519
def show_security_group_rule(self, security_group_rule, **_params):
514
def list_vips(self, **_params):
527
def list_vips(self, retrieve_all=True, **_params):
516
529
Fetches a list of all load balancer vips for a tenant
518
531
# Pass filters in "params" argument to do_request
519
return self.get(self.vips_path, params=_params)
532
return self.list('vips', self.vips_path, retrieve_all,
522
536
def show_vip(self, vip, **_params):
547
561
return self.delete(self.vip_path % (vip))
550
def list_pools(self, **_params):
564
def list_pools(self, retrieve_all=True, **_params):
552
566
Fetches a list of all load balancer pools for a tenant
554
568
# Pass filters in "params" argument to do_request
555
return self.get(self.pools_path, params=_params)
569
return self.list('pools', self.pools_path, retrieve_all,
558
573
def show_pool(self, pool, **_params):
590
605
return self.get(self.pool_path_stats % (pool), params=_params)
593
def list_members(self, **_params):
608
def list_members(self, retrieve_all=True, **_params):
595
610
Fetches a list of all load balancer members for a tenant
597
612
# Pass filters in "params" argument to do_request
598
return self.get(self.members_path, params=_params)
613
return self.list('members', self.members_path, retrieve_all,
601
617
def show_member(self, member, **_params):
626
642
return self.delete(self.member_path % (member))
629
def list_health_monitors(self, **_params):
645
def list_health_monitors(self, retrieve_all=True, **_params):
631
647
Fetches a list of all load balancer health monitors for a tenant
633
649
# Pass filters in "params" argument to do_request
634
return self.get(self.health_monitors_path, params=_params)
650
return self.list('health_monitors', self.health_monitors_path,
651
retrieve_all, **_params)
637
654
def show_health_monitor(self, health_monitor, **_params):
788
805
base_uri = self.network_gateway_path % gateway_id
789
806
return self.put("%s/disconnect_network" % base_uri, body=body)
809
def list_dhcp_agent_hosting_networks(self, network, **_params):
811
Fetches a list of dhcp agents hosting a network.
813
return self.get((self.network_path + self.DHCP_AGENTS) % network,
817
def list_networks_on_dhcp_agent(self, dhcp_agent, **_params):
819
Fetches a list of dhcp agents hosting a network.
821
return self.get((self.agent_path + self.DHCP_NETS) % dhcp_agent,
825
def add_network_to_dhcp_agent(self, dhcp_agent, body=None):
827
Adds a network to dhcp agent.
829
return self.post((self.agent_path + self.DHCP_NETS) % dhcp_agent,
833
def remove_network_from_dhcp_agent(self, dhcp_agent, network_id):
835
Remove a network from dhcp agent.
837
return self.delete((self.agent_path + self.DHCP_NETS + "/%s") % (
838
dhcp_agent, network_id))
841
def list_l3_agent_hosting_routers(self, router, **_params):
843
Fetches a list of L3 agents hosting a router.
845
return self.get((self.router_path + self.L3_AGENTS) % router,
849
def list_routers_on_l3_agent(self, l3_agent, **_params):
851
Fetches a list of L3 agents hosting a router.
853
return self.get((self.agent_path + self.L3_ROUTERS) % l3_agent,
857
def add_router_to_l3_agent(self, l3_agent, body):
859
Adds a router to L3 agent.
861
return self.post((self.agent_path + self.L3_ROUTERS) % l3_agent,
865
def remove_router_from_l3_agent(self, l3_agent, router_id):
867
Remove a router from l3 agent.
869
return self.delete((self.agent_path + self.L3_ROUTERS + "/%s") % (
870
l3_agent, router_id))
791
872
def __init__(self, **kwargs):
792
873
""" Initialize a new client for the Quantum v2.0 API. """
793
874
super(Client, self).__init__()
908
989
def put(self, action, body=None, headers=None, params=None):
909
990
return self.retry_request("PUT", action, body=body,
910
991
headers=headers, params=params)
993
def list(self, collection, path, retrieve_all=True, **params):
996
for r in self._pagination(collection, path, **params):
997
res.extend(r[collection])
998
return {collection: res}
1000
return self._pagination(collection, path, **params)
1002
def _pagination(self, collection, path, **params):
1003
if params.get('page_reverse', False):
1004
linkrel = 'previous'
1009
res = self.get(path, params=params)
1013
for link in res['%s_links' % collection]:
1014
if link['rel'] == linkrel:
1015
query_str = urlparse.urlparse(link['href']).query
1016
params = urlparse.parse_qs(query_str)