Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Created February 27, 2015 23:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/797b46c9ac4c0c3a1095 to your computer and use it in GitHub Desktop.
Save anonymous/797b46c9ac4c0c3a1095 to your computer and use it in GitHub Desktop.
def _set_network(self, section_name="network"):
if "neutron" in self.available_services:
neutron = self.clients.neutron()
public_net = [net for net in neutron.list_networks()["networks"] if
net["status"] == "ACTIVE" and
net["router:external"] is True]
if public_net:
net_id = public_net[0]["id"]
self.conf.set(section_name, "public_network_id", net_id)
public_router = neutron.list_routers(
network_id=net_id)["routers"][0]
self.conf.set(section_name, "public_router_id",
public_router["id"])
subnets = neutron.list_subnets(network_id=net_id)["subnets"]
if subnets:
subnet = subnets[0]
else:
# TODO(akurilin): create public subnet
LOG.warn("No public subnet is found.")
else:
subnets = neutron.list_subnets()["subnets"]
if subnets:
subnet = subnets[0]
else:
# TODO(akurilin): create subnet
LOG.warn("No subnet is found.")
self.conf.set(section_name, "default_network", subnet["cidr"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment