def query_resource_count(resource, conditions = [], session_uuid=None): ''' Call Query API to return the matched resource count When count=true, it will only return the number of matched resource ''' action = _gen_query_action(resource) action.conditions = conditions action.count='true' account_operations.execute_action_with_session(action, session_uuid) return action.reply.total
def change_cluster_config(category, name, value, resourceUuid, session_uuid = None): action = api_actions.UpdateResourceConfigAction() action.category = category action.name = name action.value = value action.resourceUuid = resourceUuid if value: action.value = str(value) test_util.action_logger('change cluster config category: %s, name: %s, to %s' % (category, name, value)) account_operations.execute_action_with_session(action, session_uuid)
def change_global_config(category, name, value, session_uuid = None): default_value = get_global_config_default_value(category, name, session_uuid) pre_value = get_global_config_value(category, name, session_uuid) action = api_actions.UpdateGlobalConfigAction() action.category = category action.name = name action.defaultValue = str(default_value) if value: action.value = str(value) account_operations.execute_action_with_session(action, session_uuid) return pre_value
def reconnect_sftp_backup_storage(sftpbs_uuid, session_uuid=None, timeout=120000): action = api_actions.ReconnectSftpBackupStorageAction() action.uuid = sftpbs_uuid action.timeout = timeout test_util.action_logger('Reconnect SFTP Backup Storage [uuid:] %s' % sftpbs_uuid) evt = account_operations.execute_action_with_session(action, session_uuid) return evt.inventory
def delete_volume(volume_uuid, session_uuid=None): action = api_actions.DeleteDataVolumeAction() action.uuid = volume_uuid action.timeout = 120000 evt = account_operations.execute_action_with_session(action, session_uuid) test_util.action_logger('Delete Volume [uuid:] %s' % volume_uuid) return evt
def add_root_volume_template(image_creation_option): ''' Add root volume template ''' action = api_actions.AddImageAction() action.name = image_creation_option.get_name() action.guest_os_type = image_creation_option.get_guest_os_type() action.mediaType = 'RootVolumeTemplate' if image_creation_option.get_mediaType() and \ action.mediaType != image_creation_option.get_mediaType(): test_util.test_warn('image type %s was not %s' % \ (image_creation_option.get_mediaType(), action.mediaType)) action.backupStorageUuids = \ image_creation_option.get_backup_storage_uuid_list() action.bits = image_creation_option.get_bits() action.description = image_creation_option.get_description() action.format = image_creation_option.get_format() if image_creation_option.get_system_tags() != None: action.systemTags = image_creation_option.get_system_tags().split(',') action.url = image_creation_option.get_url() action.timeout = image_creation_option.get_timeout() test_util.action_logger('Add Root Volume Template from url: %s in [backup Storage:] %s' % (action.url, action.backupStorageUuids)) evt = account_operations.execute_action_with_session(action, \ image_creation_option.get_session_uuid()) return evt.inventory
def detach_volume(volume_uuid, session_uuid=None): action = api_actions.DetachDataVolumeFromVmAction() action.uuid = volume_uuid action.timeout = 120000 test_util.action_logger('Detach Volume [uuid:] %s' % volume_uuid) evt = account_operations.execute_action_with_session(action, session_uuid) return evt.inventory
def delete_zone(zone_uuid, session_uuid=None): action = api_actions.DeleteZoneAction() action.uuid = zone_uuid action.timeout = 600000 test_util.action_logger('Delete Zone [uuid:] %s' % zone_uuid) evt = account_operations.execute_action_with_session(action, session_uuid) return evt.inventory
def delete_snapshot(snapshot_uuid, session_uuid=None): action = api_actions.DeleteVolumeSnapshotAction() action.uuid = snapshot_uuid action.timeout = 60000 test_util.action_logger('Delete [Snapshot:] %s ' % snapshot_uuid) evt = account_operations.execute_action_with_session(action, session_uuid) return evt
def list_resource(resource, session_uuid=None, uuid=None, name=None): ''' Return: list by list API. ''' if resource == BACKUP_STORAGE: action = api_actions.ListBackupStorageAction() elif resource == ZONE: action = api_actions.ListZonesAction() elif resource == PRIMARY_STORAGE: action = api_actions.ListPrimaryStorageAction() elif resource == L2_NETWORK: action = api_actions.ListL2NetworkAction() elif resource == L2_VLAN_NETWORK: action = api_actions.ListL2VlanNetworkAction() elif resource == CLUSTER: action = api_actions.ListClusterAction() elif resource == L3_NETWORK: action = api_actions.ListL3NetworkAction() elif resource == INSTANCE_OFFERING: action = api_actions.ListInstanceOfferingAction() elif resource == IMAGE: action = api_actions.ListImageAction() elif resource == VOLUME: action = api_actions.ListVolumeAction() elif resource == VM_INSTANCE: action = api_actions.ListVmInstanceAction() elif resource == IP_RANGE: action = api_actions.ListIpRangeAction() elif resource == HOST: action = api_actions.ListHostAction() elif resource == NETWORK_SERVICE_PROVIDER: action = api_actions.ListNetworkServiceProviderAction() elif resource == APPLIANCE_VM: action = api_actions.ListApplianceVmAction() elif resource == DISK_OFFERING: action = api_actions.ListDiskOfferingAction() elif resource == ACCOUNT: action = api_actions.ListAccountAction() elif resource == PRIMARY_STORAGE: action = api_actions.ListPrimaryStorageAction() elif resource == SECURITY_GROUP: action = api_actions.ListSecurityGroupAction() elif resource == VM_SECURITY_GROUP: action = api_actions.ListVmNicInSecurityGroupAction() elif resource == VM_NIC: action = api_actions.ListVmNicAction() elif resource == PORT_FORWARDING: action = api_actions.ListPortForwardingRuleAction() elif resource == MANAGEMENT_NODE: action = api_actions.ListManagementNodeAction() ret = account_operations.execute_action_with_session(action, session_uuid) if uuid: return find_item_by_uuid(ret, uuid) if name: return find_item_by_name(ret, name) return ret
def update_system_tag(tag_uuid, tag, session_uuid = None): action = api_actions.UpdateSystemTagAction() action.uuid = tag_uuid action.tag = tag test_util.action_logger('Update Tag [uuid:] %s to %s' % (tag_uuid, tag)) evt = account_operations.execute_action_with_session(action, session_uuid) return evt.inventory
def create_template_from_snapshot(image_creation_option, session_uuid=None): action = api_actions.CreateRootVolumeTemplateFromVolumeSnapshotAction() action.snapshotUuid = image_creation_option.get_root_volume_uuid() action.backupStorageUuids = image_creation_option.get_backup_storage_uuid_list() action.guestOsType = image_creation_option.get_guest_os_type() action.system = image_creation_option.get_system() action.platform = image_creation_option.get_platform() name = image_creation_option.get_name() if not name: action.name = 'test_template_image_by_snapshot' else: action.name = name description = image_creation_option.get_description() if not description: action.description = "test create template from snapshot: %s" % \ action.snapshotUuid else: action.description = description test_util.action_logger('Create Image Template from [snapshot:] %s in [backup Storage:] %s' % (action.snapshotUuid, action.backupStorageUuids)) evt = account_operations.execute_action_with_session(action, image_creation_option.get_session_uuid()) return evt.inventory
def expunge_image(image_uuid, backup_storage_uuid_list=None, session_uuid=None): action = api_actions.ExpungeImageAction() action.imageUuid = image_uuid action.backupStorageUuids = backup_storage_uuid_list test_util.action_logger('Expunge [image:] %s' % image_uuid) evt = account_operations.execute_action_with_session(action, session_uuid) return evt
def delete_host(host_uuid, session_uuid=None): action = api_actions.DeleteHostAction() action.uuid = host_uuid action.timeout = 120000 test_util.action_logger('Delete Host [uuid:] %s' % host_uuid) evt = account_operations.execute_action_with_session(action, session_uuid) return evt.inventory
def delete_scheduler(uuid, session_uuid = None): action = api_actions.DeleteSchedulerAction() action.uuid = uuid test_util.action_logger('Delete [Scheduler:] %s' % uuid) evt = account_operations.execute_action_with_session(action, session_uuid) test_util.test_logger('[Scheduler:] %s is deleted.' % uuid) return evt
def reboot_vm(vm_uuid, session_uuid=None): action = api_actions.RebootVmInstanceAction() action.uuid = vm_uuid action.timeout = 120000 test_util.action_logger('Reboot VM [uuid:] %s' % vm_uuid) evt = account_operations.execute_action_with_session(action, session_uuid) return evt.inventory
def delete_instance_offering(instance_offering_uuid, session_uuid = None): action = api_actions.DeleteInstanceOfferingAction() action.uuid = instance_offering_uuid test_util.action_logger('Delete Instance Offering [uuid:] %s' \ % instance_offering_uuid) evt = account_operations.execute_action_with_session(action, session_uuid) return evt
def reconnect_host(host_uuid, session_uuid=None, timeout=120000): action = api_actions.ReconnectHostAction() action.uuid = host_uuid action.timeout = timeout test_util.action_logger('Reconnect Host [uuid:] %s' % host_uuid) evt = account_operations.execute_action_with_session(action, session_uuid) return evt.inventory
def create_root_volume_template(image_creation_option): ''' Create Root Volume Template from a root volume ''' action = api_actions.CreateRootVolumeTemplateFromRootVolumeAction() action.rootVolumeUuid = image_creation_option.get_root_volume_uuid() action.backupStorageUuids = image_creation_option.get_backup_storage_uuid_list() name = image_creation_option.get_name() if not name: action.name = 'test_template_image' else: action.name = name action.guestOsType = image_creation_option.get_guest_os_type() action.system = image_creation_option.get_system() action.platform = image_creation_option.get_platform() description = image_creation_option.get_description() if not description: action.description = "test create template from volume" else: action.description = description test_util.action_logger('Create Image Template from [root Volume:] %s in [backup Storage:] %s' % (action.rootVolumeUuid, action.backupStorageUuids)) evt = account_operations.execute_action_with_session(action, image_creation_option.get_session_uuid()) return evt.inventory
def get_trash_on_backup_storage(backup_storage_uuid, session_uuid=None): action = api_actions.GetTrashOnBackupStorageAction() action.uuid = backup_storage_uuid action.timeout = 6000000 test_util.action_logger('Get Trash On Backup Storage [uuid:] %s' % backup_storage_uuid) evt = account_operations.execute_action_with_session(action, session_uuid) return evt.storageTrashSpecs
def update_image_platform(uuid, platform, session_uuid=None): action = api_actions.UpdateImageAction() action.uuid = uuid action.platform = platform test_util.action_logger('Update [image %s] platform' % (uuid)) evt = account_operations.execute_action_with_session(action, session_uuid) return evt.inventory
def use_snapshot(snapshot_uuid, session_uuid=None): action = api_actions.RevertVolumeFromSnapshotAction() action.uuid = snapshot_uuid action.timeout = 12000 test_util.action_logger('Revert Volume by [Snapshot:] %s ' % snapshot_uuid) evt = account_operations.execute_action_with_session(action, session_uuid) return evt
def delete_disk_offering(disk_offering_uuid, session_uuid = None): action = api_actions.DeleteDiskOfferingAction() action.uuid = disk_offering_uuid test_util.action_logger('Delete Disk Offering [uuid:] %s' \ % disk_offering_uuid) evt = account_operations.execute_action_with_session(action, session_uuid) return evt
def migrate_volume(volume_uuid, host_uuid, session_uuid = None): action = api_actions.LocalStorageMigrateVolumeAction() action.destHostUuid = host_uuid action.volumeUuid = volume_uuid test_util.action_logger('Migrate Local Storage Volume: %s to Host: %s' \ % (volume_uuid, host_uuid)) evt = account_operations.execute_action_with_session(action, session_uuid)
def revert_vm_from_backup(group_uuid, session_uuid=None): action = api_actions.RevertVmFromVmBackupAction() action.groupUuid = group_uuid action.timeout = 1800000 evt = account_operations.execute_action_with_session(action, session_uuid) test_util.test_logger('Revert [volume_uuid:] %s ' % group_uuid) return evt.inventory
def batch_delete_snapshot(snapshot_uuid_list, session_uuid=None): action = api_actions.BatchDeleteVolumeSnapshotAction() action.uuids = snapshot_uuid_list action.timeout = 300000 test_util.action_logger('Batch Delete [Snapshots:] %s ' % snapshot_uuid_list) evt = account_operations.execute_action_with_session(action, session_uuid) return evt
def delete_volume_backup(bs_uuids, uuid, session_uuid=None): action = api_actions.DeleteVolumeBackupAction() action.uuid = uuid action.backupStorageUuids = bs_uuids action.timeout = 1800000 evt = account_operations.execute_action_with_session(action, session_uuid) return evt.inventory
def recover_volume(volume_uuid, session_uuid=None): action = api_actions.RecoverDataVolumeAction() action.uuid = volume_uuid action.timeout = 240000 evt = account_operations.execute_action_with_session(action, session_uuid) test_util.action_logger('Recover Volume [uuid:] %s' % volume_uuid) return evt.inventory
def change_image_state(uuid, state, session_uuid): action = api_actions.ChangeImageStateAction() action.uuid = uuid action.stateEvent = state test_util.action_logger('Change [image %s] state' % (uuid)) evt = account_operations.execute_action_with_session(action, session_uuid) return evt.inventory
def delete_tag(tag_uuid, session_uuid=None): action = api_actions.DeleteTagAction() action.uuid = tag_uuid action.timeout = 30000 test_util.action_logger('Delete Tag [uuid:] %s' % tag_uuid) evt = account_operations.execute_action_with_session(action, session_uuid) return evt
def sync_image_from_image_store_backup_storage(dst_bs_uuid, src_bs_uuid, img_uuid, name=None, session_uuid=None): action = api_actions.SyncImageFromImageStoreBackupStorageAction() action.dstBackupStorageUuid = dst_bs_uuid action.srcBackupStorageUuid = src_bs_uuid action.uuid = img_uuid if name != None: action.name = name else: action.name = 'backup_image' evt = account_operations.execute_action_with_session(action, session_uuid) return evt.inventory
def create_data_template_from_backup(backupStorageUuid, backupUuid, name=None, session_uuid=None): action = api_actions.CreateDataVolumeTemplateFromVolumeBackupAction() action.backupStorageUuid = backupStorageUuid action.backupUuid = backupUuid if not name: name = "backup_image_%s" % backupUuid action.name = name evt = account_operations.execute_action_with_session(action, session_uuid) test_util.action_logger( "Create image from [backup:] %s in [backup Storage:] %s" % (backupUuid, backupStorageUuid)) return evt.inventory
def create_aliyun_nas_file_system(datacenter_uuid, name, storage_type, protocol='NFS', session_uuid=None): action = api_actions.CreateAliyunNasFileSystemAction() action.dataCenterUuid = datacenter_uuid action.storageType = storage_type action.protocol = protocol action.name = name test_util.action_logger('Create [Aliyun NASFile System:] %s %s' % (protocol, storage_type)) evt = account_operations.execute_action_with_session(action, session_uuid) test_util.test_logger('[Aliyun NASFile System:] %s %s is added.' % (protocol, storage_type)) return evt.inventory
def query_resource_fields(resource, conditions=[], session_uuid=None, fields=[], start=0, limit=1000): ''' Query matched resource by returning required fields and required numbers. ''' action = _gen_query_action(resource) action.conditions = conditions action.start = start action.limit = limit action.fields = fields ret = account_operations.execute_action_with_session(action, session_uuid) return ret
def create_volume_from_template(image_uuid, ps_uuid, name = None, \ host_uuid = None, session_uuid = None): action = api_actions.CreateDataVolumeFromVolumeTemplateAction() action.imageUuid = image_uuid action.primaryStorageUuid = ps_uuid if name: action.name = name else: action.name = 'new volume from template %s' % image_uuid if host_uuid: action.hostUuid = host_uuid evt = account_operations.execute_action_with_session(action, session_uuid) test_util.test_logger('[Volume:] %s is created from [Volume Template:] %s on [Primary Storage:] %s.' % (evt.inventory.uuid, image_uuid, ps_uuid)) return evt.inventory
def query_event_from_resource_stack(conditions=[], resource=EVENT_FROM_STACK, session_uuid=None, count='false'): ''' Call Query API and return all matched resource. conditions could be generated by gen_query_conditions() If session_uuid is missing, we will create one for you and only live in this API. ''' action = _gen_query_action(resource, conditions) action.conditions = conditions ret = account_operations.execute_action_with_session(action, session_uuid) return ret
def create_instance_offering(instance_offering_option, session_uuid=None): action = api_actions.CreateInstanceOfferingAction() action.cpuNum = instance_offering_option.get_cpuNum() action.cpuSpeed = instance_offering_option.get_cpuSpeed() action.memorySize = instance_offering_option.get_memorySize() action.allocatorStrategy = instance_offering_option.get_allocatorStrategy() action.type = instance_offering_option.get_type() action.name = instance_offering_option.get_name() action.description = instance_offering_option.get_description() test_util.action_logger('create instance offering: name: %s cpuNum: %s, cpuSpeed: %s, memorySize: %s, allocatorStrategy: %s, type: %s '\ % (action.name, action.cpuNum, action.cpuSpeed, action.memorySize, action.allocatorStrategy, action.type)) evt = account_operations.execute_action_with_session(action, session_uuid) test_util.test_logger('Instance Offering: %s is created' % evt.inventory.uuid) return evt.inventory
def get_global_config_value(category, name, session_uuid = None, \ default_value = None): value = None action = api_actions.QueryGlobalConfigAction() action.category = category action.conditions = [{'name': 'name', 'op': '=', 'value': name}] test_util.action_logger('Get global config category: %s, name: %s' \ % (category, name)) result = account_operations.execute_action_with_session(action, \ session_uuid) if result: if default_value != None and default_value: return result[0].defaultValue else: return result[0].value
def add_image(image_option): action = api_actions.AddImageAction() action.name = image_option.get_name() action.url = image_option.get_url() action.mediaType = image_option.get_mediaType() action.format = image_option.get_format() action.platform = image_option.get_platform() action.backupStorageUuids = image_option.get_backup_storage_uuid_list() action.resourceUuid = image_option.get_uuid() action.timeout = image_option.get_timeout() test_util.action_logger('Add [Image:] %s from [url:] %s ' % (action.name, action.url)) evt = account_operations.execute_action_with_session( action, image_option.get_session_uuid()) test_util.test_logger('[image:] %s is added.' % evt.inventory.uuid) return evt.inventory
def create_sftp_backup_storage(backup_storage_option, session_uuid=None): action = api_actions.AddSftpBackupStorageAction() action.timeout = 300000 action.name = backup_storage_option.get_name() action.description = backup_storage_option.get_description() action.type = backup_storage_option.get_type() action.url = backup_storage_option.get_url() action.hostname = backup_storage_option.get_hostname() action.username = backup_storage_option.get_username() action.password = backup_storage_option.get_password() action.sshPort = backup_storage_option.get_sshport() action.resourceUuid = backup_storage_option.get_resource_uuid() evt = account_operations.execute_action_with_session(action, session_uuid) test_util.action_logger('Create Sftp Backup Storage [uuid:] %s [name:] %s' % \ (evt.inventory.uuid, action.name)) return evt.inventory
def update_sftp_backup_storage_info(sftpUuid, infoType, infoValue, session_uuid=None): action = api_actions.UpdateSftpBackupStorageAction() action.uuid = sftpUuid if infoType == 'password': action.password = infoValue elif infoType == 'hostname': action.hostname = infoValue elif infoType == 'sshPort': action.sshPort = infoValue elif infoType == 'username': action.username = infoValue evt = account_operations.execute_action_with_session(action, session_uuid) return evt
def create_volume_from_snapshot(snapshot_uuid, name=None, ps_uuid=None, \ session_uuid=None): action = api_actions.CreateDataVolumeFromVolumeSnapshotAction() if name: action.name = name else: action.name = 'create_volume_from_snapshot' action.primaryStorageUuid = ps_uuid action.volumeSnapshotUuid = snapshot_uuid evt = account_operations.execute_action_with_session(action, session_uuid) volume = evt.inventory test_util.action_logger('[Volume:] %s is created from [snapshot]: %s on \ [primary storage:] %s' % (volume.uuid, snapshot_uuid, \ volume.primaryStorageUuid)) return volume
def create_backup(backup_option, session_uuid=None): action = api_actions.CreateVolumeBackupAction() action.volumeUuid = backup_option.get_volume_uuid() action.backupStorageUuid = backup_option.get_backupStorage_uuid() action.name = backup_option.get_name() if not action.name: action.name = 'backup_for_volume_%s' % action.volumeUuid action.description = backup_option.get_description() action.timeout = 240000 if backup_option.get_session_uuid(): session_uuid = backup_option.get_session_uuid() evt = account_operations.execute_action_with_session(action, session_uuid) backup = evt.inventory test_util.action_logger('Create [Backup:] %s [uuid:] %s for [volume:] %s' % \ (action.name, backup.uuid, action.volumeUuid)) return backup
def add_data_volume_template(image_option): action = api_actions.AddImageAction() action.name = image_option.get_name() action.url = image_option.get_url() action.mediaType = 'DataVolumnTemplate' if image_option.get_mediaType() and \ action.mediaType != image_option.get_mediaType(): test_util.test_warn('image type %s was not %s' % \ (image_option.get_mediaType(), action.mediaType)) action.format = image_option.get_format() action.backupStorageUuids = image_option.get_backup_stroage_list() test_util.action_logger('Add [Volume:] %s from [url:] %s ' % (action.name, action.url)) evt = account_operations.execute_action_with_session(action, image_option.get_session_uuid()) test_util.test_logger('[volume:] %s is added.' % evt.inventory.uuid) return evt.inventory
def create_volume_template(volume_uuid, backup_storage_uuid_list, name = None, \ session_uuid = None): action = api_actions.CreateDataVolumeTemplateFromVolumeAction() action.volumeUuid = volume_uuid if name: action.name = name else: action.name = 'new_template_from_volume_%s' % volume_uuid action.backupStorageUuids = backup_storage_uuid_list test_util.action_logger( 'Create [Volume Template] for [Volume:] %s on [Backup Storages:] %s' % (volume_uuid, backup_storage_uuid_list)) evt = account_operations.execute_action_with_session(action, session_uuid) test_util.test_logger('[Volume Templated:] %s is created.' % evt.inventory.uuid) return evt.inventory
def create_vm(vm_create_option): create_vm = api_actions.CreateVmInstanceAction() name = vm_create_option.get_name() if not name: create_vm.name = 'test_vm_default_name' else: create_vm.name = name create_vm.imageUuid = vm_create_option.get_image_uuid() create_vm.zoneUuid = vm_create_option.get_zone_uuid() create_vm.clusterUuid = vm_create_option.get_cluster_uuid() create_vm.hostUuid = vm_create_option.get_host_uuid() create_vm.instanceOfferingUuid = vm_create_option.get_instance_offering_uuid( ) create_vm.l3NetworkUuids = vm_create_option.get_l3_uuids() create_vm.defaultL3NetworkUuid = vm_create_option.get_default_l3_uuid() #If there are more than 1 network uuid, the 1st one will be the default l3. if len(create_vm.l3NetworkUuids ) > 1 and not create_vm.defaultL3NetworkUuid: create_vm.defaultL3NetworkUuid = create_vm.l3NetworkUuids[0] vm_type = vm_create_option.get_vm_type() if not vm_type: create_vm.type = 'UserVm' else: create_vm.type = vm_type create_vm.systemTags = vm_create_option.get_system_tags() create_vm.userTags = vm_create_option.get_user_tags() timeout = vm_create_option.get_timeout() if not timeout: create_vm.timeout = 600000 else: create_vm.timeout = timeout create_vm.dataDiskOfferingUuids = vm_create_option.get_data_disk_uuids() create_vm.rootDiskOfferingUuid = vm_create_option.get_root_disk_uuid() test_util.action_logger( 'Create VM: %s with [image:] %s and [l3_network:] %s' % (create_vm.name, create_vm.imageUuid, create_vm.l3NetworkUuids)) evt = account_operations.execute_action_with_session( create_vm, vm_create_option.get_session_uuid()) test_util.test_logger('[vm:] %s is created.' % evt.inventory.uuid) return evt.inventory
def create_scheduler_job(name, description, target_uuid, type, parameters, session_uuid=None): action = api_actions.CreateSchedulerJobAction() action.name = name action.description = description action.targetResourceUuid = target_uuid action.type = type action.parameters = parameters test_util.action_logger('Create [Scheduler Job:] %s [%s] %s' % (name, target_uuid, type)) evt = account_operations.execute_action_with_session(action, session_uuid) test_util.test_logger('[Scheduler Job:] %s is created.' % evt.inventory.uuid) return evt.inventory
def create_scheduler_trigger(name, start_time, repeat_count, interval, type, session_uuid=None): action = api_actions.CreateSchedulerTriggerAction() action.name = name action.startTime = start_time action.repeatCount = repeat_count action.schedulerInterval = interval action.schedulerType = type test_util.action_logger('Create [Scheduler Trigger:] %s [%s] %s %s' % (name, start_time, repeat_count, interval)) evt = account_operations.execute_action_with_session(action, session_uuid) test_util.test_logger('[Scheduler Trigger:] %s is created.' % evt.inventory.uuid) return evt.inventory
def commit_volume_as_image(image_creation_option, session_uuid = None): action = api_actions.CommitVolumeAsImageAction() action.name = image_creation_option.get_name() action.volumeUuid = image_creation_option.get_root_volume_uuid() action.backupStorageUuids = image_creation_option.get_backup_storage_uuid_list() action.guestOsType = image_creation_option.get_guest_os_type() action.system = image_creation_option.get_system() action.platform = image_creation_option.get_platform() description = image_creation_option.get_description() if not description: action.description = "test commit volume as image" else: action.description = description test_util.action_logger('Commit Image Template from [Volume:] %s in [backup Storage:] %s' % (action.volumeUuid, action.backupStorageUuids)) evt = account_operations.execute_action_with_session(action, image_creation_option.get_session_uuid()) return evt.inventory
def create_ceph_primary_storage(primary_storage_option, session_uuid=None): action = api_actions.AddCephPrimaryStorageAction() action.timeout = 300000 action.name = primary_storage_option.get_name() action.description = primary_storage_option.get_description() action.type = primary_storage_option.get_type() action.monUrls = primary_storage_option.get_monUrls() action.imageCachePoolName = \ primary_storage_option.get_imageCachePoolName() action.dataVolumePoolName = \ primary_storage_option.get_dataVolumePoolName() action.rootVolumePoolName = \ primary_storage_option.get_rootVolumePoolName() action.zoneUuid = primary_storage_option.get_zone_uuid() evt = account_operations.execute_action_with_session(action, session_uuid) test_util.action_logger('Create Primary Storage [uuid:] %s [name:] %s' % \ (evt.inventory.uuid, action.name)) return evt.inventory
def reconnect_host(host_uuid, session_uuid=None, timeout=120000): action = api_actions.ReconnectHostAction() action.uuid = host_uuid action.timeout = timeout test_util.action_logger('Reconnect Host [uuid:] %s' % host_uuid) evt = account_operations.execute_action_with_session(action, session_uuid) cur_time = time.time() while True: cond = resource_operations.gen_query_conditions('uuid', '=', host_uuid) host = resource_operations.query_resource_with_num(resource_operations.HOST, cond, limit = 1)[0] if host.status == "Connected" or host.status == "Disconnected": break time.sleep(1) if cur_time - time.time() > timeout: test_util.test_logger("reconnect_host timeout(%s)" % (timeout)) break return evt.inventory
def create_ceph_backup_storage(backup_storage_option, session_uuid=None): action = api_actions.AddCephBackupStorageAction() action.timeout = 300000 action.name = backup_storage_option.get_name() action.description = backup_storage_option.get_description() action.type = backup_storage_option.get_type() action.monUrls = backup_storage_option.get_monUrls() action.imageCachePoolName = \ backup_storage_option.get_imageCachePoolName() action.dataVolumePoolName = \ backup_storage_option.get_dataVolumePoolName() action.rootVolumePoolName = \ backup_storage_option.get_rootVolumePoolName() action.resourceUuid = backup_storage_option.get_resource_uuid() action.importImages = backup_storage_option.get_import_images() evt = account_operations.execute_action_with_session(action, session_uuid) test_util.action_logger('Create Ceph Backup Storage [uuid:] %s [name:] %s' % \ (evt.inventory.uuid, action.name)) return evt.inventory
def add_ceph_primary_storage_pool(primary_storage_uuid, pool_name, aliasName=None, isCreate=None, resourceUuid=None, description=None, session_uuid=None): action = api_actions.AddCephPrimaryStoragePoolAction() action.timeout = 300000 action.primaryStorageUuid = primary_storage_uuid action.poolName = pool_name action.aliasName = aliasName action.description = description action.isCreate = isCreate action.resourceUuid = resourceUuid evt = account_operations.execute_action_with_session(action, session_uuid) test_util.action_logger('Create Primary Storage [uuid:] %s Pool [uuid:] %s [name:] %s' % \ (action.primaryStorageUuid, evt.inventory.uuid, action.poolName)) return evt.inventory
def add_ldap_server(name, description, url, base, username, password, encryption='None', session_uuid=None): action = api_actions.AddLdapServerAction() action.name = name action.description = description action.url = url action.base = base action.username = username action.password = password action.encryption = encryption test_util.action_logger('Add [ldap Server:] %s' % url) evt = account_operations.execute_action_with_session(action, session_uuid) test_util.test_logger('[ldap Server:] %s is added.' % url) return evt
def add_iso_template(image_creation_option): ''' Add iso template ''' action = api_actions.AddImageAction() action.name = image_creation_option.get_name() action.guest_os_type = image_creation_option.get_guest_os_type() action.mediaType = 'ISO' action.backupStorageUuids = \ image_creation_option.get_backup_storage_uuid_list() action.bits = image_creation_option.get_bits() action.description = image_creation_option.get_description() action.format = 'iso' action.url = image_creation_option.get_url() action.timeout = image_creation_option.get_timeout() test_util.action_logger('Add ISO Template from url: %s in [backup Storage:] %s' % (action.url, action.backupStorageUuids)) evt = account_operations.execute_action_with_session(action, \ image_creation_option.get_session_uuid()) return evt.inventory
def create_snapshot_scheduler(snapshot_option, type, name, start_time=None, interval=None, repeatCount=None, cron=None, session_uuid=None): action = api_actions.CreateVolumeSnapshotSchedulerAction() action.volumeUuid = snapshot_option.get_volume_uuid() action.snapShotName = snapshot_option.get_name() if not action.snapShotName: action.snapShotName = 'scheduler_snapshot_for_volume_%s' % action.volumeUuid action.description = snapshot_option.get_description() action.type = type action.schedulerName = name action.startTime = start_time action.interval = interval action.repeatCount = repeatCount action.cron = cron action.timeout = 240000 if snapshot_option.get_session_uuid(): session_uuid = snapshot_option.get_session_uuid() evt = account_operations.execute_action_with_session(action, session_uuid) snapshot = evt.inventory test_util.action_logger('Scheduler Create [Snapshot:] %s for [volume:] %s [type:] %s [startTime:] %s [interval:] %s [repeatCount:] %s [cron:] %s' % \ (action.snapShotName, action.volumeUuid, type, start_time, interval, repeatCount, cron)) return snapshot
def create_volume_from_offering(volume_option): action = api_actions.CreateDataVolumeAction() action.diskOfferingUuid = volume_option.get_disk_offering_uuid() action.description = volume_option.get_description() timeout = volume_option.get_timeout() if not timeout: action.timeout = 120000 else: action.timeout = timeout name = volume_option.get_name() if not name: action.name = 'test_volume' else: action.name = name test_util.action_logger('Create [Volume:] %s with [disk offering:] %s ' % (action.name, action.diskOfferingUuid)) evt = account_operations.execute_action_with_session(action, volume_option.get_session_uuid()) test_util.test_logger('[volume:] %s is created.' % evt.inventory.uuid) return evt.inventory
def update_scheduler(uuid, type, name, start_date=None, interval=None, repeatCount=None, cron=None, session_uuid=None): action = api_actions.UpdateSchedulerAction() action.uuid = uuid action.schedulerType = type action.schedulerName = name action.startDate = start_date action.schedulerInterval = interval action.repeatCount = repeatCount action.cronScheduler = cron test_util.action_logger('Update [Scheduler:] %s [schdulerType:] %s [schdulerName:] %s [startDate:] %s [interval:] %s [repeatCount:] %s [cron:] %s' \ % (uuid, type, name, start_date, interval, repeatCount, cron)) evt = account_operations.execute_action_with_session(action, session_uuid) test_util.test_logger('[Scheduler:] %s is updated.' % uuid) return evt
def create_ipsec_connection(name, l3_uuid, peer_address, auth_key, vip_uuid, peer_cidrs, policy_mode=None, description=None, session_uuid=None): action = api_actions.CreateIPsecConnectionAction() action.timeout = 30000 action.name = name action.l3NetworkUuid = l3_uuid action.peerAddress = peer_address action.authKey = auth_key action.vipUuid = vip_uuid action.peerCidrs = peer_cidrs action.policyMode = policy_mode action.description = description evt = account_operations.execute_action_with_session(action, session_uuid) test_util.action_logger('Create Ipsec Connection [name:] %s [l3NetworkUuid:] %s [peerAddress:] %s' % \ (name, l3_uuid, peer_address)) return evt.inventory
def add_root_volume_template(image_creation_option): ''' Add root volume template ''' action = api_actions.AddImageAction() action.name = image_creation_option.get_name() action.guest_os_type = image_creation_option.get_guest_os_type() action.mediaType = 'RootVolumeTemplate' if image_creation_option.get_mediaType() and \ action.mediaType != image_creation_option.get_mediaType(): test_util.test_warn('image type %s was not %s' % \ (image_creation_option.get_mediaType(), action.mediaType)) action.backupStorageUuids = \ image_creation_option.get_backup_storage_uuid_list() action.bits = image_creation_option.get_bits() action.description = image_creation_option.get_description() action.format = image_creation_option.get_format() action.url = image_creation_option.get_url() action.timeout = image_creation_option.get_timeout() test_util.action_logger('Add Root Volume Template from url: %s in [backup Storage:] %s' % (action.url, action.backupStorageUuids)) evt = account_operations.execute_action_with_session(action, \ image_creation_option.get_session_uuid()) return evt.inventory