'''

All primary_storage operations for test.

@author: Youyk
'''

import apibinding.api_actions as api_actions
import zstackwoodpecker.test_util as test_util
import account_operations
import apibinding.inventory as inventory

def create_primary_storage(primary_storage_option, session_uuid=None):
    if primary_storage_option.type == inventory.CEPH_PRIMARY_STORAGE_TYPE:
        return create_ceph_primary_storage(primary_storage_option, session_uuid=None)
    return create_nfs_primary_storage(primary_storage_option, session_uuid=None)

def create_nfs_primary_storage(primary_storage_option, session_uuid=None):
    action = api_actions.AddNfsPrimaryStorageAction()
    action.timeout = 30000
    action.name = primary_storage_option.get_name()
    action.description = primary_storage_option.get_description()
    action.type = primary_storage_option.get_type()
    action.url = primary_storage_option.get_url()
    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 create_local_primary_storage(primary_storage_option, session_uuid=None):
    action = api_actions.AddLocalPrimaryStorageAction()
    action.timeout = 30000
    action.name = primary_storage_option.get_name()