NTNX>日記

個人的な趣味による Nutanix Community Edition 日記。Japanese のみですみません。

Nutanix Volumes VG の Description を取得してみる。(curl)

Nutanix CSI Driver で作成された Nutanix Volumes の Volume Group(VG)は、なんらかの事情により削除されずに残ることがあります。なんとか整理するために、VG が関連する Kubernetes の情報を取得してみます。

Nutanix CSI Driver による VG

Nutanix CSI Driver によって作成された VG は、下記のようになっています。

  • VG の名前:pvc-<UUID>
  • Desctiption:Kubernetes リソースの情報が記載される。

Volume Group 画面では、VG の名前が一覧表示されます。しかし、Desctiption は表示されていません。

VG の Update 画面を開くと、Desctiption が表示されます。そこで REST API で、VG の Desctiption を取得してみます。

REST API v2 での VG 情報取得

今回は、Linux(RHEL 8)の curl コマンドで Prism Element に接続して、REST API v2 の下記のメソッドで情報取得してみます。

  • GET /volume_groups

Prism Element の認証情報を変数に格納しておきます。

$ PRISM=lab-nxce-02.go-lab.jp
$ USER=admin
$ PASS='パスワード'

下記のように、curl で API をコールします。取得した JSON データは、jq コマンドで整形しています。

curl -X GET -k -s \
-u "$USER:$PASS" \
-H "Accept: application/json" \
--url "https://$PRISM:9440/PrismGateway/services/rest/v2.0/volume_groups" | \
jq -r .

実行すると、下記のように VG 情報を取得できます。

