Example #1
0
def importVolume(host, port, source, path, container, volcnt, isroot=False):
    clientUrl = EXPORT_FS.substitute(HOST=host, PORT=port)
    headers = {"content-type": "application/json"}
    payload = dict()
    payload["role"] = "target"
    payload["opcode"] = "IMPORT_FS"
    params = dict()
    params["sourceHost"] = source
    params["exportPath"] = path
    params["container"] = container
    params["volcnt"] = volcnt
    params["isroot"] = isroot
    payload["params"] = params

    rc = codes.SUCCESS
    try:
        resp = requests.post(clientUrl,
                             data=json.dumps(payload),
                             headers=headers)
    except requests.exceptions.ConnectionError as e:
        logging.error("Can not connect to cargo agent at: {}".format(host))
        rc = codes.FAILED
    else:
        rc = resp.status_code

    return codes.perror(rc)
Example #2
0
def startLazycopy(host, port, container, volume, volcnt, srchost):
    md5 = hashlib.md5()
    md5.update(volume)
    volumeId = md5.hexdigest()

    clientUrl = LAZY_COPY.substitute(HOST=host,
                                     PORT=port,
                                     CONTAINER=container,
                                     VOLUME=volumeId)
    headers = {"content-type": "application/json"}
    payload = dict()
    payload["srchost"] = srchost
    payload["volcnt"] = volcnt
    payload["volume"] = volume

    rc = codes.SUCCESS
    try:
        resp = requests.post(clientUrl,
                             data=json.dumps(payload),
                             headers=headers)
    except requests.exceptions.ConnectionError as e:
        logging.error("Can not connect to cargo agent at: {}".format(agent))
        rc = codes.FAILED
    else:
        rc = resp.status_code

    return codes.perror(rc)
Example #3
0
def failover(host, port, container):
    clientUrl = FAILOVER_CONTAINER.substitute(HOST = host, PORT = port, CONTAINER = container)
    rc = codes.SUCCESS  # TODO: This is not used
    try:
        resp = requests.post(clientUrl, headers=HEADERS)
    except requests.exceptions.ConnectionError as e:
        logging.error(ERR_FMT.format(e, agent))  # should this be host instead of agent?
        rc = codes.FAILED
    else:
        rc = resp.status_code
    return codes.perror(rc)
Example #4
0
def stopLazyCopy(host, port, container, volume): 
    volumeId = hashlib.md5(volume).hexdigest()
    clientUrl = LAZY_COPY.substitute(HOST = host, PORT = port, CONTAINER = container, VOLUME = volumeId)
    rc = codes.SUCCESS  # TODO: This is not used
    try:
        resp = requests.delete(clientUrl, headers=HEADERS)
    except requests.exceptions.ConnectionError as e:
        logging.error(ERR_FMT.format(e, agent))  # should this be host instead of agent?
        rc = codes.FAILED
    else:
        rc = resp.status_code
    return codes.perror(rc)
Example #5
0
def exportVolume(host, port, exportpath):
    clientUrl = EXPORT_FS.substitute(HOST = host, PORT = port)
    params = {"exportPath": exportpath}
    payload = {"role": "source", "opcode": "EXPORT_FS", "params": params}
    rc = codes.SUCCESS  # TODO: This is not used
    try:
        resp = requests.post(clientUrl, data=json.dumps(payload), headers=HEADERS)
    except requests.exceptions.ConnectionError as e:
        logging.error(ERR_FMT.format(e, host))
        rc = codes.FAILED
    else:
        rc = resp.status_code
    return codes.perror(rc)    
Example #6
0
def startLazycopy(host, port, container, volume, volcnt, srchost):
    volumeId = hashlib.md5(volume).hexdigest()
    clientUrl = LAZY_COPY.substitute(HOST = host, PORT = port, CONTAINER = container, VOLUME = volumeId)
    payload = {"srchost": srchost, "volcnt": volcnt, "volume": volume}
    rc = codes.SUCCESS  # TODO: This is not used
    try:
        resp = requests.post(clientUrl, data=json.dumps(payload), headers=HEADERS)
    except requests.exceptions.ConnectionError as e:
        logging.error(ERR_FMT.format(e, agent))  # should this be host instead of agent?
        rc = codes.FAILED
    else:
        rc = resp.status_code
    return codes.perror(rc)
