示例#1
0
 def test_DirectoryRequest_get(self):
     domain = 'default'
     dir_path = 'local/dir/subdir/'
     req = DirectoryRequest()
     req.set_body(dir_path=dir_path)
     req.set_path(domain=domain, dir_path=dir_path)
     assert req.get()['path'] == '/mgmt/filestore/default/local/dir/subdir'
     assert req.get()['method'] == 'GET'
     assert not req.get()['data']
示例#2
0
 def test_DirectoryRequest_create(self):
     domain = 'default'
     dir_path = 'local/dir/subdir/'
     req = DirectoryRequest()
     req.set_body(dir_path=dir_path)
     req.set_path(domain=domain, dir_path=dir_path)
     assert req.post()['path'] == '/mgmt/filestore/default/local'
     assert req.post()['method'] == 'POST'
     assert req.post()['data'] == {'directory': {'name': 'dir/subdir/'}}
示例#3
0
def list_directory(module, domain, dir_path):
    connection = Connection(module._socket_path)
    dir_req = DirectoryRequest()
    dir_req.set_path(domain=domain, dir_path=dir_path)

    dir_resp = connection.get_resource_or_none(dir_req.path)
    if dir_resp is None:
        return []
    data = dir_resp['filestore']['location']
    if 'file' in data and isinstance(data['file'], dict):
        return [data['file']]
    elif 'file' in data and isinstance(data['file'], list):
        return data['file']
    else:
        return []
示例#4
0
 def test_DirectoryRequest_update(self):
     domain = 'default'
     dir_path = 'local/dir/subdir/'
     req = DirectoryRequest()
     req.set_body(dir_path=dir_path)
     req.set_path(domain=domain, dir_path=dir_path)
     try:
         req.put()
         assert False
     except Exception:  # Put not implemented
         assert True
示例#5
0
    def test_DirectoryRequest__init__(self):
        domain = 'default'
        dir_path = 'local/dir/subdir/'

        req = DirectoryRequest()
        req.set_body(dir_path=dir_path)
        req.set_path(domain=domain, dir_path=dir_path)

        assert req
        assert req.path == '/mgmt/filestore/default/local/dir/subdir'
        assert req.body == {'directory': {'name': 'dir/subdir/'}}
示例#6
0
def ensure_directory(module, domain, dir_path, state='present'):
    # Directory is a top_dir, nothing to ensure.
    diff = None
    result = {}
    result['changed'] = False

    if len(dir_path.split('/')) == 1:
        result = {}
        result['path'] = dir_path
        result['diff'] = {}
        return result

    connection = Connection(module._socket_path)
    dir_req = DirectoryRequest()
    dir_req.set_body(dir_path=dir_path)
    dir_req.set_path(domain=domain, dir_path=dir_path)
    dir_state = connection.get_resource_or_none(dir_req.path)

    if dir_state and state == 'present':
        result['path'] = dir_path
        diff = {}
        result['response'] = None
    elif dir_state is None and state == 'present':
        if not module.check_mode:
            resp = connection.send_request(**dir_req.post())
            result['response'] = resp
        result['changed'] = True
        diff = {'before': None, 'after': dir_path}
        result['path'] = dir_path
    elif dir_state and state == 'absent':
        if not module.check_mode:
            resp = connection.send_request(**dir_req.delete())
            result['response'] = resp
        diff = {'before': dir_path, 'after': None}
        result['changed'] = True
    elif dir_state is None and state == 'absent':
        diff = {'before': None, 'after': None}
        result['response'] = None

    if module._diff:
        result['diff'] = diff
    return result