Esempio n. 1
0
def _gen_query_action(resource):
    if resource == BACKUP_STORAGE:
        action = api_actions.QueryBackupStorageAction()
    elif resource == SFTP_BACKUP_STORAGE:
        action = api_actions.QuerySftpBackupStorageAction()
    elif resource == CEPH_BACKUP_STORAGE:
        action = api_actions.QueryCephBackupStorageAction()
    elif resource == ZONE:
        action = api_actions.QueryZoneAction()
    elif resource == PRIMARY_STORAGE:
        action = api_actions.QueryPrimaryStorageAction()
    elif resource == L2_NETWORK:
        action = api_actions.QueryL2NetworkAction()
    elif resource == L2_VLAN_NETWORK:
        action = api_actions.QueryL2VlanNetworkAction()
    elif resource == CLUSTER:
        action = api_actions.QueryClusterAction()
    elif resource == L3_NETWORK:
        action = api_actions.QueryL3NetworkAction()
    elif resource == INSTANCE_OFFERING:
        action = api_actions.QueryInstanceOfferingAction()
    elif resource == IMAGE:
        action = api_actions.QueryImageAction()
    elif resource == VOLUME:
        action = api_actions.QueryVolumeAction()
    elif resource == VM_INSTANCE:
        action = api_actions.QueryVmInstanceAction()
    elif resource == IP_RANGE:
        action = api_actions.QueryIpRangeAction()
    elif resource == HOST:
        action = api_actions.QueryHostAction()
    elif resource == NETWORK_SERVICE_PROVIDER:
        action = api_actions.QueryNetworkServiceProviderAction()
    elif resource == NETWORK_SERVICE_PROVIDER_L3_REF:
        action = api_actions.QueryNetworkServiceL3NetworkRefAction()
    elif resource == APPLIANCE_VM:
        action = api_actions.QueryApplianceVmAction()
    elif resource == VIRTUALROUTER_VM:
        action = api_actions.QueryVirtualRouterVmAction()
    elif resource == DISK_OFFERING:
        action = api_actions.QueryDiskOfferingAction()
    elif resource == ACCOUNT:
        action = api_actions.QueryAccountAction()
    elif resource == PRIMARY_STORAGE:
        action = api_actions.QueryPrimaryStorageAction()
    elif resource == CEPH_PRIMARY_STORAGE:
        action = api_actions.QueryCephPrimaryStorageAction()
    elif resource == SECURITY_GROUP:
        action = api_actions.QuerySecurityGroupAction()
    elif resource == SECURITY_GROUP_RULE:
        action = api_actions.QuerySecurityGroupRuleAction()
    elif resource == VM_SECURITY_GROUP:
        action = api_actions.QueryVmNicInSecurityGroupAction()
    elif resource == VM_NIC:
        action = api_actions.QueryVmNicAction()
    elif resource == PORT_FORWARDING:
        action = api_actions.QueryPortForwardingRuleAction()
    elif resource == MANAGEMENT_NODE:
        action = api_actions.QueryManagementNodeAction()
    elif resource == EIP:
        action = api_actions.QueryEipAction()
    elif resource == VIP:
        action = api_actions.QueryVipAction()
    elif resource == VR_OFFERING:
        action = api_actions.QueryVirtualRouterOfferingAction()
    elif resource == SYSTEM_TAG:
        action = api_actions.QuerySystemTagAction()
    elif resource == USER_TAG:
        action = api_actions.QueryUserTagAction()
    elif resource == VOLUME_SNAPSHOT_TREE:
        action = api_actions.QueryVolumeSnapshotTreeAction()
    elif resource == VOLUME_SNAPSHOT:
        action = api_actions.QueryVolumeSnapshotAction()
    elif resource == USER:
        action = api_actions.QueryUserAction()
    elif resource == LOAD_BALANCER:
        action = api_actions.QueryLoadBalancerAction()
    elif resource == LOAD_BALANCER_LISTENER:
        action = api_actions.QueryLoadBalancerListenerAction()
    elif resource == LOCAL_STORAGE_RESOURCE_REF:
        action = api_actions.QueryLocalStorageResourceRefAction()

    return action
