本文整理汇总了Python中zstackwoodpecker.operations.account_operations.login_as_admin函数的典型用法代码示例。如果您正苦于以下问题:Python login_as_admin函数的具体用法?Python login_as_admin怎么用?Python login_as_admin使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了login_as_admin函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test
def test():
global vm
vm = test_stub.create_vr_vm('migrate_vm', 'imageName_s', 'l3VlanNetwork2')
vm.check()
session_uuid = acc_ops.login_as_admin()
console = test_lib.lib_get_vm_console_address(vm.get_vm().uuid, session_uuid)
if test_lib.lib_network_check(console.hostIp, console.port):
test_util.test_logger('[vm:] %s console on %s:%s is connectable' % (vm.get_vm().uuid, console.hostIp, console.port))
else:
test_util.test_fail('[vm:] %s console on %s:%s is not connectable' % (vm.get_vm().uuid, console.hostIp, console.port))
acc_ops.logout(session_uuid)
test_stub.migrate_vm_to_random_host(vm)
vm.check()
session_uuid = acc_ops.login_as_admin()
console = test_lib.lib_get_vm_console_address(vm.get_vm().uuid, session_uuid)
if test_lib.lib_network_check(console.hostIp, console.port):
test_util.test_logger('[vm:] %s console on %s:%s is connectable' % (vm.get_vm().uuid, console.hostIp, console.port))
else:
test_util.test_fail('[vm:] %s console on %s:%s is not connectable' % (vm.get_vm().uuid, console.hostIp, console.port))
acc_ops.logout(session_uuid)
vm.destroy()
test_util.test_pass('Migrate VM Console Access Test Success')
示例2: test
def test():
#Enable twofa and check login
password = 'b109f3bbbc244eb82441917ed06d618b9008dd09b3befd1b5e07394c706a8bb980b1d7785e5976ec049b46df5f1326af5a2ea6d103fd07c95385ffab0cacbc86'
session_uuid = acc_ops.login_as_admin()
twofa_enabled = conf_ops.get_global_config_value('twofa', 'twofa.enable')
if twofa_enabled == 'false':
conf_ops.change_global_config('twofa', 'twofa.enable', 'true')
twofa = acc_ops.get_twofa_auth_secret('admin', password, session_uuid = session_uuid)
secret = twofa.secret
twofa_status = twofa.status
if twofa_status != 'NewCreated':
test_util.test_fail("The twofa auth secret statue should be 'NewCreated' but it's %s" %twofa_status)
security_code = test_stub.get_security_code(secret)
session1_uuid = acc_ops.login_by_account('admin', password, system_tags=['twofatoken::%s' %security_code])
if session1_uuid != None:
test_util.test_logger("Enable twofa and login with security code passed")
twofa_status = acc_ops.get_twofa_auth_secret('admin', password, session_uuid = session_uuid).status
if twofa_status != 'Logined':
test_util.test_fail("The twofa auth secret statue should be 'Logined' but it's %s" %twofa_status)
#Disable twofa and check login again
conf_ops.change_global_config('twofa', 'twofa.enable', 'false', session_uuid = session_uuid)
session2_uuid = acc_ops.login_as_admin()
if session2_uuid != None:
test_util.test_pass("Disable twofa and login without security code passed")
test_util.test_fail("Fail to login without security code after twofa disabled")
示例3: test
def test():
global session_to
global session_mc
global session_uuid
session_to = con_ops.change_global_config("identity", "session.timeout", "720000", session_uuid)
session_mc = con_ops.change_global_config("identity", "session.maxConcurrent", "10000", session_uuid)
session_uuid = acc_ops.login_as_admin()
num = res_ops.query_resource_count(res_ops.SECURITY_GROUP, [], session_uuid)
if num <= thread_threshold:
sgs = res_ops.query_resource(res_ops.SECURITY_GROUP, [], session_uuid)
delete_sgs(sgs)
else:
start = 0
limit = thread_threshold - 1
curr_num = start
sgs = []
while curr_num < num:
sgs_tmp = res_ops.query_resource_fields(res_ops.SECURITY_GROUP, [], session_uuid, ["uuid"], start, limit)
sgs.extend(sgs_tmp)
curr_num += limit
start += limit
delete_sgs(sgs)
# con_ops.change_global_config('identity', 'session.timeout', session_to)
# con_ops.change_global_config('identity', 'session.maxConcurrent', session_mc)
con_ops.change_global_config("identity", "session.timeout", session_to, session_uuid)
con_ops.change_global_config("identity", "session.maxConcurrent", session_mc, session_uuid)
left_num = res_ops.query_resource_count(res_ops.SECURITY_GROUP, [], session_uuid)
acc_ops.logout(session_uuid)
if left_num == 0:
test_util.test_pass("Delete SG Success. Delete %d SGs." % num)
else:
test_util.test_fail("Delete SG Fail. %d SGs are not deleted." % left_num)
示例4: delete_all_volumes
def delete_all_volumes(thread_threshold = 1000):
session_uuid = acc_ops.login_as_admin()
session_to = con_ops.change_global_config('identity', 'session.timeout', '720000')
session_mc = con_ops.change_global_config('identity', 'session.maxConcurrent', '10000')
delete_policy = test_lib.lib_set_delete_policy('volume', 'Direct')
expunge_time = test_lib.lib_set_expunge_time('volume', 1)
cond = res_ops.gen_query_conditions('status', '!=', 'Deleted')
num = res_ops.query_resource_count(res_ops.VOLUME, cond)
if num <= thread_threshold:
volumes = res_ops.query_resource(res_ops.VOLUME, cond)
do_delete_volumes(volumes, thread_threshold)
else:
start = 0
limit = thread_threshold - 1
curr_num = start
volumes = []
while curr_num < num:
volumes_temp = res_ops.query_resource_fields(res_ops.VOLUME, \
cond, None, ['uuid'], start, limit)
volumes.extend(volumes_temp)
curr_num += limit
start += limit
do_delete_volumes(volumes, thread_threshold)
test_lib.lib_set_delete_policy('volume', delete_policy)
test_lib.lib_set_expunge_time('volume', expunge_time)
test_util.test_logger('Volumes destroy Success. Destroy %d Volumes.' % num)
示例5: umount_all_primary_storages_violently
def umount_all_primary_storages_violently():
session_uuid = acc_ops.login_as_admin()
zones = res_ops.query_resource(res_ops.ZONE)
for zone in zones:
conditions = res_ops.gen_query_conditions('zoneUuid', '=', zone.uuid)
conditions = res_ops.gen_query_conditions('state', '=', 'Enabled', conditions)
pss = res_ops.query_resource(res_ops.PRIMARY_STORAGE, conditions, session_uuid)
conditions = res_ops.gen_query_conditions('zoneUuid', '=', zone.uuid)
conditions = res_ops.gen_query_conditions('state', '=', host_header.ENABLED, conditions)
conditions = res_ops.gen_query_conditions('status', '=', host_header.CONNECTED, conditions)
conditions = res_ops.gen_query_conditions('hypervisorType', '=', inventory.KVM_HYPERVISOR_TYPE, conditions)
all_hosts = res_ops.query_resource(res_ops.HOST, conditions, session_uuid)
for host in all_hosts:
for ps in pss:
ps_url = ps.mountPath
thread = threading.Thread(\
target = umount_primary_storage_violently, \
args = (host.managementIp, ps_url))
thread.start()
while threading.active_count() > 1:
time.sleep(0.1)
acc_ops.logout(session_uuid)
delete_ps_ceph_pools()
示例6: delete_all_volumes
def delete_all_volumes(thread_threshold=1000):
session_uuid = acc_ops.login_as_admin()
session_to = con_ops.change_global_config("identity", "session.timeout", "720000")
session_mc = con_ops.change_global_config("identity", "session.maxConcurrent", "10000")
delete_policy = test_lib.lib_set_delete_policy("volume", "Direct")
expunge_time = test_lib.lib_set_expunge_time("volume", 1)
cond = res_ops.gen_query_conditions("status", "!=", "Deleted")
num = res_ops.query_resource_count(res_ops.VOLUME, cond)
if num <= thread_threshold:
volumes = res_ops.query_resource(res_ops.VOLUME, cond)
do_delete_volumes(volumes, thread_threshold)
else:
start = 0
limit = thread_threshold - 1
curr_num = start
volumes = []
while curr_num < num:
volumes_temp = res_ops.query_resource_fields(res_ops.VOLUME, cond, None, ["uuid"], start, limit)
volumes.extend(volumes_temp)
curr_num += limit
start += limit
do_delete_volumes(volumes, thread_threshold)
test_lib.lib_set_delete_policy("volume", delete_policy)
test_lib.lib_set_expunge_time("volume", expunge_time)
test_util.test_logger("Volumes destroy Success. Destroy %d Volumes." % num)
示例7: __init__
def __init__(self, get_host_con = None, justify_con = None):
self.exc_info = []
self.hosts = []
self.i = 0
self.session_uuid = None
self.session_to = None
self.session_mc = None
self.host_num = os.environ.get('ZSTACK_TEST_NUM')
self.thread_threshold = os.environ.get('ZSTACK_THREAD_THRESHOLD')
self.get_host_con = get_host_con
self.justify_con = justify_con
if not self.host_num:
self.host_num = 0
else:
self.host_num = int(self.host_num)
if not self.thread_threshold:
self.thread_threshold = 1000
else:
self.thread_threshold = int(self.thread_threshold)
self.hosts = res_ops.query_resource(res_ops.HOST, self.get_host_con)
if self.host_num > len(self.hosts):
self.host_num = len(self.hosts)
test_util.test_warn('ZSTACK_TEST_NUM is forcibly set as %d\n' % len(self.hosts))
self.session_to = con_ops.change_global_config('identity', 'session.timeout',\
'720000', self.session_uuid)
self.session_mc = con_ops.change_global_config('identity', 'session.maxConcurrent',\
'10000', self.session_uuid)
self.session_uuid = acc_ops.login_as_admin()
示例8: test
def test():
global session_uuid
global session_to
global session_mc
vm_num = os.environ.get('ZSTACK_TEST_NUM')
if not vm_num:
vm_num = 0
else:
vm_num = int(vm_num)
test_util.test_logger('ZSTACK_THREAD_THRESHOLD is %d' % thread_threshold)
test_util.test_logger('ZSTACK_TEST_NUM is %d' % vm_num)
org_num = vm_num
vm_creation_option = test_util.VmOption()
image_name = os.environ.get('imageName_s')
image_uuid = test_lib.lib_get_image_by_name(image_name).uuid
l3_name = os.environ.get('l3VlanNetworkName1')
conditions = res_ops.gen_query_conditions('name', '=', l3_name)
l3_uuid = res_ops.query_resource_with_num(res_ops.L3_NETWORK, conditions, \
session_uuid, start = 0, limit = 1)[0].uuid
vm_creation_option.set_l3_uuids([l3_uuid])
conditions = res_ops.gen_query_conditions('type', '=', 'UserVm')
instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING, conditions)[0].uuid
vm_creation_option.set_image_uuid(image_uuid)
vm_creation_option.set_instance_offering_uuid(instance_offering_uuid)
session_uuid = acc_ops.login_as_admin()
#change account session timeout.
session_to = con_ops.change_global_config('identity', 'session.timeout', '720000', session_uuid)
session_mc = con_ops.change_global_config('identity', 'session.maxConcurrent', '10000', session_uuid)
vm_creation_option.set_session_uuid(session_uuid)
vm = test_vm_header.ZstackTestVm()
random_name = random.random()
vm_name = 'multihost_basic_vm_%s' % str(random_name)
vm_creation_option.set_name(vm_name)
while vm_num > 0:
check_thread_exception()
vm.set_creation_option(vm_creation_option)
vm_num -= 1
thread = threading.Thread(target=create_vm, args=(vm,))
while threading.active_count() > thread_threshold:
time.sleep(1)
thread.start()
while threading.active_count() > 1:
time.sleep(0.01)
cond = res_ops.gen_query_conditions('name', '=', vm_name)
vms = res_ops.query_resource_count(res_ops.VM_INSTANCE, cond, session_uuid)
con_ops.change_global_config('identity', 'session.timeout', session_to, session_uuid)
con_ops.change_global_config('identity', 'session.maxConcurrent', session_mc, session_uuid)
acc_ops.logout(session_uuid)
if vms == org_num:
test_util.test_pass('Create %d VMs Test Success' % org_num)
else:
test_util.test_fail('Create %d VMs Test Failed. Only find %d VMs.' % (org_num, vms))
示例9: test
def test():
global session_to
global session_mc
global session_uuid
session_to = con_ops.change_global_config('identity', 'session.timeout', '720000', session_uuid)
session_mc = con_ops.change_global_config('identity', 'session.maxConcurrent', '10000', session_uuid)
session_uuid = acc_ops.login_as_admin()
cond = res_ops.gen_query_conditions('type', '=', 'Data')
num = res_ops.query_resource_count(res_ops.VOLUME, cond, session_uuid)
if num <= thread_threshold:
volumes = res_ops.query_resource(res_ops.VOLUME, cond, session_uuid)
delete_volumes(volumes)
else:
start = 0
limit = thread_threshold - 1
curr_num = start
volumes = []
while curr_num < num:
volumes_temp = res_ops.query_resource_with_num(res_ops.VOLUME, cond, session_uuid, start, limit)
volumes.extend(volumes_temp)
start += limit
curr_num += limit
delete_volumes(volumes)
#con_ops.change_global_config('identity', 'session.timeout', session_to)
#con_ops.change_global_config('identity', 'session.maxConcurrent', session_mc)
con_ops.change_global_config('identity', 'session.timeout', session_to, session_uuid)
con_ops.change_global_config('identity', 'session.maxConcurrent', session_mc, session_uuid)
left_num = res_ops.query_resource_count(res_ops.VOLUME, cond, session_uuid)
acc_ops.logout(session_uuid)
if left_num == 0:
test_util.test_pass('Delete Data Volume Success. Delete %d Volumes.' % num)
else:
test_util.test_fail('Delete Data Volume Fail. %d Volumes are not deleted.' % left_num)
示例10: test
def test():
global session_to
global session_mc
global session_uuid
session_uuid = acc_ops.login_as_admin()
session_to = con_ops.change_global_config('identity', 'session.timeout', '720000', session_uuid)
session_mc = con_ops.change_global_config('identity', 'session.maxConcurrent', '10000', session_uuid)
cond = res_ops.gen_query_conditions('type', '=', inventory.USER_VM_TYPE)
num = res_ops.query_resource_count(res_ops.VM_INSTANCE, cond, session_uuid)
if num <= thread_threshold:
vms = res_ops.query_resource(res_ops.VM_INSTANCE, cond, session_uuid)
destroy_vms(vms)
else:
start = 0
limit = thread_threshold - 1
curr_num = start
vms = []
while curr_num < num:
vms_temp = res_ops.query_resource_fields(res_ops.VM_INSTANCE, \
cond, session_uuid, ['uuid'], start, limit)
vms.extend(vms_temp)
curr_num += limit
start += limit
destroy_vms(vms)
vip_num = res_ops.query_resource_count(res_ops.VIP, [], session_uuid)
if vip_num <= thread_threshold:
vips = res_ops.query_resource(res_ops.VIP, [], session_uuid)
destroy_vips(vips)
else:
start = 0
limit = thread_threshold - 1
curr_num = start
vms = []
while curr_num < vip_num:
vips_temp = res_ops.query_resource_fields(res_ops.VIP, \
[], session_uuid, ['uuid'], start, limit)
vips.extend(vips_temp)
curr_num += limit
start += limit
destroy_vips(vips)
#con_ops.change_global_config('identity', 'session.timeout', session_to)
#con_ops.change_global_config('identity', 'session.maxConcurrent', session_mc)
left_num = res_ops.query_resource_count(res_ops.VM_INSTANCE, cond, session_uuid)
if left_num == 0:
test_util.test_pass('None VR VMs destroy Success. Destroy %d VMs.' % num)
else:
test_util.test_fail('None VR VMs destroy Fail. %d VMs are not Destroied.' % left_num)
left_num = res_ops.query_resource_count(res_ops.VIP, [], session_uuid)
if left_num == 0:
test_util.test_pass('VIP destroy Success. Destroy %d VIP.' % num)
else:
test_util.test_fail('VIP destroy Fail. %d VIP are not Destroied.' % left_num)
con_ops.change_global_config('identity', 'session.timeout', session_to, session_uuid)
con_ops.change_global_config('identity', 'session.maxConcurrent', session_mc, session_uuid)
acc_ops.logout(session_uuid)
示例11: cleanup_none_vm_volumes_violently
def cleanup_none_vm_volumes_violently():
session_uuid = acc_ops.login_as_admin()
try:
priSto_host_list = {}
result = res_ops.get_resource(res_ops.VOLUME, session_uuid)
for volume in result:
if not volume.installPath:
continue
volume_path = os.path.dirname(volume.installPath)
# VM volume has been cleanup in destroy_vm_and_storage_violently()
if not volume.hasattr("vmInstanceUuid"):
pri_sto_uuid = volume.primaryStorageUuid
if priSto_host_list.has_key(pri_sto_uuid):
host_ip = priSto_host_list[pri_sto_uuid]
else:
# TODO: need to add multi hosts, if primary storage is local storage.
host = _get_host_from_primary_storage(pri_sto_uuid, session_uuid)
host_ip = host.managementIp
priSto_host_list[pri_sto_uuid] = host_ip
thread = threading.Thread(target=_delete_file, args=(host_ip, volume_path))
thread.start()
while threading.active_count() > 1:
time.sleep(0.1)
except Exception as e:
test_util.test_logger("cleanup volumes violently meet exception")
traceback.print_exc(file=sys.stdout)
raise e
finally:
acc_ops.logout(session_uuid)
示例12: add_zone_resource
def add_zone_resource(deploy_config, zone_name):
session_uuid = acc_ops.login_as_admin()
try:
test_util.test_dsc('-------add zone operation-------')
dep_ops.add_zone(deploy_config, session_uuid, zone_name = zone_name)
test_util.test_dsc('-------add l2 operation-------')
dep_ops.add_l2_network(deploy_config, session_uuid, \
zone_name = zone_name)
test_util.test_dsc('-------add primary stroage operation-------')
dep_ops.add_primary_storage(deploy_config, session_uuid, \
zone_name = zone_name)
test_util.test_dsc('-------add cluster operation-------')
dep_ops.add_cluster(deploy_config, session_uuid, \
zone_name = zone_name)
test_util.test_dsc('-------add host operation-------')
dep_ops.add_host(deploy_config, session_uuid, \
zone_name = zone_name)
test_util.test_dsc('-------add l3 operation-------')
dep_ops.add_l3_network(deploy_config, session_uuid, \
zone_name = zone_name)
test_util.test_dsc('-------add virtual router offering operation-------')
dep_ops.add_virtual_router(deploy_config, session_uuid, \
zone_name = zone_name)
zone = res_ops.get_resource(res_ops.ZONE, session_uuid, \
name = zone_name)[0]
except Exception as e:
test_util.test_logger('[Error] zstack deployment meets exception when adding zone resource .')
traceback.print_exc(file=sys.stdout)
raise e
finally:
acc_ops.logout(session_uuid)
test_util.action_logger('Complete add zone resources for [uuid:] %s' \
% zone.uuid)
示例13: test
def test():
global session_uuid
session_uuid = acc_ops.login_as_admin()
l3_1_name = os.environ.get('l3VlanNetworkName1')
l3_1 = test_lib.lib_get_l3_by_name(l3_1_name)
#create VRs.
vrs = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)
if not vrs:
vm = test_stub.create_vlan_vm(l3_name=l3_1_name)
vm.destroy()
vr1 = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0]
else:
vr1 = vrs[0]
vm_ops.stop_vm(vr1.uuid)
if test_lib.lib_get_ha_enable() != 'true' or vr1.applianceVmType != "vrouter":
vm_ops.start_vm(vr1.uuid)
vr1_mgmt_ip = test_lib.lib_find_vr_mgmt_ip(vr1)
if not test_lib.lib_wait_target_up(vr1_mgmt_ip, '7272', 120):
test_util.test_fail('vr: %s is not startup in 120 seconds. Fail to reboot it. ' % vr1.uuid)
timeout = time.time() + 60
while time.time() < timeout:
cond = res_ops.gen_query_conditions('uuid', '=', vr1.uuid)
vms = res_ops.query_resource(res_ops.VM_INSTANCE, cond)
if vms[0].status == 'Connected':
test_util.test_pass('Test Reconnect VR VM start VRs success')
time.sleep(1)
test_util.test_fail('VR VM: %s is not connected within 60 seconds' % vr1.uuid)
示例14: test
def test():
global session_to
global session_mc
global session_uuid
session_to = con_ops.change_global_config('identity', 'session.timeout', '720000', session_uuid)
session_mc = con_ops.change_global_config('identity', 'session.maxConcurrent', '10000', session_uuid)
session_uuid = acc_ops.login_as_admin()
num = res_ops.query_resource_count(res_ops.VIP, [], session_uuid)
if num <= thread_threshold:
vips = res_ops.query_resource(res_ops.VIP, [], session_uuid)
delete_vips(vips)
else:
start = 0
limit = thread_threshold - 1
curr_num = start
vips = []
while curr_num < num:
vips_temp = res_ops.query_resource_fields(res_ops.VIP, [], \
session_uuid, ['uuid'], start, limit)
vips.extend(vips_temp)
curr_num += limit
start += limit
delete_vips(vips)
con_ops.change_global_config('identity', 'session.timeout', session_to, session_uuid)
con_ops.change_global_config('identity', 'session.maxConcurrent', session_mc, session_uuid)
left_num = res_ops.query_resource_count(res_ops.VIP, [], session_uuid)
acc_ops.logout(session_uuid)
if left_num == 0:
test_util.test_pass('Delete VIP Success. Delete %d VIPs.' % num)
else:
test_util.test_fail('Delete VIP Fail. %d VIPs are not deleted.' % left_num)
示例15: dump_zstack_deployment_config
def dump_zstack_deployment_config(deployConfig = None):
'''
deployConfig is the original zstack config. We need this conifg to set
username/password, as they are not get from ZStack API
will return an xmlobject
'''
if not deployConfig:
deployConfig = xmlobject.XmlObject('fake')
root_xml = etree.Element("deployerConfig")
session_uuid = account_operations.login_as_admin()
try:
add_nodes_config(root_xml, deployConfig.nodes__, session_uuid)
add_sftp_backup_stroage_config(root_xml, \
deployConfig.backupStorages__, session_uuid)
add_instance_offering_config(root_xml, session_uuid)
add_disk_offering_config(root_xml, session_uuid)
add_image_config(root_xml, deployConfig.images__, session_uuid)
add_zone_config(root_xml, deployConfig.zones, session_uuid)
except Exception as e:
test_util.test_logger('[Error] export zstack deployment configuration meets exception.')
traceback.print_exc(file=sys.stdout)
raise e
finally:
account_operations.logout(session_uuid)
return root_xml