'Add an iSCSI target to targetgroup.'

def add_to_targetgroup(self, iqn, targetgroup):

    svc = ('/api/san/v1/iscsi/target-groups/' + targetgroup)
    ret = self.rclient.get(svc)
    if (ret.status != restclient.Status.OK):
        svccrt = '/api/san/v1/iscsi/target-groups'
        arg = {'name': targetgroup, 'targets': [iqn]}
        ret = self.rclient.post(svccrt, arg)
        if (ret.status != restclient.Status.CREATED):
            exception_msg = (_('Error    Creating    TargetGroup:    %(targetgroup)s    withIQN:    %(iqn)sReturn    code:    %(ret.status)d    Message:    %(ret.data)s    .') % {'targetgroup': targetgroup, 'iqn': iqn, 'ret.status': ret.status, 'ret.data': ret.data})
            LOG.error(exception_msg)
            raise exception.VolumeBackendAPIException(data=exception_msg)
        return
    arg = {'targets': [iqn]}
    ret = self.rclient.put(svc, arg)
    if (ret.status != restclient.Status.ACCEPTED):
        exception_msg = (_('Error    Adding    to    TargetGroup:    %(targetgroup)s    withIQN:    %(iqn)sReturn    code:    %(ret.status)d    Message:    %(ret.data)s.') % {'targetgroup': targetgroup, 'iqn': iqn, 'ret.status': ret.status, 'ret.data': ret.data})
        LOG.error(exception_msg)
        raise exception.VolumeBackendAPIException(data=exception_msg)