Esempio n. 2
0
def query_img(conditions=[], parameters=[]):
	action = api_actions.QueryImageAction()
	action.conditions = conditions
	action.parameters = parameters
	evt = zs.execute_action_with_session(action,zs.login_as_admin())
	return evt 
Esempio n. 3
0
def _lazyload_image(condition=None):
    def _load_image(action):
        increase_image_thread()
        try:
            #evt = action.run()
            evt = account_operations.execute_action_with_session(action, None)
        except:
            exc_info.append(sys.exc_info())
        finally:
            decrease_image_thread()

    iaction = api_actions.QueryImageAction()
    iaction.conditions = condition
    ret = account_operations.execute_action_with_session(iaction, None)

    if len(ret) != 0:
        print "no need lazy"
        return

    test_config_path = os.environ.get('WOODPECKER_TEST_CONFIG_FILE')
    test_config_obj = test_util.TestConfig(test_config_path)
    #Special config in test-config.xml, such like test ping target.
    test_config = test_config_obj.get_test_config()
    #All configs in deploy.xml.
    all_config = test_config_obj.get_deploy_config()
    #Detailed zstack deployment information, including zones/cluster/hosts...
    deploy_config = all_config.deployerConfig

    for i in xmlobject.safe_list(deploy_config.images.image):
        image_action = api_actions.QueryImageAction()
        condition = gen_query_conditions('name', '=', i.name_)
        image_action.conditions = condition
        ret = account_operations.execute_action_with_session(
            image_action, None)

        if len(ret) != 0:
            print "image has beed added"
            continue

        session_uuid = None
        if i.hasattr('label_') and i.label_ == 'lazyload':
            for bsref in xmlobject.safe_list(i.backupStorageRef):
                bss = get_resource(BACKUP_STORAGE, None, name=bsref.text_)
                bs = deploy_operations.get_first_item_from_list(
                    bss, 'backup storage', bsref.text_, 'image')
                action = api_actions.AddImageAction()
                action.sessionUuid = session_uuid
                #TODO: account uuid will be removed later.
                action.accountUuid = inventory.INITIAL_SYSTEM_ADMIN_UUID
                action.backupStorageUuids = [bs.uuid]
                action.bits = i.bits__
                if not action.bits:
                    action.bits = 64
                action.description = i.description__
                action.format = i.format_
                action.mediaType = i.mediaType_
                action.guestOsType = i.guestOsType__
                if not action.guestOsType:
                    action.guestOsType = 'unknown'
                action.platform = i.platform__
                if not action.platform:
                    action.platform = 'Linux'
                action.hypervisorType = i.hypervisorType__
                action.name = i.name_
                action.url = i.url_
                action.timeout = 1800000
                if i.hasattr('system_'):
                    action.system = i.system_
                if i.hasattr('systemTags_'):
                    action.systemTags = i.systemTags_.split(',')
                thread = threading.Thread(target=_load_image, args=(action, ))
                wait_for_image_thread_queue()
                print 'before add image2: %s' % i.url_
                thread.start()
                print 'add image: %s' % i.url_
    print 'all images add command are executed'
    wait_for_thread_done(True)
    print 'all images have been added'
