CPD:使用restAPI和cpd-cli命令创建DMC实例

环境

  • Red Hat Enterprise Linux release 8.6 (Ootpa)
  • OCP 4.12.22
  • IBM CP4D 4.8.0
  • Data Management Console 3.1.12 (DMC for CPD 4.8.0)

注:使用了fyre VM。

创建DMC实例

准备

首先export环境变量:

. ./stg_env.sh

cpd-cli 放到PATH里。编辑 ~/.bashrc 文件,添加如下内容:

export PATH=~/cpd-cli-linux-EE-13.1.0-74:$PATH

然后:

. ~/.bashrc

确认已添加:

which cpd-cli
/root/cpd-cli-linux-EE-13.1.0-74/cpd-cli

log in OCP和CPD:

oc login https://$(hostname):6443 -u kubeadmin -p $(cat /root/auth/kubeadmin-password)

cpd-cli manage login-to-ocp -u kubeadmin -p $(cat /root/auth/kubeadmin-password) --server=https://$(hostname):6443

方法1:从UI创建

略。

方法2:使用restAPI创建

设置环境变量:

export INSTANCE_NAME=data-management-console

export INSTANCE_DESCRIPTION="IBM Db2 Data Management Console"

export STORAGE_SIZE=10

export INSTANCE_SIZE=small

export PROJECT_CPD_INST_OPERANDS=cpd-instance

export VERSION=4.8.0

export STG_CLASS_FILE=nfs-client

export CPD_ROUTE=$(oc get route cpd -n ${PROJECT_CPD_INST_OPERANDS} -o jsonpath={".spec.host"})

创建文件 data-management-console-instance.json

cat << EOF > ./data-management-console-instance.json
{
    "addon_type":"dmc",
    "display_name":"${INSTANCE_NAME}",
    "description":"${INSTANCE_DESCRIPTION}",
    "namespace":"${PROJECT_CPD_INST_OPERANDS}",
    "addon_version": "${VERSION}",
    "parameters":{
        "storageClass":"${STG_CLASS_FILE}",
        "storageSize":"${STORAGE_SIZE}Gi"
    },
    "create_arguments":{
        "metadata":{
            "storageClass":"${STG_CLASS_FILE}",
            "storageSize":"${STORAGE_SIZE}Gi",
            "scaleConfig":"${INSTANCE_SIZE}"
        }
    },
    "pre_existing_owner":false
}
EOF

创建完成后,检查一下文件内容:

{
    "addon_type":"dmc",
    "display_name":"data-management-console",
    "description":"IBM Db2 Data Management Console",
    "namespace":"cpd-instance",
    "addon_version": "4.8.0",
    "parameters":{
        "storageClass":"nfs-client",
        "storageSize":"10Gi"
    },
    "create_arguments":{
        "metadata":{
            "storageClass":"nfs-client",
            "storageSize":"10Gi",
            "scaleConfig":"small"
        }
    },
    "pre_existing_owner":false
}

设置环境变量:

export PAYLOAD_FILE=data-management-console-instance.json

接下来要用到Zen API key。

先要获取API key。在UI右上角,点击“Profile and settings”:

CPD:使用restAPI和cpd-cli命令创建DMC实例_第1张图片

点击“API key -> Generate new key”:

CPD:使用restAPI和cpd-cli命令创建DMC实例_第2张图片

点击“Generate”:

CPD:使用restAPI和cpd-cli命令创建DMC实例_第3张图片

点击“Copy”,把API key保存到某个地方(如果丢失,无法找回,只能重新生成一个新key)。

例如,获取的API key为: KIXAyDVUZvNhjca4oR3eApYk10kJdzsmKwZ33bG1

现在,要通过API key生成ZenApiKey,方法为:

echo ":" | base64

例如:

echo "cpadmin:KIXAyDVUZvNhjca4oR3eApYk10kJdzsmKwZ33bG1" | base64

生成的ZenApiKey为: Y3BhZG1pbjpLSVhBeURWVVp2TmhqY2E0b1IzZUFwWWsxMGtKZHpzbUt3WjMzYkcxCg==

设置环境变量:

export API_KEY=KIXAyDVUZvNhjca4oR3eApYk10kJdzsmKwZ33bG1

export ZenApiKey=Y3BhZG1pbjpLSVhBeURWVVp2TmhqY2E0b1IzZUFwWWsxMGtKZHpzbUt3WjMzYkcxCg==

接下来,就可以创建DMC实例了:

