本文整理汇总了Python中core.models.provider.Provider.get_active方法的典型用法代码示例。如果您正苦于以下问题:Python Provider.get_active方法的具体用法?Python Provider.get_active怎么用?Python Provider.get_active使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类core.models.provider.Provider
的用法示例。
在下文中一共展示了Provider.get_active方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: prune_machines
# 需要导入模块: from core.models.provider import Provider [as 别名]
# 或者: from core.models.provider.Provider import get_active [as 别名]
def prune_machines():
"""
Query the cloud and remove any machines
that exist in the DB but can no longer be found.
"""
for p in Provider.get_active():
prune_machines_for.apply_async(args=[p.id])
示例2: search
# 需要导入模块: from core.models.provider import Provider [as 别名]
# 或者: from core.models.provider.Provider import get_active [as 别名]
def search(cls, query, identity=None):
if identity:
base_apps = Application.objects.filter(
# Privately owned OR public machines
Q(private=True,
providermachine__instance_source__created_by_identity=identity)
| Q(private=False,
providermachine__instance_source__provider=identity.provider))
else:
active_providers = Provider.get_active()
base_apps = Application.objects.filter(
# Public machines
private=False,
#Providermachine's provider is active
providermachine__instance_source__provider__in=active_providers)
# AND query matches on:
query_match = base_apps.filter(
# app tag name
Q(tags__name__icontains=query)
# OR app tag desc
| Q(tags__description__icontains=query)
# OR app name
| Q(name__icontains=query)
# OR app desc
| Q(description__icontains=query),
only_current_source())
return query_match.distinct()
示例3: get
# 需要导入模块: from core.models.provider import Provider [as 别名]
# 或者: from core.models.provider.Provider import get_active [as 别名]
def get(self, request, provider_uuid):
try:
provider = Provider.get_active(provider_uuid)
except Provider.DoesNotExist:
return failure_response(
status.HTTP_404_NOT_FOUND,
"The provider does not exist.")
admin_driver = get_admin_driver(provider)
if not admin_driver:
return failure_response(
status.HTTP_404_NOT_FOUND,
"The driver cannot be retrieved for this provider.")
if not hasattr(admin_driver._connection, "ex_hypervisor_statistics"):
return failure_response(
status.HTTP_404_NOT_FOUND,
"Occupancy statistics cannot be retrieved for this provider.")
try:
stats = admin_driver._connection.ex_hypervisor_statistics()
return Response(stats)
except (socket_error, ConnectionFailure):
return connection_failure(provider_uuid)
except Exception as exc:
return failure_response(
status.HTTP_503_SERVICE_UNAVAILABLE,
"Error occurred while retrieving statistics: %s" %
exc)
示例4: get
# 需要导入模块: from core.models.provider import Provider [as 别名]
# 或者: from core.models.provider.Provider import get_active [as 别名]
def get(self, request, project_uuid):
user = request.user
group = get_user_group(user.username)
project = get_group_project(group, project_uuid)
if not project:
return Response(
"Project with ID=%s does not "
"exist" % project_uuid,
status=status.HTTP_400_BAD_REQUEST
)
instances = project.instances.filter(
only_current(), provider_machine__provider__active=True
)
active_provider_uuids = [ap.uuid for ap in Provider.get_active()]
instances = instances.filter(
pk__in=[
i.id for i in instances
if i.instance.provider_uuid() in active_provider_uuids
]
)
serialized_data = InstanceSerializer(
instances, many=True, context={
"request": request
}
).data
response = Response(serialized_data)
return response
示例5: get_os_account_driver
# 需要导入模块: from core.models.provider import Provider [as 别名]
# 或者: from core.models.provider.Provider import get_active [as 别名]
def get_os_account_driver(provider):
from service.accounts.openstack import AccountDriver as OSAccountDriver
if provider not in Provider.get_active(type_name='openstack'):
raise Exception("An active openstack provider is required to"
" update image owner")
accounts = OSAccountDriver(provider)
return accounts
示例6: _fix_existing_machines
# 需要导入模块: from core.models.provider import Provider [as 别名]
# 或者: from core.models.provider.Provider import get_active [as 别名]
def _fix_existing_machines():
#NOTE: Run once on prod, then remove this function..
from core.models import Provider, ProviderMachine, MachineRequest
for pm in ProviderMachine.objects.filter(provider__in=Provider.get_active(type_name='openstack')):
owner = pm.application.created_by
if 'admin' not in owner.username:
try:
update_owner(pm, owner.username)
print "Updated owner for %s" % owner
except Exception, exc:
print "Cannot update owner %s" % owner
print "Exception = %s" % exc
示例7: _os_update_owner
# 需要导入模块: from core.models.provider import Provider [as 别名]
# 或者: from core.models.provider.Provider import get_active [as 别名]
def _os_update_owner(provider_machine, tenant_name):
from core.models import Provider
from service.driver import get_admin_driver
provider = provider_machine.provider
if provider not in Provider.get_active(type_name='openstack'):
raise Exception("An active openstack provider is required to"
" update image owner")
esh_driver = get_admin_driver(provider)
if not esh_driver:
raise Exception("The account driver of Provider %s is required to"
" update image metadata" % provider)
esh_machine = esh_driver.get_machine(provider_machine.identifier)
if not esh_machine:
raise Exception("Machine with ID %s not found"
% provider_machine.identifier)
tenant_id = _tenant_name_to_id(provider_machine.provider, tenant_name)
update_machine_metadata(esh_driver, esh_machine,
{"owner": tenant_id,
"application_owner": tenant_name})
示例8: get
# 需要导入模块: from core.models.provider import Provider [as 别名]
# 或者: from core.models.provider.Provider import get_active [as 别名]
def get(self, request, provider_uuid):
try:
provider = Provider.get_active(provider_uuid)
except Provider.DoesNotExist:
return failure_response(
status.HTTP_404_NOT_FOUND,
"The provider does not exist.")
admin_driver = get_admin_driver(provider)
if not admin_driver:
return failure_response(
status.HTTP_404_NOT_FOUND,
"The driver cannot be retrieved for this provider.")
if hasattr(admin_driver._connection, "ex_hypervisor_statistics"):
return Response(
admin_driver._connection.ex_hypervisor_statistics())
else:
return failure_response(
status.HTTP_404_NOT_FOUND,
"Hypervisor statistics are unavailable for this provider.")
示例9: visible_applications
# 需要导入模块: from core.models.provider import Provider [as 别名]
# 或者: from core.models.provider.Provider import get_active [as 别名]
def visible_applications(user):
apps = []
if not user:
return apps
from core.models import Provider, ProviderMachineMembership
active_providers = Provider.get_active()
now_time = timezone.now()
#Look only for 'Active' private applications
for app in Application.objects.filter(only_current(), private=True):
#Retrieve the machines associated with this app
machine_set = app.providermachine_set.filter(only_current_source())
#Skip app if all their machines are on inactive providers.
if all(not pm.instance_source.provider.is_active() for pm in machine_set):
continue
#Add the application if 'user' is a member of the application or PM
if app.members.filter(user=user):
_add_app(apps, app)
for pm in machine_set:
if pm.members.filter(user=user):
_add_app(apps, app)
break
return apps
示例10: monitor_sizes
# 需要导入模块: from core.models.provider import Provider [as 别名]
# 或者: from core.models.provider.Provider import get_active [as 别名]
def monitor_sizes():
"""
Update sizes for each active provider.
"""
for p in Provider.get_active():
monitor_sizes_for.apply_async(args=[p.id])
示例11: monitor_resources
# 需要导入模块: from core.models.provider import Provider [as 别名]
# 或者: from core.models.provider.Provider import get_active [as 别名]
def monitor_resources():
"""
Update instances for each active provider.
"""
for p in Provider.get_active():
monitor_resources_for.apply_async(args=[p.id])
示例12: monitor_machines
# 需要导入模块: from core.models.provider import Provider [as 别名]
# 或者: from core.models.provider.Provider import get_active [as 别名]
def monitor_machines():
"""
Update machines by querying the Cloud for each active provider.
"""
for p in Provider.get_active():
monitor_machines_for.apply_async(args=[p.id])
示例13: monitor_instances
# 需要导入模块: from core.models.provider import Provider [as 别名]
# 或者: from core.models.provider.Provider import get_active [as 别名]
def monitor_instances():
"""
Update instances for each active provider.
"""
for p in Provider.get_active():
monitor_instances_for(p)
示例14: monitor_instance_allocations
# 需要导入模块: from core.models.provider import Provider [as 别名]
# 或者: from core.models.provider.Provider import get_active [as 别名]
def monitor_instance_allocations():
"""
Update instances for each active provider.
"""
for p in Provider.get_active():
monitor_instances_for.apply_async(args=[p.id], check_allocations=True)