本文整理汇总了Python中core.models.provider.Provider类的典型用法代码示例。如果您正苦于以下问题:Python Provider类的具体用法?Python Provider怎么用?Python Provider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Provider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self):
self.user = UserFactory.create()
provider_type = ProviderType(name='Test_%s' % self.user.username)
provider_type.save()
platform_type = PlatformType(
name='test-platform-%s' % self.user.username
)
platform_type.save()
provider = Provider(
location='BIO5', type=provider_type, virtualization=platform_type
)
provider.save()
active_status = InstanceStatus.objects.filter(name='active').last()
if not active_status:
active_status = InstanceStatus(name='active')
active_status.save()
suspended_status = InstanceStatus.objects.filter(name='suspended'
).last()
if not suspended_status:
suspended_status = InstanceStatus(name='suspended')
suspended_status.save()
self.provider = provider
self.active_status = active_status
self.suspended_status = suspended_status
示例2: get_os_account_driver
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
示例3: search
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()
示例4: prune_machines
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])
示例5: get
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
示例6: get
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)
示例7: _fix_existing_machines
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
示例8: _os_update_owner
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})
示例9: get
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.")
示例10: visible_applications
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
示例11: current_providers
def current_providers(self):
return Provider.shared_with_group(self).filter(only_current(), active=True)
示例12: monitor_instance_allocations
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)
示例13: monitor_sizes
def monitor_sizes():
"""
Update sizes for each active provider.
"""
for p in Provider.get_active():
monitor_sizes_for.apply_async(args=[p.id])
示例14: monitor_resources
def monitor_resources():
"""
Update instances for each active provider.
"""
for p in Provider.get_active():
monitor_resources_for.apply_async(args=[p.id])
示例15: monitor_machines
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])