Example #7
0
def nfsImportVolume(host, port, nfsMeta, volume):
    clientUrl = EXPORT_FS.substitute(HOST = host, PORT = port)
    params = {"nfsmeta": nfsMeta, "volume": volume}
    payload = {"role": "target", "opcode": "IMPORT_NFS", "params": params}
    rc = codes.SUCCESS  # TODO: This is not used
    try:
        resp = requests.post(clientUrl, data=json.dumps(payload), headers=HEADERS)
    except requests.exceptions.ConnectionError as e:
        logging.error(ERR_FMT.format(e, host))
        rc = codes.FAILED
    else:
        rc = resp.status_code
    return codes.perror(rc)    
Example #8
0
def failover(host, port, container):
    clientUrl = FAILOVER_CONTAINER.substitute(HOST = host, PORT = port, CONTAINER = container)
    headers = {"content-type": "application/json"}
    payload = dict()
    rc = codes.SUCCESS
    try:
        resp = requests.post(clientUrl, data=json.dumps(payload), headers=headers)
    except requests.exceptions.ConnectionError as e:
        logging.error("Can not connect to cargo agent at: {}".format(agent))
        rc = codes.FAILED
    else:
        rc = resp.status_code

    return codes.perror(rc)
Example #9
0
def stopContainer(host, port, name):
    if name.startswith("/"):
        name = name.split("/")[1]
    clientUrl = OPERATE_CONTAINER.substitute(HOST = host, PORT = port, NAME = name)
    payload = {"opcode": "stop"}
    rc = codes.SUCCESS  # TODO: This is not used
    try:
        resp = requests.post(clientUrl, data=json.dumps(payload), headers=HEADERS)
    except requests.exceptions.ConnectionError as e:
        logging.error(ERR_FMT.format(e, host))
        rc = codes.FAILED
    else:
        rc = resp.status_code
    return codes.perror(rc)
Example #10
0
def failover(host, port, container):
    clientUrl = FAILOVER_CONTAINER.substitute(HOST=host,
                                              PORT=port,
                                              CONTAINER=container)
    rc = codes.SUCCESS  # TODO: This is not used
    try:
        resp = requests.post(clientUrl, headers=HEADERS)
    except requests.exceptions.ConnectionError as e:
        logging.error(ERR_FMT.format(
            e, agent))  # should this be host instead of agent?
        rc = codes.FAILED
    else:
        rc = resp.status_code
    return codes.perror(rc)
Example #11
0
def exportVolume(host, port, exportpath):
    clientUrl = EXPORT_FS.substitute(HOST=host, PORT=port)
    params = {"exportPath": exportpath}
    payload = {"role": "source", "opcode": "EXPORT_FS", "params": params}
    rc = codes.SUCCESS  # TODO: This is not used
    try:
        resp = requests.post(clientUrl,
                             data=json.dumps(payload),
                             headers=HEADERS)
    except requests.exceptions.ConnectionError as e:
        logging.error(ERR_FMT.format(e, host))
        rc = codes.FAILED
    else:
        rc = resp.status_code
    return codes.perror(rc)
Example #12
0
def nfsImportVolume(host, port, nfsMeta, volume):
    clientUrl = EXPORT_FS.substitute(HOST=host, PORT=port)
    params = {"nfsmeta": nfsMeta, "volume": volume}
    payload = {"role": "target", "opcode": "IMPORT_NFS", "params": params}
    rc = codes.SUCCESS  # TODO: This is not used
    try:
        resp = requests.post(clientUrl,
                             data=json.dumps(payload),
                             headers=HEADERS)
    except requests.exceptions.ConnectionError as e:
        logging.error(ERR_FMT.format(e, host))
        rc = codes.FAILED
    else:
        rc = resp.status_code
    return codes.perror(rc)
Example #13
0
def importVolume(host, port, source, path, container, volcnt, isroot = False):
    clientUrl = EXPORT_FS.substitute(HOST = host, PORT = port)
    params = {"sourceHost": source, "exportPath": path, "container": container,
              "volcnt": volcnt, "isroot": isroot}
    payload = {"role": "target", "opcode": "IMPORT_FS", "params": params}

    rc = codes.SUCCESS  # TODO: This is not used
    try:
        resp = requests.post(clientUrl, data=json.dumps(payload), headers=HEADERS)
    except requests.exceptions.ConnectionError as e:
        logging.error(ERR_FMT.format(e, host))
        rc = codes.FAILED
    else:
        rc = resp.status_code
                
    return codes.perror(rc)    
