本文整理汇总了Python中neutronclient.v2_0.client.Client.list_subnets方法的典型用法代码示例。如果您正苦于以下问题:Python Client.list_subnets方法的具体用法?Python Client.list_subnets怎么用?Python Client.list_subnets使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类neutronclient.v2_0.client.Client
的用法示例。
在下文中一共展示了Client.list_subnets方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: RouterPortCleanup
# 需要导入模块: from neutronclient.v2_0.client import Client [as 别名]
# 或者: from neutronclient.v2_0.client.Client import list_subnets [as 别名]
class RouterPortCleanup():
def __init__(self):
kwargs = {}
kwargs['username'] = os.environ.get('OS_USERNAME')
kwargs['tenant_name'] = os.environ.get('OS_TENANT_NAME')
kwargs['auth_url'] = os.environ.get('OS_AUTH_URL')
#kwargs['endpoint_url'] = os.environ.get('OS_AUTH_URL')
kwargs['auth_strategy'] = 'keystone'
kwargs['password']= os.environ.get('OS_PASSWORD')
self.client = NeutronClient(**kwargs)
self.subnets = []
self.ports = []
def _check_and_delete(self, port):
for subnet in self.subnets:
if port['fixed_ips'][0]['subnet_id'] == subnet['id']:
if port['fixed_ips'][0]['ip_address'] == subnet['gateway_ip']:
# delete this port
print "Found a stale port : "+ port['id']
self.client.delete_port(port['id'])
print "Deleted the port : " + port['id']
print "\n\n"
return
def clean_up_ports(self):
""" Delete the stale ports.
These ports have
1. Empty device_id
2. Empty device_owner
3. The IP address of the port will be the gateway ip of the subnet
"""
# get the subnets
self.subnets = self.client.list_subnets()['subnets']
print "subnets = \n"
print self.subnets
print "\n"
self.ports = self.client.list_ports()['ports']
for port in self.ports:
print "\n**************************"
print 'port =' + str(port)
print "\n"
if len(port['device_owner']) == 0 and len(port['device_id']) == 0:
self._check_and_delete(port)