$ curl -X GET -k -s \
> -u "$USER:$PASS" \
> -H "Accept: application/json" \
> --url "https://$PRISM:9440/PrismGateway/services/rest/v2.0/volume_groups" | \
> jq -r .
{
  "metadata": {
    "grand_total_entities": 6,
    "total_entities": 0,
    "count": 6
  },
  "entities": [
    {
      "uuid": "00144e7f-07c2-4544-6493-66ac8cbda9b2",
      "name": "pvc-f115e944-6d2b-41f2-8ce4-2e6e7dd98fc2",
      "description": "FS:ext4, CSI StorageClass nutanix-volume for nkpm01, PVC:git-operator-git-volume, NS:git-operator-system, POD:git-operator-git-0, SA:default",
      "logical_timestamp": 6,
      "disk_list": [
        {
          "index": 0,
          "vmdisk_uuid": "015bb10d-0cfc-475a-8458-fffb1dcafb28",
          "container_id": 4,
          "storage_container_id": 4,
          "container_uuid": "0a6d6d1a-b52f-4998-903d-fcf9af00885a",
          "storage_container_uuid": "0a6d6d1a-b52f-4998-903d-fcf9af00885a",
          "vmdisk_size_mb": 10240,
          "vmdisk_size_bytes": 10737418240,
          "vmdisk_path": "/default-container-57560544335892/.stargate/castor/vgdisk/015bb10d-0cfc-475a-8458-fffb1dcafb28",
          "flash_mode_enabled": false
        }
      ],
      "iscsi_target": "ntnx-k8s-00144e7f-07c2-4544-6493-66ac8cbda9b2",
      "flash_mode_enabled": false,
      "load_balance_vm_attachments": true,
      "is_shared": false
    },
    {
      "uuid": "f5c83859-0fc4-4d4d-51af-5d9f729c56c6",
      "name": "pvc-70ba1c1e-6db8-49ed-bf27-57accb1d600a",
      "description": "FS:ext4, CSI StorageClass nutanix-volume for nkpm01, PVC:git-operator-git-volume, NS:git-operator-system, POD:git-operator-git-0, SA:default",
      "logical_timestamp": 4,
      "disk_list": [
        {
          "index": 0,
          "vmdisk_uuid": "b5b463aa-e8fa-4f97-9f59-e4b1ec89affa",
          "container_id": 4,
          "storage_container_id": 4,
          "container_uuid": "0a6d6d1a-b52f-4998-903d-fcf9af00885a",
          "storage_container_uuid": "0a6d6d1a-b52f-4998-903d-fcf9af00885a",
          "vmdisk_size_mb": 10240,
          "vmdisk_size_bytes": 10737418240,
          "vmdisk_path": "/default-container-57560544335892/.stargate/castor/vgdisk/b5b463aa-e8fa-4f97-9f59-e4b1ec89affa",
          "flash_mode_enabled": false
        }
      ],
      "iscsi_target": "ntnx-k8s-f5c83859-0fc4-4d4d-51af-5d9f729c56c6",
      "attachment_list": [
        {
          "vm_uuid": "ea1b9005-42ed-41b5-95fc-50ca9f078fab"
        }
      ],
      "flash_mode_enabled": false,
      "load_balance_vm_attachments": true,
      "is_shared": false
    },
    {
      "uuid": "afbcd4e9-59a5-4f18-7c94-7a8c416a1b00",
      "name": "pvc-2ed1fdf9-0b97-4a0d-8164-a9b3af85a055",
      "description": "FS:ext4, CSI StorageClass nutanix-volume for nkpm01, PVC:git-operator-admin-volume, NS:git-operator-system, POD:git-operator-git-0, SA:default",
      "logical_timestamp": 7,
      "disk_list": [
        {
          "index": 0,
          "vmdisk_uuid": "da17ed3b-0453-4840-86ce-df687d7989af",
          "container_id": 4,
          "storage_container_id": 4,
          "container_uuid": "0a6d6d1a-b52f-4998-903d-fcf9af00885a",
          "storage_container_uuid": "0a6d6d1a-b52f-4998-903d-fcf9af00885a",
          "vmdisk_size_mb": 2048,
          "vmdisk_size_bytes": 2147483648,
          "vmdisk_path": "/default-container-57560544335892/.stargate/castor/vgdisk/da17ed3b-0453-4840-86ce-df687d7989af",
          "flash_mode_enabled": false
        }
      ],
      "iscsi_target": "ntnx-k8s-afbcd4e9-59a5-4f18-7c94-7a8c416a1b00",
      "flash_mode_enabled": false,
      "load_balance_vm_attachments": true,
      "is_shared": false
    },
    {
      "uuid": "f3d7bd21-79d1-440c-b774-7e80c5cac253",
      "name": "pvc-a170b447-789f-40b9-88c5-2d0981a3c5dc",
      "description": "nke02, PVC:prometheus-k8s-db-prometheus-k8s-0, NS:ntnx-system, POD:prometheus-k8s-0, SA:prometheus-k8s",
      "logical_timestamp": 2,
      "disk_list": [
        {
          "index": 0,
          "vmdisk_uuid": "eb566cd3-fc03-4e6e-92fd-1800ada8e4ce",
          "container_id": 4,
          "storage_container_id": 4,
          "container_uuid": "0a6d6d1a-b52f-4998-903d-fcf9af00885a",
          "storage_container_uuid": "0a6d6d1a-b52f-4998-903d-fcf9af00885a",
          "vmdisk_size_mb": 30720,
          "vmdisk_size_bytes": 32212254720,
          "vmdisk_path": "/default-container-57560544335892/.stargate/castor/vgdisk/eb566cd3-fc03-4e6e-92fd-1800ada8e4ce",
          "flash_mode_enabled": false
        }
      ],
      "iscsi_target": "ntnx-k8s-f3d7bd21-79d1-440c-b774-7e80c5cac253",
      "attachment_list": [
        {
          "client_uuid": "0efce0c6-a850-4d10-8fa4-e705784d3673",
          "iscsi_initiator_name": "iqn.2009-09.com.nutanix:dcce2d6b2699"
        }
      ],
      "flash_mode_enabled": false,
      "enabled_authentications": [
        {
          "auth_type": "chap"
        }
      ],
      "is_shared": true
    },
    {
      "uuid": "3e6a0843-9418-417c-a4c9-24489723db04",
      "name": "pvc-f31b37e7-d2e0-49bf-b5fa-512e71f49e1e",
      "description": "nke01, PVC:prometheus-k8s-db-prometheus-k8s-0, NS:ntnx-system, POD:prometheus-k8s-0, SA:prometheus-k8s",
      "logical_timestamp": 2,
      "disk_list": [
        {
          "index": 0,
          "vmdisk_uuid": "7328f2b1-aa1c-4c31-b42f-8db4e39ef734",
          "container_id": 4,
          "storage_container_id": 4,
          "container_uuid": "0a6d6d1a-b52f-4998-903d-fcf9af00885a",
          "storage_container_uuid": "0a6d6d1a-b52f-4998-903d-fcf9af00885a",
          "vmdisk_size_mb": 30720,
          "vmdisk_size_bytes": 32212254720,
          "vmdisk_path": "/default-container-57560544335892/.stargate/castor/vgdisk/7328f2b1-aa1c-4c31-b42f-8db4e39ef734",
          "flash_mode_enabled": false
        }
      ],
      "iscsi_target": "ntnx-k8s-3e6a0843-9418-417c-a4c9-24489723db04",
      "attachment_list": [
        {
          "client_uuid": "fc4c1dde-c71c-4c66-aa77-09462d904054",
          "iscsi_initiator_name": "iqn.2009-09.com.nutanix:4a4a351ff937"
        }
      ],
      "flash_mode_enabled": false,
      "enabled_authentications": [
        {
          "auth_type": "chap"
        }
      ],
      "is_shared": true
    },
    {
      "uuid": "9af089e6-f671-4a89-4be5-64ae2b58d003",
      "name": "pvc-e9c8c3b5-a399-46f1-819a-d5b019fae2cb",
      "description": "FS:ext4, CSI StorageClass nutanix-volume for nkpm01, PVC:git-operator-admin-volume, NS:git-operator-system, POD:git-operator-git-0, SA:default",
      "logical_timestamp": 4,
      "disk_list": [
        {
          "index": 0,
          "vmdisk_uuid": "071e681e-b968-4276-808e-133f205d0381",
          "container_id": 4,
          "storage_container_id": 4,
          "container_uuid": "0a6d6d1a-b52f-4998-903d-fcf9af00885a",
          "storage_container_uuid": "0a6d6d1a-b52f-4998-903d-fcf9af00885a",
          "vmdisk_size_mb": 2048,
          "vmdisk_size_bytes": 2147483648,
          "vmdisk_path": "/default-container-57560544335892/.stargate/castor/vgdisk/071e681e-b968-4276-808e-133f205d0381",
          "flash_mode_enabled": false
        }
      ],
      "iscsi_target": "ntnx-k8s-9af089e6-f671-4a89-4be5-64ae2b58d003",
      "attachment_list": [
        {
          "vm_uuid": "ea1b9005-42ed-41b5-95fc-50ca9f078fab"
        }
      ],
      "flash_mode_enabled": false,
      "load_balance_vm_attachments": true,
      "is_shared": false
    }
  ]
}