curl -k --request POST \
--url "https://${CPD_ROUTE}/zen-data/v3/service_instances" \
--header "Authorization: ZenApiKey ${ZenApiKey}" \
--header 'Content-Type: application/json' \
--data @${PAYLOAD_FILE}

注意使用的是ZenApiKey。

返回结果是新创建实例的ID,例如:

{"id":"1699866419910616"}

等DMC实例创建好。

检查实例:

curl -k --request GET \
--url "https://${CPD_ROUTE}/zen-data/v3/service_instances/1699866419910616" \
--header "Authorization: ZenApiKey ${ZenApiKey}" \
--header 'Content-Type: application/json' | jq .

例如,结果为:

{
  "service_instance": {
    "addon_type": "dmc",
    "addon_version": "4.8.0",
    "connection_info": {
      "external_url": "$HOST/v1/external"
    },
    "created_at": "2023-11-13T04:55:40.271977Z",
    "description": "Data Management Console",
    "display_name": "data-management-console",
    "id": "1699851327823720",
    "instance_identifiers": null,
    "metadata": {
      "storageClass": "nfs-client",
      "storageSize": "10Gi"
    },
    "misc_data": {},
    "namespace": "cpd-instance",
    "owner_uid": "1000331001",
    "owner_username": "cpadmin",
    "parameters": {},
    "provision_status": "PROVISIONED",
    "resources": {
      "cpu": "4.20",
      "memory": "10.43 Gi"
    },
    "roles": [
      "Admin"
    ],
    "updated_at": "2023-11-13T06:50:03.486676Z",
    "zen_service_instance_info": {
      "docker_registry_prefix": "icr.io/cpopen/cpfs"
    }
  }
}

方法3:使用cpd-cli命令创建

同样需要设置环境变量,以及创建文件 data-management-console-instance.json ,参见上面的描述。

不同之处在于,需要设置一个profile参数。

设置环境变量:

export CPD_ADMIN_USER=cpadmin

export CPD_PROFILE_NAME=cpd-admin-profile

# 也可以用前面的 ${CPD_ROUTE} 变量
export CPD_PROFILE_URL=https://cpd-cpd-instance.apps.o1-370456.cp.fyre.ibm.com

export LOCAL_USER=cpadmin

# 注意这里是API key,不要跟前面的ZenApiKey弄混了
cpd-cli config users set ${LOCAL_USER} --username ${CPD_ADMIN_USER} --apikey ${API_KEY}

cpd-cli config profiles set ${CPD_PROFILE_NAME} \
--user ${LOCAL_USER} \
--url ${CPD_PROFILE_URL}

创建好profile之后,可以list一下实例:

cpd-cli service-instance --profile ${CPD_PROFILE_NAME} list

结果如下:

 Namespace           Service type        Version             ID                  Name                      Provision status    Upgrade version option
 ---------           ------------        -------             --                  ----                      ----------------    ----------------------
 cpd-instance        dmc                 4.8.0               1699866419910616    data-management-console   PROVISIONED         []

为了测试创建,先把DMC实例删掉。

然后再创建DMC实例:

cpd-cli service-instance create \
--profile=${CPD_PROFILE_NAME} \
--from-source=${PAYLOAD_FILE}

运行成功,没有返回结果。

等DMC实例创建好。

检查实例:

cpd-cli service-instance status ${INSTANCE_NAME} \
--profile=${CPD_PROFILE_NAME} \
--output=json

结果如下:

{
  "service_instance": {
    "display_name": "data-management-console",
    "id": "1699869169988950",
    "service_type": "dmc",
    "service_version": "4.8.0",
    "namespace": "cpd-instance",
    "provision_status": "PROVISIONED",
    "service_status": "RUNNING"
  }
}

参考

  • https://ibmdocs-test.dcs.ibm.com/docs/en/SSQNUZ_4.8_test?topic=pis-creating-service-instance-6
  • https://ibmdocs-test.dcs.ibm.com/docs/en/SSQNUZ_4.8_test?topic=sirio-service-instance-creation-cpd-cli-service-instance-create#payload__dmc__title__1
  • https://ibmdocs-test.dcs.ibm.com/docs/en/SSQNUZ_4.8_test?topic=only-service-instance-creation-rest-api
  • https://www.ibm.com/docs/en/cloud-paks/cp-data/4.7.x?topic=interface-creating-cpd-cli-profile

注:CPD 4.8还没有release,这是draft doc,如果是正式doc,应该是 https://www.ibm.com/docs/en/cloud-paks/cp-data/4.8.x?topic=xxxxx

你可能感兴趣的:(openshift,openshift)