hpe-container-platform-community/hpecp-python-library

Implement epic cluster management

snowch opened this issue · 5 comments

Create cluster:

POST /api/v2/cluster/ HTTP/1.1
Host: 127.0.0.1:8080
Content-Length: 336
Accept-Encoding: gzip, deflate
REMOTE_ADDR: 85.255.236.160
Accept: */*
User-Agent: python-requests/2.6.0 CPython/2.7.5 Linux/3.10.0-1127.18.2.el7.x86_64
Connection: keep-alive
X-BDS-SESSION: /api/v2/session/41767072-b4ac-48fb-903b-118437e9490e
Authorization: /api/v2/session/41767072-b4ac-48fb-903b-118437e9490e

{
  "isolated": false,
  "label": {
    "name": "c1",
    "description": ""
  },
  "dependent_nodegroups": [],
  "debug": false,
  "two_phase_delete": false,
  "nodegroup": {
    "role_configs": [
      {
        "node_count": 1,
        "flavor": "/api/v1/flavor/1",
        "role_id": "utility"
      }
    ],
    "catalog_entry_distro_id": "bluedata/centos6",
    "config_choice_selections": [],
    "constraints": []
  }
}
HTTP/1.1 201 Created
Access-Control-Allow-Origin: *
Content-Length: 13
Content-Type: text/plain
Date: Fri, 31 Jul 2020 03:48:28 GMT
Location: /api/v2/cluster/1
Server: HPE Ezmeral Container Platform 5.1

201 Created

Stop cluster:

POST /api/v2/cluster/4/change_task HTTP/1.1
Host: 127.0.0.1:8080
Content-Length: 60
Accept-Encoding: gzip, deflate
REMOTE_ADDR: 85.255.236.160
Accept: */*
User-Agent: python-requests/2.6.0 CPython/2.7.5 Linux/3.10.0-1127.18.2.el7.x86_64
Connection: keep-alive
X-BDS-SESSION: /api/v2/session/41767072-b4ac-48fb-903b-118437e9490e
Authorization: /api/v2/session/41767072-b4ac-48fb-903b-118437e9490e

{"change_spec": {"action": "stop"}, "operation": "power_op"}
HTTP/1.1 201 Created
Access-Control-Allow-Origin: *
Content-Length: 13
Content-Type: text/plain
Date: Fri, 31 Jul 2020 04:19:33 GMT
Location: /api/v2/cluster/4/change_history/1
Server: HPE Ezmeral Container Platform 5.1

201 Created

Reboot cluster:

POST /api/v2/cluster/4/change_task HTTP/1.1
Host: 127.0.0.1:8080
Content-Length: 62
Accept-Encoding: gzip, deflate
REMOTE_ADDR: 85.255.236.160
Accept: */*
User-Agent: python-requests/2.6.0 CPython/2.7.5 Linux/3.10.0-1127.18.2.el7.x86_64
Connection: keep-alive
X-BDS-SESSION: /api/v2/session/41767072-b4ac-48fb-903b-118437e9490e
Authorization: /api/v2/session/41767072-b4ac-48fb-903b-118437e9490e

{"change_spec": {"action": "reboot"}, "operation": "power_op"}
HTTP/1.1 201 Created
Access-Control-Allow-Origin: *
Content-Length: 13
Content-Type: text/plain
Date: Fri, 31 Jul 2020 04:33:59 GMT
Location: /api/v2/cluster/4/change_history/3
Server: HPE Ezmeral Container Platform 5.1

201 Created

hmm?

2020-07-31 05:36:14,588 - hpecp - HPECP_CLI - DEBUG - ('405 Client Error: Method Not Allowed for url: http://54.70.70.121:8080/api/v2/cluster/4/change_task', 'post', 'http://54.70.70.121:8080/api/v2/cluster/4/change_task', '{"change_spec": {"action": "reboot"}, "operation": "power_op"}')

Ok - this operation needs to be performed using the tenant api, i.e.

$ cat ~/.hpecp.conf
[default]
api_host = 54.70.70.121
api_port = 8080
use_ssl = False
verify_ssl = False
warn_ssl = False
username = admin
password = admin123

[tenant-2]
tenant = /api/v1/tenant/2

then

$ PROFILE=tenant-2 hpecp httpclient post /api/v2/cluster/4/change_task --json-file <(echo -n '{"change_spec": {"action": "start"}, "operation": "power_op"}')
GET /api/v2/cluster/4/node?services&catalog_entry HTTP/1.1
Host: 127.0.0.1:8080
Accept-Encoding: gzip, deflate
REMOTE_ADDR: 185.69.144.159
Accept: */*
User-Agent: python-requests/2.6.0 CPython/2.7.5 Linux/3.10.0-1127.18.2.el7.x86_64
Connection: keep-alive
X-BDS-SESSION: /api/v2/session/bdbc5cda-991f-4196-a63a-65612f625113
Authorization: /api/v2/session/bdbc5cda-991f-4196-a63a-65612f625113

HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Content-Length: 6526
Content-Type: application/json
Date: Fri, 31 Jul 2020 22:12:20 GMT
Server: HPE Ezmeral Container Platform 5.1

{
  "_links": {
    "self": {
      "href": "/api/v2/cluster/4/node?services&catalog_entry"
    },
    "nodegroup_filter": {
      "href": "/api/v2/cluster/4/node?nodegroup={nodegroup}",
      "templated": true
    },
    "role_filter": {
      "href": "/api/v2/cluster/4/node?role={role}",
      "templated": true
    },
    "include_flavor": {
      "href": "/api/v2/cluster/4/node?flavor"
    }
  },
  "_embedded": {
    "nodes": [
      {
        "_links": {
          "self": {
            "href": "/api/v2/cluster/4/node/5?services&catalog_entry"
          },
          "cluster": {
            "href": "/api/v2/cluster/4",
            "title": "g"
          },
          "tenant": {
            "href": "/api/v1/tenant/2",
            "title": "Demo Tenant"
          },
          "include_flavor": {
            "href": "/api/v2/cluster/4/node/5?flavor"
          }
        },
        "private_ip": "172.18.0.4",
        "fqdn": "bluedata-5.demo.bdlocal",
        "name": "bluedata-5",
        "metrics_instances": [
          {
            "metric_id": "cpu",
            "selectors": [
              {
                "field": "docker.container.id",
                "value": "555aeca67454e21e1e58bd1e4d948abfd94a095058c0dfdcd5a2842169a62b06"
              }
            ]
          },
          {
            "metric_id": "memory",
            "selectors": [
              {
                "field": "docker.container.id",
                "value": "555aeca67454e21e1e58bd1e4d948abfd94a095058c0dfdcd5a2842169a62b06"
              }
            ]
          },
          {
            "metric_id": "network_in",
            "selectors": [
              {
                "field": "beat.hostname",
                "value": "ip-10-1-0-223.us-west-2.compute.internal"
              },
              {
                "field": "system.network.name",
                "value": "24426-h"
              }
            ]
          },
          {
            "metric_id": "network_out",
            "selectors": [
              {
                "field": "beat.hostname",
                "value": "ip-10-1-0-223.us-west-2.compute.internal"
              },
              {
                "field": "system.network.name",
                "value": "24426-h"
              }
            ]
          },
          {
            "metric_id": "disk_overlay_read_ops",
            "selectors": [
              {
                "field": "docker.container.id",
                "value": "555aeca67454e21e1e58bd1e4d948abfd94a095058c0dfdcd5a2842169a62b06"
              }
            ]
          },
          {
            "metric_id": "disk_overlay_read_bytes",
            "selectors": [
              {
                "field": "docker.container.id",
                "value": "555aeca67454e21e1e58bd1e4d948abfd94a095058c0dfdcd5a2842169a62b06"
              }
            ]
          },
          {
            "metric_id": "disk_overlay_read_rate",
            "selectors": [
              {
                "field": "docker.container.id",
                "value": "555aeca67454e21e1e58bd1e4d948abfd94a095058c0dfdcd5a2842169a62b06"
              }
            ]
          },
          {
            "metric_id": "disk_overlay_write_ops",
            "selectors": [
              {
                "field": "docker.container.id",
                "value": "555aeca67454e21e1e58bd1e4d948abfd94a095058c0dfdcd5a2842169a62b06"
              }
            ]
          },
          {
            "metric_id": "disk_overlay_write_bytes",
            "selectors": [
              {
                "field": "docker.container.id",
                "value": "555aeca67454e21e1e58bd1e4d948abfd94a095058c0dfdcd5a2842169a62b06"
              }
            ]
          },
          {
            "metric_id": "disk_overlay_write_rate",
            "selectors": [
              {
                "field": "docker.container.id",
                "value": "555aeca67454e21e1e58bd1e4d948abfd94a095058c0dfdcd5a2842169a62b06"
              }
            ]
          }
        ],
        "status": "ready",
        "role": "jupyterhub",
        "nodegroup_id": "1",
        "catalog_entry": "/api/v1/catalog/29",
        "catalog_entry_distro_id": "bluedata/spark240juphub7xssl",
        "catalog_entry_label": {
          "name": "Spark240",
          "description": "Spark240 multirole with Jupyter Notebook, Jupyterhub with SSL and gateway node"
        },
        "catalog_entry_state": "installed",
        "catalog_entry_version": "2.8",
        "services": [
          {
            "id": "jupyterhub",
            "label": {
              "name": "Jupyterhub",
              "description": ""
            },
            "endpoint": {
              "is_dashboard": true,
              "url_scheme": "https",
              "port": "443",
              "path": "/",
              "loadbalanced": false,
              "proxy_host": "ip-10-1-0-190.us-west-2.compute.internal",
              "proxy_port": "10005",
              "proxy_scheme": "https"
            }
          },
          {
            "id": "ssh",
            "label": {
              "name": "SSH",
              "description": ""
            },
            "endpoint": {
              "is_dashboard": false,
              "port": "22",
              "loadbalanced": false,
              "proxy_host": "ip-10-1-0-190.us-west-2.compute.internal",
              "proxy_port": "10004"
            }
          }
        ],
        "hypervisor_host": "ip-10-1-0-223.us-west-2.compute.internal"
      },
      {
        "_links": {
          "self": {
            "href": "/api/v2/cluster/4/node/4?services&catalog_entry"
          },
          "cluster": {
            "href": "/api/v2/cluster/4",
            "title": "g"
          },
          "tenant": {
            "href": "/api/v1/tenant/2",
            "title": "Demo Tenant"
          },
          "include_flavor": {
            "href": "/api/v2/cluster/4/node/4?flavor"
          }
        },
        "private_ip": "172.18.0.5",
        "fqdn": "bluedata-4.demo.bdlocal",
        "name": "bluedata-4",
        "metrics_instances": [
          {
            "metric_id": "cpu",
            "selectors": [
              {
                "field": "docker.container.id",
                "value": "3ef4b9021b9c7700d5c3ea9c30ac352b3d8d6b87d62aadfbff3e72497738906a"
              }
            ]
          },
          {
            "metric_id": "memory",
            "selectors": [
              {
                "field": "docker.container.id",
                "value": "3ef4b9021b9c7700d5c3ea9c30ac352b3d8d6b87d62aadfbff3e72497738906a"
              }
            ]
          },
          {
            "metric_id": "network_in",
            "selectors": [
              {
                "field": "beat.hostname",
                "value": "ip-10-1-0-223.us-west-2.compute.internal"
              },
              {
                "field": "system.network.name",
                "value": "24428-h"
              }
            ]
          },
          {
            "metric_id": "network_out",
            "selectors": [
              {
                "field": "beat.hostname",
                "value": "ip-10-1-0-223.us-west-2.compute.internal"
              },
              {
                "field": "system.network.name",
                "value": "24428-h"
              }
            ]
          },
          {
            "metric_id": "disk_overlay_read_ops",
            "selectors": [
              {
                "field": "docker.container.id",
                "value": "3ef4b9021b9c7700d5c3ea9c30ac352b3d8d6b87d62aadfbff3e72497738906a"
              }
            ]
          },
          {
            "metric_id": "disk_overlay_read_bytes",
            "selectors": [
              {
                "field": "docker.container.id",
                "value": "3ef4b9021b9c7700d5c3ea9c30ac352b3d8d6b87d62aadfbff3e72497738906a"
              }
            ]
          },
          {
            "metric_id": "disk_overlay_read_rate",
            "selectors": [
              {
                "field": "docker.container.id",
                "value": "3ef4b9021b9c7700d5c3ea9c30ac352b3d8d6b87d62aadfbff3e72497738906a"
              }
            ]
          },
          {
            "metric_id": "disk_overlay_write_ops",
            "selectors": [
              {
                "field": "docker.container.id",
                "value": "3ef4b9021b9c7700d5c3ea9c30ac352b3d8d6b87d62aadfbff3e72497738906a"
              }
            ]
          },
          {
            "metric_id": "disk_overlay_write_bytes",
            "selectors": [
              {
                "field": "docker.container.id",
                "value": "3ef4b9021b9c7700d5c3ea9c30ac352b3d8d6b87d62aadfbff3e72497738906a"
              }
            ]
          },
          {
            "metric_id": "disk_overlay_write_rate",
            "selectors": [
              {
                "field": "docker.container.id",
                "value": "3ef4b9021b9c7700d5c3ea9c30ac352b3d8d6b87d62aadfbff3e72497738906a"
              }
            ]
          }
        ],
        "status": "ready",
        "role": "controller",
        "nodegroup_id": "1",
        "catalog_entry": "/api/v1/catalog/29",
        "catalog_entry_distro_id": "bluedata/spark240juphub7xssl",
        "catalog_entry_label": {
          "name": "Spark240",
          "description": "Spark240 multirole with Jupyter Notebook, Jupyterhub with SSL and gateway node"
        },
        "catalog_entry_state": "installed",
        "catalog_entry_version": "2.8",
        "services": [
          {
            "id": "spark",
            "label": {
              "name": "Spark master",
              "description": ""
            },
            "endpoint": {
              "is_dashboard": true,
              "url_scheme": "http",
              "port": "8080",
              "path": "/",
              "loadbalanced": false,
              "proxy_host": "ip-10-1-0-190.us-west-2.compute.internal",
              "proxy_port": "10000",
              "proxy_scheme": "http"
            }
          },
          {
            "id": "spark_master",
            "label": {
              "name": "Spark master",
              "description": ""
            },
            "endpoint": {
              "is_dashboard": false,
              "url_scheme": "spark",
              "port": "7077",
              "loadbalanced": false,
              "proxy_host": "ip-10-1-0-190.us-west-2.compute.internal",
              "proxy_port": "10003",
              "proxy_scheme": "spark"
            },
            "exported_service": "spark"
          },
          {
            "id": "spark_worker",
            "label": {
              "name": "Spark worker",
              "description": ""
            },
            "endpoint": {
              "is_dashboard": true,
              "url_scheme": "http",
              "port": "8081",
              "path": "/",
              "loadbalanced": false,
              "proxy_host": "ip-10-1-0-190.us-west-2.compute.internal",
              "proxy_port": "10001",
              "proxy_scheme": "http"
            }
          },
          {
            "id": "ssh",
            "label": {
              "name": "SSH",
              "description": ""
            },
            "endpoint": {
              "is_dashboard": false,
              "port": "22",
              "loadbalanced": false,
              "proxy_host": "ip-10-1-0-190.us-west-2.compute.internal",
              "proxy_port": "10002"
            }
          }
        ],
        "hypervisor_host": "ip-10-1-0-223.us-west-2.compute.internal"
      }
    ]
  }
}