本文整理汇总了Python中service.driver.get_admin_driver函数的典型用法代码示例。如果您正苦于以下问题:Python get_admin_driver函数的具体用法?Python get_admin_driver怎么用?Python get_admin_driver使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_admin_driver函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: suspend_all_instances
def suspend_all_instances():
admin_driver = get_admin_driver(Provider.objects.get(id=4))
all_insts = admin_driver.meta(admin_driver=admin_driver).all_instances()
users = []
bad_instances = []
for i in all_insts:
if "creator" in i.extra["metadata"]:
users.append(i.extra["metadata"]["creator"])
else:
bad_instances.append(i)
if bad_instances:
print "WARN: These instances are MISSING because they have incomplete metadata:\n%s" % (bad_instances,)
all_users = sorted(list(OrderedDict.fromkeys(users)))
for count, user in enumerate(all_users):
ident = Identity.objects.filter(created_by__username=user, provider__id=4)
if len(ident) > 1:
print "WARN: User %s has >1 identity!" % user
ident = ident[0]
driver = get_esh_driver(ident)
instances = driver.list_instances()
print "Found %s instances for %s" % (len(instances), user)
for inst in instances:
if inst._node.extra["status"] == "active":
print "Attempt to suspend Instance %s in state %s" % (inst.id, inst._node.extra["status"])
try:
suspend_instance(driver, inst, ident.provider.id, ident.id, ident.created_by)
print "Suspended Instance %s.. Sleep 2min" % (inst.id,)
time.sleep(2 * 60)
except Exception, err:
print "WARN: Could not suspend instance %s. Error: %s" % (inst.id, err)
示例2: monitor_sizes_for
def monitor_sizes_for(provider_id, print_logs=False):
"""
Run the set of tasks related to monitoring sizes for a provider.
Optionally, provide a list of usernames to monitor
While debugging, print_logs=True can be very helpful.
start_date and end_date allow you to search a 'non-standard' window of time.
"""
from service.driver import get_admin_driver
if print_logs:
import logging
import sys
consolehandler = logging.StreamHandler(sys.stdout)
consolehandler.setLevel(logging.DEBUG)
celery_logger.addHandler(consolehandler)
provider = Provider.objects.get(id=provider_id)
admin_driver = get_admin_driver(provider)
# Non-End dated sizes on this provider
db_sizes = Size.objects.filter(only_current(), provider=provider)
all_sizes = admin_driver.list_sizes()
seen_sizes = []
for cloud_size in all_sizes:
core_size = convert_esh_size(cloud_size, provider.uuid)
seen_sizes.append(core_size)
now_time = timezone.now()
needs_end_date = [size for size in db_sizes if size not in seen_sizes]
for size in needs_end_date:
celery_logger.debug("End dating inactive size: %s" % size)
size.end_date = now_time
size.save()
if print_logs:
celery_logger.removeHandler(consolehandler)
示例3: main
def main():
for prov in Provider.objects.filter(type__name__icontains='openstack'):
if not prov.is_active():
continue
print "Importing machine membership for %s" % prov
accounts = OSAccounts(prov)
if not accounts:
print "Aborting import: Could not retrieve OSAccounts driver "\
"for Provider %s" % prov
continue
admin_driver = get_admin_driver(prov)
if not admin_driver:
print "Aborting import: Could not retrieve admin_driver "\
"for Provider %s" % prov
continue
private_images = admin_driver.filter_machines(
accounts.list_all_images(is_public=False),
black_list=["eki-", "eri-", "ChromoSnapShot"])
public_images = admin_driver.filter_machines(
accounts.list_all_images(is_public=True),
black_list=["eki-", "eri-", "ChromoSnapShot"])
fix_public_images(public_images, prov, accounts)
fix_private_images(private_images, prov, accounts)
fix_private_images_without_repr(private_images, prov, accounts)
示例4: 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)
示例5: get
def get(self, request, provider_uuid, identity_uuid):
"""
Using provider and identity, getlist of machines
TODO: Cache this request
"""
# TODO: Decide how we should pass this in (I.E. GET query string?)
active = False
user = request.user
provider = Provider.objects.filter(uuid=provider_uuid)
if not provider:
return invalid_creds(provider_uuid, identity_uuid)
esh_driver = get_admin_driver(provider[0])
esh_hypervisor_list = []
if not hasattr(esh_driver._connection, 'ex_list_hypervisor_nodes'):
return failure_response(
status.HTTP_404_NOT_FOUND,
"The Hypervisor List cannot be retrieved for this provider.")
try:
esh_hypervisor_list =\
esh_driver._connection.ex_list_hypervisor_nodes()
region_name = esh_driver._connection._ex_force_service_region
for obj in esh_hypervisor_list:
obj['service_region'] = region_name
response = Response(esh_hypervisor_list)
return response
except (socket_error, ConnectionFailure):
return connection_failure(provider_uuid, identity_uuid)
except Exception as exc:
return failure_response(
status.HTTP_404_NOT_FOUND,
"Error encountered retrieving hypervisor list:%s" % exc)
示例6: enable_image_validation
def enable_image_validation(machine_request, init_task, final_task, original_status="", error_handler_task=None):
if not error_handler_task:
error_handler_task = machine_request_error.s(machine_request.id)
# Task 3 = Validate the new image by launching an instance
admin_ident = machine_request.new_admin_identity()
admin_driver = get_admin_driver(machine_request.new_machine_provider)
if 'validating' == original_status:
image_id = machine_request.new_machine.identifier
celery_logger.info("Start with validating:%s" % image_id)
# If validating, seed the image_id and start here..
validate_task = validate_new_image.s(image_id, machine_request.id)
init_task = validate_task
else:
validate_task = validate_new_image.s(machine_request.id)
init_task.link(validate_task)
#Validate task returns an instance_id
# Task 4 = Wait for new instance to be 'active'
wait_for_task = wait_for_instance.s(
# NOTE: 1st arg, instance_id, passed from last task.
admin_driver.__class__,
admin_driver.provider,
admin_driver.identity,
"active",
test_tmp_status=True,
return_id=True)
validate_task.link(wait_for_task)
validate_task.link_error(error_handler_task)
# Task 5 = Terminate the new instance on completion
destroy_task = destroy_instance.s(
admin_ident.created_by, admin_ident.uuid)
wait_for_task.link(destroy_task)
wait_for_task.link_error(error_handler_task)
destroy_task.link_error(error_handler_task)
destroy_task.link(final_task)
return init_task
示例7: suspend_all_instances
def suspend_all_instances(provider, action, sleep_time=None, dry_run=False):
admin_driver = get_admin_driver(provider)
all_insts = admin_driver.meta(admin_driver=admin_driver).all_instances()
users = []
bad_instances = []
for i in all_insts:
if 'creator' in i.extra['metadata']:
users.append(i.extra['metadata']['creator'])
else:
bad_instances.append(i)
if bad_instances:
print "WARN: These instances are MISSING because they have incomplete metadata:\n%s" % (bad_instances,)
all_users = sorted(list(OrderedDict.fromkeys(users)))
for count, user in enumerate(all_users):
ident = Identity.objects.filter(created_by__username=user, provider__id=4)
if len(ident) > 1:
print "WARN: User %s has >1 identity!" % user
ident = ident[0]
driver = get_esh_driver(ident)
instances = driver.list_instances()
print "Found %s instances for %s" % (len(instances), user)
for inst in instances:
if not sleep_time:
sleep_for = random.uniform(SLEEP_MIN,SLEEP_MAX)
else:
sleep_for = sleep_time
_execute_action(ident, inst, action, sleep_for, dry_run)
示例8: get_app_driver
def get_app_driver(provider_machine):
from service.driver import get_admin_driver
provider = provider_machine.provider
esh_driver = get_admin_driver(provider)
if not esh_driver:
raise Exception("The driver of the account provider is required to"
" update image metadata")
return esh_driver
示例9: monitor_sizes_for
def monitor_sizes_for(provider_id, print_logs=False):
"""
Run the set of tasks related to monitoring sizes for a provider.
Optionally, provide a list of usernames to monitor
While debugging, print_logs=True can be very helpful.
start_date and end_date allow you to search a 'non-standard' window of time.
"""
from service.driver import get_admin_driver
if print_logs:
console_handler = _init_stdout_logging()
provider = Provider.objects.get(id=provider_id)
admin_driver = get_admin_driver(provider)
# Non-End dated sizes on this provider
db_sizes = Size.objects.filter(only_current(), provider=provider)
all_sizes = admin_driver.list_sizes()
seen_sizes = []
for cloud_size in all_sizes:
core_size = convert_esh_size(cloud_size, provider.uuid)
seen_sizes.append(core_size)
now_time = timezone.now()
needs_end_date = [size for size in db_sizes if size not in seen_sizes]
for size in needs_end_date:
celery_logger.debug("End dating inactive size: %s" % size)
size.end_date = now_time
size.save()
# Find home for 'Unknown Size'
unknown_sizes = Size.objects.filter(
provider=provider, name__contains='Unknown Size'
)
for size in unknown_sizes:
# Lookup sizes may not show up in 'list_sizes'
if size.alias == 'N/A':
continue # This is a sentinal value added for a separate purpose.
try:
libcloud_size = admin_driver.get_size(
size.alias, forced_lookup=True
)
except BaseHTTPError as error:
if error.code == 404:
# The size may have been truly deleted
continue
if not libcloud_size:
continue
cloud_size = OSSize(libcloud_size)
core_size = convert_esh_size(cloud_size, provider.uuid)
if print_logs:
_exit_stdout_logging(console_handler)
for size in seen_sizes:
size.esh = None
return seen_sizes
示例10: invalidate_machine_cache
def invalidate_machine_cache(machine_request):
"""
The new image won't populate in the machine list unless
the list is cleared.
"""
provider = machine_request.instance.\
provider_machine.provider
driver = get_admin_driver(provider)
if not driver:
return
driver.provider.machineCls.invalidate_provider_cache(driver.provider)
示例11: get_instance_owner_map
def get_instance_owner_map(provider):
admin_driver = get_admin_driver(provider)
meta = admin_driver.meta(admin_driver=admin_driver)
logger.info("Retrieving all tenants..")
all_tenants = admin_driver._connection._keystone_list_tenants()
logger.info("Retrieved %s tenants. Retrieving all instances.."
% len(all_tenants))
all_instances = meta.all_instances()
logger.info("Retrieved %s instances." % len(all_instances))
#Convert tenant-id to tenant-name all at once
all_instances = _convert_tenant_id_to_names(all_instances, all_tenants)
logger.info("Owner information added.")
#Make a mapping of owner-to-instance
instance_map = _make_instance_owner_map(all_instances)
logger.info("Instance owner map created")
return instance_map
示例12: admin_capacity_check
def admin_capacity_check(provider_id, instance_id):
from service.driver import get_admin_driver
from core.models import Provider
p = Provider.objects.get(id=provider_id)
admin_driver = get_admin_driver(p)
instance = admin_driver.get_instance(instance_id)
if not instance:
logger.warn("ERROR - Could not find instance id=%s" % (instance_id,))
return
hypervisor_hostname = instance.extra["object"].get("OS-EXT-SRV-ATTR:hypervisor_hostname")
if not hypervisor_hostname:
logger.warn("ERROR - Server Attribute hypervisor_hostname missing!" "Assumed to be under capacity")
return
hypervisor_stats = admin_driver._connection.ex_detail_hypervisor_node(hypervisor_hostname)
return test_capacity(hypervisor_hostname, instance, hypervisor_stats)
示例13: get_all_instances
def get_all_instances():
from core.models import Identity, Provider
from api import get_esh_driver
from service.driver import get_admin_driver
all_instances = []
for provider in Provider.objects.all():
try:
admin_driver = get_admin_driver(provider)
if not admin_driver:
raise Exception("No account admins for provider %s"
% provider)
meta_driver = admin_driver.meta(admin_driver=admin_driver)
all_instances.extend(meta_driver.all_instances())
except:
logger.exception("Problem accessing all "
"instances for provider: %s" % provider)
return all_instances
示例14: get
def get(self, request, provider_id):
try:
provider = Provider.objects.get(id=provider_id)
except Provider.DoesNotExist:
errorObj = failureJSON([{
'code': 404,
'message':
'The provider does not exist.'}])
return Response(errorObj, status=status.HTTP_404_NOT_FOUND)
admin_driver = get_admin_driver(provider)
if hasattr(admin_driver._connection, "ex_hypervisor_statistics"):
return Response(admin_driver._connection.ex_hypervisor_statistics())
else:
errorObj = failureJSON([{
'code': 404,
'message':
'The provider does not exist.'}])
return Response(errorObj, status=status.HTTP_404_NOT_FOUND)
示例15: upload_privacy_data
def upload_privacy_data(machine_request, new_machine):
from service.driver import get_admin_driver, get_account_driver
prov = new_machine.provider
accounts = get_account_driver(prov)
if not accounts:
print "Aborting import: Could not retrieve Account Driver "\
"for Provider %s" % prov
return
admin_driver = get_admin_driver(prov)
if not admin_driver:
print "Aborting import: Could not retrieve admin_driver "\
"for Provider %s" % prov
return
img = accounts.get_image(new_machine.identifier)
tenant_list = machine_request.get_access_list()
#All in the list will be added as 'sharing' the OStack img
#All tenants already sharing the OStack img will be added to this list
return sync_membership(accounts, img, new_machine, tenant_list)