本文整理汇总了Python中service.accounts.openstack.AccountDriver.delete_security_group方法的典型用法代码示例。如果您正苦于以下问题:Python AccountDriver.delete_security_group方法的具体用法?Python AccountDriver.delete_security_group怎么用?Python AccountDriver.delete_security_group使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类service.accounts.openstack.AccountDriver
的用法示例。
在下文中一共展示了AccountDriver.delete_security_group方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: clear_empty_ips
# 需要导入模块: from service.accounts.openstack import AccountDriver [as 别名]
# 或者: from service.accounts.openstack.AccountDriver import delete_security_group [as 别名]
def clear_empty_ips():
logger.debug("clear_empty_ips task started at %s." % datetime.now())
from service import instance as instance_service
from rtwo.driver import OSDriver
from api import get_esh_driver
from service.accounts.openstack import AccountDriver as OSAccountDriver
identities = Identity.objects.filter(provider__type__name__iexact="openstack", provider__active=True)
key_sorter = lambda ident: attrgetter(ident.provider.type.name, ident.created_by.username)
identities = sorted(identities, key=key_sorter)
os_acct_driver = None
total = len(identities)
for idx, core_identity in enumerate(identities):
try:
# Initialize the drivers
driver = get_esh_driver(core_identity)
if not isinstance(driver, OSDriver):
continue
if not os_acct_driver or os_acct_driver.core_provider != core_identity.provider:
os_acct_driver = OSAccountDriver(core_identity.provider)
logger.info("Initialized account driver")
# Get useful info
creds = core_identity.get_credentials()
tenant_name = creds["ex_tenant_name"]
logger.info("Checking Identity %s/%s - %s" % (idx + 1, total, tenant_name))
# Attempt to clean floating IPs
num_ips_removed = driver._clean_floating_ip()
if num_ips_removed:
logger.debug("Removed %s ips from OpenStack Tenant %s" % (num_ips_removed, tenant_name))
# Test for active/inactive instances
instances = driver.list_instances()
active = any(driver._is_active_instance(inst) for inst in instances)
inactive = all(driver._is_inactive_instance(inst) for inst in instances)
for instance in instances:
if driver._is_inactive_instance(instance) and instance.ip:
# If an inactive instance has floating/fixed IPs.. Remove them!
instance_service.remove_ips(driver, instance)
if active and not inactive:
# User has >1 active instances AND not all instances inactive
pass
elif os_acct_driver.network_manager.get_network_id(
os_acct_driver.network_manager.neutron, "%s-net" % tenant_name
):
# User has 0 active instances OR all instances are inactive
# Network exists, attempt to dismantle as much as possible
remove_network = not inactive
logger.info("Removing project network %s for %s" % (remove_network, tenant_name))
if remove_network:
# Sec. group can't be deleted if instances are suspended
# when instances are suspended we pass remove_network=False
os_acct_driver.delete_security_group(core_identity)
os_acct_driver.delete_network(core_identity, remove_network=remove_network)
else:
# logger.info("No Network found. Skipping %s" % tenant_name)
pass
except Exception as exc:
logger.exception(exc)
logger.debug("clear_empty_ips task finished at %s." % datetime.now())
示例2: remove_empty_network
# 需要导入模块: from service.accounts.openstack import AccountDriver [as 别名]
# 或者: from service.accounts.openstack.AccountDriver import delete_security_group [as 别名]
def remove_empty_network(
driverCls, provider, identity,
core_identity_id,
*args, **kwargs):
try:
#For testing ONLY.. Test cases ignore countdown..
if app.conf.CELERY_ALWAYS_EAGER:
logger.debug("Eager task waiting 1 minute")
time.sleep(60)
logger.debug("remove_empty_network task started at %s." %
datetime.now())
logger.debug("CoreIdentity(id=%s)" % core_identity_id)
core_identity = Identity.objects.get(id=core_identity_id)
driver = get_driver(driverCls, provider, identity)
instances = driver.list_instances()
active_instances = False
#TODO: Replace with any()
for instance in instances:
if driver._is_active_instance(instance):
active_instances = True
break
if not active_instances:
inactive_instances = all(driver._is_inactive_instance(
instance) for instance in instances)
#Inactive instances, True: Remove network, False
remove_network = not inactive_instances
#Check for project network
from service.accounts.openstack import AccountDriver as\
OSAccountDriver
os_acct_driver = OSAccountDriver(core_identity.provider)
logger.info("No active instances. Removing project network"
"from %s" % core_identity)
os_acct_driver.delete_network(core_identity,
remove_network=remove_network)
if remove_network:
#Sec. group can't be deleted if instances are suspended
# when instances are suspended we pass remove_network=False
os_acct_driver.delete_security_group(core_identity)
return True
logger.debug("remove_empty_network task finished at %s." %
datetime.now())
return False
except Exception as exc:
logger.exception("Failed to check if project network is empty")
remove_empty_network.retry(exc=exc)