Exemplo n.º 1
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/'}}
Exemplo n.º 2
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