情報量が多いので、Description や接続設定などを確認しやすいように、jq のクエリで絞ります。

curl -X GET -k -s \
-u "$USER:$PASS" \
-H "Accept: application/json" \
--url "https://$PRISM:9440/PrismGateway/services/rest/v2.0/volume_groups" | \
jq -r '[.entities[] | {name: .name, description: .description, attachment_list: .attachment_list}]'

これで、下記のように VG 情報を取得できます。

$ curl -X GET -k -s \
> -u "$USER:$PASS" \
> -H "Accept: application/json" \
> --url "https://$PRISM:9440/PrismGateway/services/rest/v2.0/volume_groups" | \
> jq -r '[.entities[] | {name: .name, description: .description, attachment_list: .attachment_list}]'
[
  {
    "name": "pvc-f115e944-6d2b-41f2-8ce4-2e6e7dd98fc2",
    "description": "FS:ext4, CSI StorageClass nutanix-volume for nkpm01, PVC:git-operator-git-volume, NS:git-operator-system, POD:git-operator-git-0, SA:default",
    "attachment_list": null
  },
  {
    "name": "pvc-70ba1c1e-6db8-49ed-bf27-57accb1d600a",
    "description": "FS:ext4, CSI StorageClass nutanix-volume for nkpm01, PVC:git-operator-git-volume, NS:git-operator-system, POD:git-operator-git-0, SA:default",
    "attachment_list": [
      {
        "vm_uuid": "ea1b9005-42ed-41b5-95fc-50ca9f078fab"
      }
    ]
  },
  {
    "name": "pvc-2ed1fdf9-0b97-4a0d-8164-a9b3af85a055",
    "description": "FS:ext4, CSI StorageClass nutanix-volume for nkpm01, PVC:git-operator-admin-volume, NS:git-operator-system, POD:git-operator-git-0, SA:default",
    "attachment_list": null
  },
  {
    "name": "pvc-a170b447-789f-40b9-88c5-2d0981a3c5dc",
    "description": "nke02, PVC:prometheus-k8s-db-prometheus-k8s-0, NS:ntnx-system, POD:prometheus-k8s-0, SA:prometheus-k8s",
    "attachment_list": [
      {
        "client_uuid": "0efce0c6-a850-4d10-8fa4-e705784d3673",
        "iscsi_initiator_name": "iqn.2009-09.com.nutanix:dcce2d6b2699"
      }
    ]
  },
  {
    "name": "pvc-f31b37e7-d2e0-49bf-b5fa-512e71f49e1e",
    "description": "nke01, PVC:prometheus-k8s-db-prometheus-k8s-0, NS:ntnx-system, POD:prometheus-k8s-0, SA:prometheus-k8s",
    "attachment_list": [
      {
        "client_uuid": "fc4c1dde-c71c-4c66-aa77-09462d904054",
        "iscsi_initiator_name": "iqn.2009-09.com.nutanix:4a4a351ff937"
      }
    ]
  },
  {
    "name": "pvc-e9c8c3b5-a399-46f1-819a-d5b019fae2cb",
    "description": "FS:ext4, CSI StorageClass nutanix-volume for nkpm01, PVC:git-operator-admin-volume, NS:git-operator-system, POD:git-operator-git-0, SA:default",
    "attachment_list": [
      {
        "vm_uuid": "ea1b9005-42ed-41b5-95fc-50ca9f078fab"
      }
    ]
  }
]