Example #14
0
def stopLazyCopy(host, port, container, volume):
    volumeId = hashlib.md5(volume).hexdigest()
    clientUrl = LAZY_COPY.substitute(HOST=host,
                                     PORT=port,
                                     CONTAINER=container,
                                     VOLUME=volumeId)
    rc = codes.SUCCESS  # TODO: This is not used
    try:
        resp = requests.delete(clientUrl, headers=HEADERS)
    except requests.exceptions.ConnectionError as e:
        logging.error(ERR_FMT.format(
            e, agent))  # should this be host instead of agent?
        rc = codes.FAILED
    else:
        rc = resp.status_code
    return codes.perror(rc)
Example #15
0
def stopContainer(host, port, name):
    if name.startswith("/"):
        name = name.split("/")[1]
    clientUrl = OPERATE_CONTAINER.substitute(HOST=host, PORT=port, NAME=name)
    payload = {"opcode": "stop"}
    rc = codes.SUCCESS  # TODO: This is not used
    try:
        resp = requests.post(clientUrl,
                             data=json.dumps(payload),
                             headers=HEADERS)
    except requests.exceptions.ConnectionError as e:
        logging.error(ERR_FMT.format(e, host))
        rc = codes.FAILED
    else:
        rc = resp.status_code
    return codes.perror(rc)
Example #16
0
def stopLazyCopy(host, port, container, volume): 
    md5=hashlib.md5()
    md5.update(volume)
    volumeId = md5.hexdigest()
    clientUrl = LAZY_COPY.substitute(HOST = host, PORT = port, CONTAINER = container, VOLUME = volumeId)
    headers = {"content-type": "application/json"}
    payload = dict()
    rc = codes.SUCCESS
    try:
        resp = requests.delete(clientUrl, data=json.dumps(payload), headers=headers)
    except requests.exceptions.ConnectionError as e:
        logging.error("Can not connect to cargo agent at: {}".format(agent))
        rc = codes.FAILED
    else:
        rc = resp.status_code

    return codes.perror(rc)
Example #17
0
def stopContainer(host, port, name):
    payload = dict()
    payload["opcode"] = "stop"
    if name.startswith("/"):
        name = name.split("/")[1]
    headers = {"content-type": "application/json"}

    clientUrl = OPERATE_CONTAINER.substitute(HOST = host, PORT = port, NAME = name)
    rc = codes.SUCCESS
    try:
        resp = requests.post(clientUrl, data=json.dumps(payload), headers=headers)
    except requests.exceptions.ConnectionError as e:
        logging.error("Can not connect to cargo agent at: {}".format(host))
        rc = codes.FAILED
    else:
        rc = resp.status_code

    return codes.perror(rc)
Example #18
0
def failover(host, port, container):
    clientUrl = FAILOVER_CONTAINER.substitute(HOST=host,
                                              PORT=port,
                                              CONTAINER=container)
    headers = {"content-type": "application/json"}
    payload = dict()
    rc = codes.SUCCESS
    try:
        resp = requests.post(clientUrl,
                             data=json.dumps(payload),
                             headers=headers)
    except requests.exceptions.ConnectionError as e:
        logging.error("Can not connect to cargo agent at: {}".format(agent))
        rc = codes.FAILED
    else:
        rc = resp.status_code

    return codes.perror(rc)
Example #19
0
def startLazycopy(host, port, container, volume, volcnt, srchost):
    volumeId = hashlib.md5(volume).hexdigest()
    clientUrl = LAZY_COPY.substitute(HOST=host,
                                     PORT=port,
                                     CONTAINER=container,
                                     VOLUME=volumeId)
    payload = {"srchost": srchost, "volcnt": volcnt, "volume": volume}
    rc = codes.SUCCESS  # TODO: This is not used
    try:
        resp = requests.post(clientUrl,
                             data=json.dumps(payload),
                             headers=HEADERS)
    except requests.exceptions.ConnectionError as e:
        logging.error(ERR_FMT.format(
            e, agent))  # should this be host instead of agent?
        rc = codes.FAILED
    else:
        rc = resp.status_code
    return codes.perror(rc)
Example #20
0
def nfsImportVolume(host, port, nfsMeta, volume):
    clientUrl = EXPORT_FS.substitute(HOST = host, PORT = port)
    headers = {"content-type": "application/json"}
    payload = dict()
    payload["role"] = "target"
    payload["opcode"] = "IMPORT_NFS"
    params = dict()
    params["nfsmeta"] = nfsMeta
    params["volume"] = volume
    payload["params"] = params
    rc = codes.SUCCESS
    try:
        resp = requests.post(clientUrl, data=json.dumps(payload), headers=headers)
    except requests.exceptions.ConnectionError as e:
        logging.error("Can not connect to cargo agent at: {}".format(host))
        rc = codes.FAILED
    else:
        rc = resp.status_code
                
    return codes.perror(rc)    