Esempio n. 4
0
def _gen_query_action(resource, condition=None):
    if resource == BACKUP_STORAGE:
        action = api_actions.QueryBackupStorageAction()
    elif resource == SFTP_BACKUP_STORAGE:
        action = api_actions.QuerySftpBackupStorageAction()
    elif resource == CEPH_BACKUP_STORAGE:
        action = api_actions.QueryCephBackupStorageAction()
    elif resource == ZONE:
        action = api_actions.QueryZoneAction()
    elif resource == PRIMARY_STORAGE:
        action = api_actions.QueryPrimaryStorageAction()
    elif resource == L2_NETWORK:
        action = api_actions.QueryL2NetworkAction()
    elif resource == L2_VLAN_NETWORK:
        action = api_actions.QueryL2VlanNetworkAction()
    elif resource == L2_VXLAN_NETWORK:
        action = api_actions.QueryL2VxlanNetworkAction()
    elif resource == L2_VXLAN_NETWORK_POOL:
        action = api_actions.QueryL2VxlanNetworkPoolAction()
    elif resource == VNI_RANGE:
        action = api_actions.QueryVniRangeAction()
    elif resource == CLUSTER:
        action = api_actions.QueryClusterAction()
    elif resource == L3_NETWORK:
        action = api_actions.QueryL3NetworkAction()
    elif resource == INSTANCE_OFFERING:
        action = api_actions.QueryInstanceOfferingAction()
    elif resource == IMAGE:
        _lazyload_image(condition)
        action = api_actions.QueryImageAction()
    elif resource == VOLUME:
        action = api_actions.QueryVolumeAction()
    elif resource == SHARE_VOLUME:
        action = api_actions.QueryShareableVolumeVmInstanceRefAction()
    elif resource == VM_INSTANCE:
        action = api_actions.QueryVmInstanceAction()
    elif resource == IP_RANGE:
        action = api_actions.QueryIpRangeAction()
    elif resource == HOST:
        action = api_actions.QueryHostAction()
    elif resource == NETWORK_SERVICE_PROVIDER:
        action = api_actions.QueryNetworkServiceProviderAction()
    elif resource == NETWORK_SERVICE_PROVIDER_L3_REF:
        action = api_actions.QueryNetworkServiceL3NetworkRefAction()
    elif resource == APPLIANCE_VM:
        action = api_actions.QueryApplianceVmAction()
    elif resource == VIRTUALROUTER_VM:
        action = api_actions.QueryVirtualRouterVmAction()
    elif resource == DISK_OFFERING:
        action = api_actions.QueryDiskOfferingAction()
    elif resource == ACCOUNT:
        action = api_actions.QueryAccountAction()
    elif resource == CEPH_PRIMARY_STORAGE:
        action = api_actions.QueryCephPrimaryStorageAction()
    elif resource == CEPH_PRIMARY_STORAGE_POOL:
        action = api_actions.QueryCephPrimaryStoragePoolAction()
    elif resource == SECURITY_GROUP:
        action = api_actions.QuerySecurityGroupAction()
    elif resource == SECURITY_GROUP_RULE:
        action = api_actions.QuerySecurityGroupRuleAction()
    elif resource == VM_SECURITY_GROUP:
        action = api_actions.QueryVmNicInSecurityGroupAction()
    elif resource == VM_NIC:
        action = api_actions.QueryVmNicAction()
    elif resource == PORT_FORWARDING:
        action = api_actions.QueryPortForwardingRuleAction()
    elif resource == MANAGEMENT_NODE:
        action = api_actions.QueryManagementNodeAction()
    elif resource == EIP:
        action = api_actions.QueryEipAction()
    elif resource == VIP:
        action = api_actions.QueryVipAction()
    elif resource == VR_OFFERING:
        action = api_actions.QueryVirtualRouterOfferingAction()
    elif resource == SYSTEM_TAG:
        action = api_actions.QuerySystemTagAction()
    elif resource == USER_TAG:
        action = api_actions.QueryUserTagAction()
    elif resource == VOLUME_SNAPSHOT_TREE:
        action = api_actions.QueryVolumeSnapshotTreeAction()
    elif resource == VOLUME_SNAPSHOT:
        action = api_actions.QueryVolumeSnapshotAction()
    elif resource == USER:
        action = api_actions.QueryUserAction()
    elif resource == LOAD_BALANCER:
        action = api_actions.QueryLoadBalancerAction()
    elif resource == LOAD_BALANCER_LISTENER:
        action = api_actions.QueryLoadBalancerListenerAction()
    elif resource == LOCAL_STORAGE_RESOURCE_REF:
        action = api_actions.QueryLocalStorageResourceRefAction()
    elif resource == IMAGE_STORE_BACKUP_STORAGE:
        action = api_actions.QueryImageStoreBackupStorageAction()
    elif resource == SCHEDULER:
        action = api_actions.QuerySchedulerAction()
    elif resource == SCHEDULERJOB:
        action = api_actions.QuerySchedulerJobAction()
    elif resource == SCHEDULERTRIGGER:
        action = api_actions.QuerySchedulerTriggerAction()
    elif resource == VCENTER:
        action = api_actions.QueryVCenterAction()
    elif resource == VCENTER_CLUSTER:
        action = api_actions.QueryVCenterClusterAction()
    elif resource == VCENTER_BACKUP_STORAGE:
        action = api_actions.QueryVCenterBackupStorageAction()
    elif resource == VCENTER_PRIMARY_STORAGE:
        action = api_actions.QueryVCenterPrimaryStorageAction()
    elif resource == MONITOR_TRIGGER:
        action = api_actions.QueryMonitorTriggerAction()
    elif resource == MONITOR_TRIGGER_ACTION:
        action = api_actions.QueryMonitorTriggerActionAction()
    elif resource == PXE_SERVER:
        action = api_actions.QueryBaremetalPxeServerAction()
    elif resource == CHASSIS:
        action = api_actions.QueryBaremetalChassisAction()
    elif resource == HWINFO:
        action = api_actions.QueryBaremetalHardwareInfoAction()
    elif resource == BAREMETAL_INS:
        action = api_actions.QueryBaremetalInstanceAction()
    elif resource == LONGJOB:
        action = api_actions.QueryLongJobAction()
    elif resource == ALARM:
        action = api_actions.QueryAlarmAction()
    elif resource == EVENT_SUBSCRIPTION:
        action = api_actions.QueryEventSubscriptionAction()
    elif resource == SNS_APPLICATION_ENDPOINT:
        action = api_actions.QuerySNSApplicationEndpointAction()
    elif resource == SNS_APPLICATION_PLATFORM:
        action = api_actions.QuerySNSApplicationPlatformAction()
    elif resource == SNS_TOPIC:
        action = api_actions.QuerySNSTopicAction()
    elif resource == SNS_TOPIC_SUBSCRIBER:
        action = api_actions.QuerySNSTopicSubscriberAction()
    elif resource == SNS_DING_TALK_ENDPOINT:
        action = api_actions.QuerySNSDingTalkEndpointAction()
    elif resource == SNS_EMAIL_ENDPOINT:
        action = api_actions.QuerySNSEmailEndpointAction()
    elif resource == SNS_EMAIL_PLATFORM:
        action = api_actions.QuerySNSEmailPlatformAction()
    elif resource == SNS_HTTP_ENDPOINT:
        action = api_actions.QuerySNSHttpEndpointAction()
    elif resource == SNS_TEXT_TEMPLATE:
        action = api_actions.QuerySNSTextTemplateAction()
    elif resource == AFFINITY_GROUP:
        action = api_actions.QueryAffinityGroupAction()
    elif resource == IAM2_ORGANIZATION:
        action = api_actions.QueryIAM2OrganizationAction()
    elif resource == IAM2_PROJECT:
        action = api_actions.QueryIAM2ProjectAction()
    elif resource == IAM2_VIRTUAL_ID_GROUP:
        action = api_actions.QueryIAM2VirtualIDGroupAction()
    elif resource == IAM2_VIRTUAL_ID:
        action = api_actions.QueryIAM2VirtualIDAction()
    elif resource == IAM2_PROJECT_TEMPLATE:
        action = api_actions.QueryIAM2ProjectTemplateAction()
    elif resource == IAM2_VIRTUAL_ID_GROUP_ATTRIBUTE:
        action = api_actions.QueryIAM2VirtualIDGroupAttributeAction()
    elif resource == IAM2_VIRTUAL_ID_ATTRIBUTE:
        action = api_actions.QueryIAM2VirtualIDAttributeAction()
    elif resource == IAM2_PROJECT_ATTRIBUTE:
        action = api_actions.QueryIAM2ProjectAttributeAction()
    elif resource == IAM2_ORGANIZATION_ATTRIBUTE:
        action = api_actions.QueryIAM2OrganizationAttributeAction()
    elif resource == ROLE:
        action = api_actions.QueryRoleAction()
    elif resource == DATACENTER:
        action = api_actions.QueryDataCenterFromLocalAction()
    elif resource == ALIYUNNAS_ACCESSGROUP:
        action = api_actions.QueryAliyunNasAccessGroupAction()
    elif resource == NAS_FILESYSTEM:
        action = api_actions.QueryNasFileSystemAction()
    elif resource == NAS_MOUNTTARGET:
        action = api_actions.QueryNasMountTargetAction()
    elif resource == STACK_TEMPLATE:
        action = api_actions.QueryStackTemplateAction()
    elif resource == RESOURCE_STACK:
        action = api_actions.QueryResourceStackAction()
    elif resource == EVENT_FROM_STACK:
        action = api_actions.QueryEventFromResourceStackAction()
    elif resource == TICKET:
        action = api_actions.QueryTicketAction()
    elif resource == TICKET_HISTORY:
        action = api_actions.QueryTicketHistoryAction()
    elif resource == QUOTA:
        action = api_actions.QueryQuotaAction()
    elif resource == CERTIFICATE:
        action = api_actions.QueryCertificateAction()
    elif resource == VOLUME_BACKUP:
        action = api_actions.QueryVolumeBackupAction()
    elif resource == IPSEC_CONNECTION:
        action = api_actions.QueryIPSecConnectionAction()
    return action
