本文整理汇总了Python中neutronclient.v2_0.client.Client.delete_port方法的典型用法代码示例。如果您正苦于以下问题:Python Client.delete_port方法的具体用法?Python Client.delete_port怎么用?Python Client.delete_port使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类neutronclient.v2_0.client.Client
的用法示例。
在下文中一共展示了Client.delete_port方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: RouterPortCleanup
# 需要导入模块: from neutronclient.v2_0.client import Client [as 别名]
# 或者: from neutronclient.v2_0.client.Client import delete_port [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)
示例2: StalePortCleanup
# 需要导入模块: from neutronclient.v2_0.client import Client [as 别名]
# 或者: from neutronclient.v2_0.client.Client import delete_port [as 别名]
class StalePortCleanup():
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')
kwargs['endpoint_type'] = os.environ.get('OS_ENDPOINT_TYPE')
self.client = NeutronClient(**kwargs)
self.subnets = []
self.stale_ports = []
self.stale_networks = {}
self.all_ports = []
def get_stale_ports(self):
self.all_ports = self.client.list_ports()['ports']
for port in self.all_ports or []:
try:
if not port['fixed_ips'] or not port['fixed_ips'][0]['subnet_id']:
self.stale_ports.append(port)
if port['network_id'] not in self.stale_networks:
self.stale_networks[port['network_id']] = {
'network_id': port['network_id'],
'tenant_id': port['tenant_id']}
except Exception as e:
print("Exception occured for port : " + str(port['id']) + "\n")
def _display_stale_port_info(self, port):
print('Port Id = ' + str(port['id']) + '\n')
print('This port belongs to tenant : ' + str(port['tenant_id']) + '\n')
print('This port belongs to network : ' + str(port['network_id'] + '\n'))
if port['fixed_ips']:
print("This port has IP address : " + str(port['fixed_ips'][0]['ip_address']) + "\n")
if port['device_id']:
print("This port has device id set to : " + str(port['device_id']) + "\n")
if port['device_owner']:
print("This port has device owner set to : " + str(port['device_owner']) + "\n")
def display_stale_resources(self):
print('Total stale ports found : ' + str(len(self.stale_ports)))
if len(self.stale_ports):
print('Below are the stale ports which will be deleted : Please review')
for port in self.stale_ports:
print('**************\n')
self._display_stale_port_info(port)
print('**************\n\n')
print('\n\n##################################\n\n')
print('Total stale networks found : ' + str(len(self.stale_networks)))
if len(self.stale_networks):
print('Below are the stale networks')
for net_info in self.stale_networks.itervalues():
print('**************\n')
print('Network Id : ' + net_info['network_id'] + '\n')
print("This network belongs to tenant : " + net_info['tenant_id'] + "\n")
print('**************\n')
def delete_stale_resources(self):
print("Deleting the stale resources")
for port in self.stale_ports:
print("Deleting port : " + str(port['id']) + "\n")
try:
self.client.delete_port(port['id'])
except Exception as e:
print("Exception occured in deleting port : " + str(port['id']) +"\n")
print("Exception e = " + str(e) + "\n")
if not self.stale_networks:
return
print("Deleting state networks now")
for net_info in self.stale_networks.itervalues():
print("Deleting Stale networks : " + net_info['network_id'] + "\n")
try:
self.client.delete_network(net_info['network_id'])
except Exception as e:
print("Exception occured in deleting network : " + str(net_info['network_id']) +"\n")
print("Exception e = " + str(e) + "\n")