示例#1
0
文件: utils.py 项目: zhen00fa/cinder
def get_datanode_id():

    dnid = None
    cmd_out = None
    cmd_err = None
    try:
        cmd_arg = {'operation': 'get_datanode_id'}
        # create a json for cmd argument
        cmdarg_json = json.dumps(cmd_arg)

        # call hscli for get_datanode_id
        (cmd_out, cmd_err) = hscli.hsexecute(cmdarg_json)

        # cmd_err should be None in case of successful execution of cmd
        if not cmd_err:
            processed_output = process_cmd_out(cmd_out)
            dnid = processed_output.get('payload')
        else:
            LOG.error("Error %s in getting datanode hypervisor id",
                      cmd_err)
            raise exception.UnableToExecuteHyperScaleCmd(
                command=cmdarg_json)
    except exception.UnableToExecuteHyperScaleCmd:
        with excutils.save_and_reraise_exception():
            LOG.debug("Unable to execute get_datanode_id", exc_info=True)

    except exception.UnableToProcessHyperScaleCmdOutput:
        with excutils.save_and_reraise_exception():
            LOG.debug("Unable to process get_datanode_id output",
                      exc_info=True)
    return dnid
示例#2
0
文件: utils.py 项目: zhen00fa/cinder
def get_hyperscale_version():

    version = None
    cmd_err = None
    try:
        cmd_arg = {'operation': 'version'}
        # create a json for cmd argument
        cmdarg_json = json.dumps(cmd_arg)

        # call hscli for version
        (cmd_out, cmd_err) = hscli.hsexecute(cmdarg_json)

        # cmd_err should be None in case of successful execution of cmd
        if not cmd_err:
            processed_output = process_cmd_out(cmd_out)
            version = processed_output.get('payload')
        else:
            LOG.error("Error %s in getting hyperscale version",
                      cmd_err)
            raise exception.ErrorInHyperScaleVersion(cmd_err=cmd_err)
    except (exception.UnableToExecuteHyperScaleCmd,
            exception.UnableToProcessHyperScaleCmdOutput):
        LOG.error("Exception in running the command for version",
                  exc_info=True)
        raise exception.UnableToExecuteHyperScaleCmd(command="version")

    return version
示例#3
0
文件: utils.py 项目: zhen00fa/cinder
def update_image(image_path, volume_id, hs_img_id):
    cmd_out = None
    cmd_err = None
    output = None
    try:
        cmd_arg = {}
        cmd_arg['operation'] = 'update_image'
        cmd_arg['image_path'] = image_path
        cmd_arg['volume_id'] = volume_id
        cmd_arg['hs_image_id'] = hs_img_id
        # create a json for cmd argument
        cmdarg_json = json.dumps(cmd_arg)

        (cmd_out, cmd_err) = hscli.hsexecute(cmdarg_json)

        # cmd_err should be None in case of successful execution of cmd
        if not cmd_err:
            output = process_cmd_out(cmd_out)
        else:
            LOG.error("Error %s in execution of update_image",
                      cmd_err)
            raise exception.UnableToExecuteHyperScaleCmd(
                command=cmdarg_json)
    except exception.UnableToExecuteHyperScaleCmd:
        with excutils.save_and_reraise_exception():
            LOG.debug("Unable to execute update_image", exc_info=True)

    except exception.UnableToProcessHyperScaleCmdOutput:
        with excutils.save_and_reraise_exception():
            LOG.debug("Unable to process update_image output",
                      exc_info=True)
    return output
示例#4
0
文件: utils.py 项目: zhen00fa/cinder
def episodic_snap(meta):

    cmd_out = None
    cmd_err = None
    out_meta = None
    try:
        cmd_arg = {}
        cmd_arg['operation'] = 'episodic_snap'
        cmd_arg['metadata'] = meta
        # create a json for cmd argument
        cmdarg_json = json.dumps(cmd_arg)

        # call hscli for episodic_snap
        (cmd_out, cmd_err) = hscli.hsexecute(cmdarg_json)

        # cmd_err should be None in case of successful execution of cmd
        if not cmd_err:
            processed_output = process_cmd_out(cmd_out)
            out_meta = processed_output.get('payload')
        else:
            LOG.error("Error %s in processing episodic_snap",
                      cmd_err)
            raise exception.UnableToExecuteHyperScaleCmd(
                command=cmdarg_json)
    except exception.UnableToExecuteHyperScaleCmd:
        with excutils.save_and_reraise_exception():
            LOG.debug("Unable to execute episodic_snap", exc_info=True)

    except exception.UnableToProcessHyperScaleCmdOutput:
        with excutils.save_and_reraise_exception():
            LOG.debug("Unable to process episodic_snap output",
                      exc_info=True)
    return out_meta
示例#5
0
def get_image_path(image_id, op_type='image'):

    cmd_out = None
    cmd_err = None
    image_path = None
    try:
        cmd_arg = {}
        if op_type == 'image':
            cmd_arg['operation'] = 'get_image_path'
        elif op_type == 'volume':
            cmd_arg['operation'] = 'get_volume_path'
        cmd_arg['image_id'] = image_id
        # create a json for cmd argument
        cmdarg_json = json.dumps(cmd_arg)

        # call hscli for get_image_path
        (cmd_out, cmd_err) = hscli.hsexecute(cmdarg_json)

        # cmd_err should be None in case of successful execution of cmd
        if not cmd_err:
            processed_output = process_cmd_out(cmd_out)
            image_path = processed_output.get('payload')
        else:
            LOG.error("Error %s in processing get_image_path", cmd_err)
            raise exception.UnableToExecuteHyperScaleCmd(command=cmdarg_json)
    except exception.UnableToExecuteHyperScaleCmd:
        with excutils.save_and_reraise_exception():
            LOG.debug("Unable to execute get_image_path", exc_info=True)

    except exception.UnableToProcessHyperScaleCmdOutput:
        with excutils.save_and_reraise_exception():
            LOG.debug("Unable to process get_image_path output", exc_info=True)
    return image_path
示例#6
0
 def test_create_volume_from_snapshot_with_exception(self, mock_mdp):
     """Test case create volume from snapshot thorws exception."""
     fake_volume, fake_snapshot = _stub_volume(), _stub_snapshot()
     mock_mdp.side_effect = v_exception.UnableToExecuteHyperScaleCmd(
         command='mock error')
     self.assertRaises(v_exception.UnableToExecuteHyperScaleCmd,
                       self.driver.create_volume_from_snapshot, fake_volume,
                       fake_snapshot)
示例#7
0
 def test_create_cloned_volume_with_exception(self, mock_mdp):
     """Test case throws exception when command failed to execute."""
     vol_a = _stub_volume()
     vol_b = _stub_volume()
     mock_mdp.side_effect = v_exception.UnableToExecuteHyperScaleCmd(
         command='mock error')
     self.assertRaises(v_exception.UnableToExecuteHyperScaleCmd,
                       self.driver.create_cloned_volume, vol_b, vol_a)
示例#8
0
 def test_create_snapshot_with_exception(self, mock_gvmv, mock_es,
                                         mock_mcp):
     """Test case create snapshot throws exception."""
     mock_gvmv.side_effect = VRTSHyperScaleDriverTestCase.gvmv_side_effect
     mock_es_obj = {'payload': {'update': False}}
     mock_es.return_value = mock_es_obj
     mock_mcp.side_effect = v_exception.UnableToExecuteHyperScaleCmd(
         command='mock error')
     fake_snapshot = _stub_snapshot()
     self.assertRaises(v_exception.UnableToExecuteHyperScaleCmd,
                       self.driver.create_snapshot, fake_snapshot)