Esempio n. 5
0
def _gen_query_action(resource, condition=None):
    if resource == BACKUP_STORAGE:
        action = api_actions.QueryBackupStorageAction()
    elif resource == SFTP_BACKUP_STORAGE:
        action = api_actions.QuerySftpBackupStorageAction()
    elif resource == CEPH_BACKUP_STORAGE:
        action = api_actions.QueryCephBackupStorageAction()
    elif resource == ZONE:
        action = api_actions.QueryZoneAction()
    elif resource == PRIMARY_STORAGE:
        action = api_actions.QueryPrimaryStorageAction()
    elif resource == L2_NETWORK:
        action = api_actions.QueryL2NetworkAction()
    elif resource == L2_VLAN_NETWORK:
        action = api_actions.QueryL2VlanNetworkAction()
    elif resource == L2_VXLAN_NETWORK:
        action = api_actions.QueryL2VxlanNetworkAction()
    elif resource == L2_VXLAN_NETWORK_POOL:
        action = api_actions.QueryL2VxlanNetworkPoolAction()
    elif resource == VNI_RANGE:
        action = api_actions.QueryVniRangeAction()
    elif resource == CLUSTER:
        action = api_actions.QueryClusterAction()
    elif resource == L3_NETWORK:
        action = api_actions.QueryL3NetworkAction()
    elif resource == INSTANCE_OFFERING:
        action = api_actions.QueryInstanceOfferingAction()
    elif resource == IMAGE:
        _lazyload_image(condition)
        action = api_actions.QueryImageAction()
    elif resource == VOLUME:
        action = api_actions.QueryVolumeAction()
    elif resource == SHARE_VOLUME:
        action = api_actions.QueryShareableVolumeVmInstanceRefAction()
    elif resource == VM_INSTANCE:
        action = api_actions.QueryVmInstanceAction()
    elif resource == IP_RANGE:
        action = api_actions.QueryIpRangeAction()
    elif resource == HOST:
        action = api_actions.QueryHostAction()
    elif resource == NETWORK_SERVICE_PROVIDER:
        action = api_actions.QueryNetworkServiceProviderAction()
    elif resource == NETWORK_SERVICE_PROVIDER_L3_REF:
        action = api_actions.QueryNetworkServiceL3NetworkRefAction()
    elif resource == APPLIANCE_VM:
        action = api_actions.QueryApplianceVmAction()
    elif resource == VIRTUALROUTER_VM:
        action = api_actions.QueryVirtualRouterVmAction()
    elif resource == DISK_OFFERING:
        action = api_actions.QueryDiskOfferingAction()
    elif resource == ACCOUNT:
        action = api_actions.QueryAccountAction()
    elif resource == CEPH_PRIMARY_STORAGE:
        action = api_actions.QueryCephPrimaryStorageAction()
    elif resource == CEPH_PRIMARY_STORAGE_POOL:
        action = api_actions.QueryCephPrimaryStoragePoolAction()
    elif resource == SECURITY_GROUP:
        action = api_actions.QuerySecurityGroupAction()
    elif resource == SECURITY_GROUP_RULE:
        action = api_actions.QuerySecurityGroupRuleAction()
    elif resource == VM_SECURITY_GROUP:
        action = api_actions.QueryVmNicInSecurityGroupAction()
    elif resource == VM_NIC:
        action = api_actions.QueryVmNicAction()
    elif resource == PORT_FORWARDING:
        action = api_actions.QueryPortForwardingRuleAction()
    elif resource == MANAGEMENT_NODE:
        action = api_actions.QueryManagementNodeAction()
    elif resource == EIP:
        action = api_actions.QueryEipAction()
    elif resource == VIP:
        action = api_actions.QueryVipAction()
    elif resource == VR_OFFERING:
        action = api_actions.QueryVirtualRouterOfferingAction()
    elif resource == SYSTEM_TAG:
        action = api_actions.QuerySystemTagAction()
    elif resource == USER_TAG:
        action = api_actions.QueryUserTagAction()
    elif resource == VOLUME_SNAPSHOT_TREE:
        action = api_actions.QueryVolumeSnapshotTreeAction()
    elif resource == VOLUME_SNAPSHOT:
        action = api_actions.QueryVolumeSnapshotAction()
    elif resource == USER:
        action = api_actions.QueryUserAction()
    elif resource == LOAD_BALANCER:
        action = api_actions.QueryLoadBalancerAction()
    elif resource == LOAD_BALANCER_LISTENER:
        action = api_actions.QueryLoadBalancerListenerAction()
    elif resource == LOCAL_STORAGE_RESOURCE_REF:
        action = api_actions.QueryLocalStorageResourceRefAction()
    elif resource == IMAGE_STORE_BACKUP_STORAGE:
        action = api_actions.QueryImageStoreBackupStorageAction()
    elif resource == SCHEDULER:
        action = api_actions.QuerySchedulerAction()
    elif resource == SCHEDULERJOB:
        action = api_actions.QuerySchedulerJobAction()
    elif resource == SCHEDULERTRIGGER:
        action = api_actions.QuerySchedulerTriggerAction()
    elif resource == VCENTER:
        action = api_actions.QueryVCenterAction()
    elif resource == VCENTER_CLUSTER:
        action = api_actions.QueryVCenterClusterAction()
    elif resource == VCENTER_BACKUP_STORAGE:
        action = api_actions.QueryVCenterBackupStorageAction()
    elif resource == VCENTER_PRIMARY_STORAGE:
        action = api_actions.QueryVCenterPrimaryStorageAction()
    elif resource == MONITOR_TRIGGER:
        action = api_actions.QueryMonitorTriggerAction()
    elif resource == MONITOR_TRIGGER_ACTION:
        action = api_actions.QueryMonitorTriggerActionAction()
    elif resource == PXE_SERVER:
        action = api_actions.QueryBaremetalPxeServerAction()
    elif resource == CHASSIS:
        action = api_actions.QueryBaremetalChassisAction()
    elif resource == HWINFO:
        action = api_actions.QueryBaremetalHardwareInfoAction()

    return action