Example #21
0
def exportVolume(host, port, exportpath):
    clientUrl = EXPORT_FS.substitute(HOST = host, PORT = port)
    headers = {"content-type": "application/json"}
    payload = dict()
    payload["role"] = "source"
    payload["opcode"] = "EXPORT_FS"
    params = dict()
    params["exportPath"] = exportpath
    payload["params"] = params

    rc = codes.SUCCESS
    try:
        resp = requests.post(clientUrl, data=json.dumps(payload), headers=headers)
    except requests.exceptions.ConnectionError as e:
        logging.error("Can not connect to cargo agent at: {}".format(host))
        rc = codes.FAILED
    else:
        rc = resp.status_code

    return codes.perror(rc)    
Example #22
0
def stopContainer(host, port, name):
    payload = dict()
    payload["opcode"] = "stop"
    if name.startswith("/"):
        name = name.split("/")[1]
    headers = {"content-type": "application/json"}

    clientUrl = OPERATE_CONTAINER.substitute(HOST=host, PORT=port, NAME=name)
    rc = codes.SUCCESS
    try:
        resp = requests.post(clientUrl,
                             data=json.dumps(payload),
                             headers=headers)
    except requests.exceptions.ConnectionError as e:
        logging.error("Can not connect to cargo agent at: {}".format(host))
        rc = codes.FAILED
    else:
        rc = resp.status_code

    return codes.perror(rc)
Example #23
0
def exportVolume(host, port, exportpath):
    clientUrl = EXPORT_FS.substitute(HOST=host, PORT=port)
    headers = {"content-type": "application/json"}
    payload = dict()
    payload["role"] = "source"
    payload["opcode"] = "EXPORT_FS"
    params = dict()
    params["exportPath"] = exportpath
    payload["params"] = params

    rc = codes.SUCCESS
    try:
        resp = requests.post(clientUrl,
                             data=json.dumps(payload),
                             headers=headers)
    except requests.exceptions.ConnectionError as e:
        logging.error("Can not connect to cargo agent at: {}".format(host))
        rc = codes.FAILED
    else:
        rc = resp.status_code

    return codes.perror(rc)
Example #24
0
def nfsImportVolume(host, port, nfsMeta, volume):
    clientUrl = EXPORT_FS.substitute(HOST=host, PORT=port)
    headers = {"content-type": "application/json"}
    payload = dict()
    payload["role"] = "target"
    payload["opcode"] = "IMPORT_NFS"
    params = dict()
    params["nfsmeta"] = nfsMeta
    params["volume"] = volume
    payload["params"] = params
    rc = codes.SUCCESS
    try:
        resp = requests.post(clientUrl,
                             data=json.dumps(payload),
                             headers=headers)
    except requests.exceptions.ConnectionError as e:
        logging.error("Can not connect to cargo agent at: {}".format(host))
        rc = codes.FAILED
    else:
        rc = resp.status_code

    return codes.perror(rc)
Example #25
0
def importVolume(host, port, source, path, container, volcnt, isroot=False):
    clientUrl = EXPORT_FS.substitute(HOST=host, PORT=port)
    params = {
        "sourceHost": source,
        "exportPath": path,
        "container": container,
        "volcnt": volcnt,
        "isroot": isroot
    }
    payload = {"role": "target", "opcode": "IMPORT_FS", "params": params}

    rc = codes.SUCCESS  # TODO: This is not used
    try:
        resp = requests.post(clientUrl,
                             data=json.dumps(payload),
                             headers=HEADERS)
    except requests.exceptions.ConnectionError as e:
        logging.error(ERR_FMT.format(e, host))
        rc = codes.FAILED
    else:
        rc = resp.status_code

    return codes.perror(rc)
Example #26
0
def importVolume(host, port, source, path, container, volcnt, isroot = False):
    clientUrl = EXPORT_FS.substitute(HOST = host, PORT = port)
    headers = {"content-type": "application/json"}
    payload = dict()
    payload["role"] = "target"
    payload["opcode"] = "IMPORT_FS"
    params = dict()
    params["sourceHost"] = source
    params["exportPath"] = path
    params["container"] = container
    params["volcnt"] = volcnt
    params["isroot"] = isroot
    payload["params"] = params

    rc = codes.SUCCESS
    try:
        resp = requests.post(clientUrl, data=json.dumps(payload), headers=headers)
    except requests.exceptions.ConnectionError as e:
        logging.error("Can not connect to cargo agent at: {}".format(host))
        rc = codes.FAILED
    else:
        rc = resp.status_code
                
    return codes.perror(rc)