さらに整理しやすいように、VG の名前と Desctiption だけを CSV で出力してみます。

curl -X GET -k -s \
-u "$USER:$PASS" \
-H "Accept: application/json" \
--url "https://$PRISM:9440/PrismGateway/services/rest/v2.0/volume_groups" | \
jq -r '.entities[] | [.name, .description] | @csv'

CSV で出力できました。フィールドの中にもカンマがたくさんありますが・・・

$ curl -X GET -k -s \
> -u "$USER:$PASS" \
> -H "Accept: application/json" \
> --url "https://$PRISM:9440/PrismGateway/services/rest/v2.0/volume_groups" | \
> jq -r '.entities[] | [.name, .description] | @csv'
"pvc-f115e944-6d2b-41f2-8ce4-2e6e7dd98fc2","FS:ext4, CSI StorageClass nutanix-volume for nkpm01, PVC:git-operator-git-volume, NS:git-operator-system, POD:git-operator-git-0, SA:default"
"pvc-70ba1c1e-6db8-49ed-bf27-57accb1d600a","FS:ext4, CSI StorageClass nutanix-volume for nkpm01, PVC:git-operator-git-volume, NS:git-operator-system, POD:git-operator-git-0, SA:default"
"pvc-2ed1fdf9-0b97-4a0d-8164-a9b3af85a055","FS:ext4, CSI StorageClass nutanix-volume for nkpm01, PVC:git-operator-admin-volume, NS:git-operator-system, POD:git-operator-git-0, SA:default"
"pvc-a170b447-789f-40b9-88c5-2d0981a3c5dc","nke02, PVC:prometheus-k8s-db-prometheus-k8s-0, NS:ntnx-system, POD:prometheus-k8s-0, SA:prometheus-k8s"
"pvc-f31b37e7-d2e0-49bf-b5fa-512e71f49e1e","nke01, PVC:prometheus-k8s-db-prometheus-k8s-0, NS:ntnx-system, POD:prometheus-k8s-0, SA:prometheus-k8s"
"pvc-e9c8c3b5-a399-46f1-819a-d5b019fae2cb","FS:ext4, CSI StorageClass nutanix-volume for nkpm01, PVC:git-operator-admin-volume, NS:git-operator-system, POD:git-operator-git-0, SA:default"

 

これをもとに、VG の要否を確認していこうと思います。

以上。

©2024 gowatana
クリエイティブ・コモンズ・ライセンスこの 作品 は クリエイティブ・コモンズ 表示 4.0 国際 ライセンスの下に提供されています。