暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

OpenStack API

运维扫盲人 2021-06-17
388
    https://docs.openstack.org/api-quick-start/

    一、获取token

      root@controller-01:~# token=`openstack token issue|awk 'NR==5{print $4}'`

      TIPs:如果token过期,会返回一个401,重新获取token即可。

      二、keystone

      2.1 get/project

        root@controller-01:~# curl -H "X-Auth-Token:gAAAAABgWAeer7W2qkCz5-patcMWiKKDtmQujwYC_KdDtKNdrX5_rZbzzox2uJSBH7HcH980CKDdgBRt8CfDJCHtXnF7GLsipVyohYmma95cjMA0D50YTY3X5y2M-fGK23tuCd8zjie8qh69hSYsnncyjNGS8Pc9wKWA1l5HQOL_TbbAiNeTX5A" -H "Content-Type: application/json" http://controller:5000/v3/projects | python3 -m json.too
        root@controller-01:~# curl -H "X-Auth-Token:$token" -H "Content-Type: application/json" http://controller:5000/v3/projects | python3 -m json.tool
        % Total % Received % Xferd Average Speed Time Time Time Current
        Dload Upload Total Spent Left Speed
        100 983 100 983 0 0 4273 0 --:--:-- --:--:-- --:--:-- 4255
        {
        "projects": [
        {
        "id": "5516783c84af40a0abe77b1a39e489ce",
        "name": "myproject",
        "domain_id": "default",
        "description": "Demo Project",
        "enabled": true,
        "parent_id": "default",
        "is_domain": false,
        "tags": [],
        "links": {
        "self": "http://controller:5000/v3/projects/5516783c84af40a0abe77b1a39e489ce"
        }
        },
        {
        "id": "ded04e0f8ea5491582278519ce380edc",
        "name": "admin",
        "domain_id": "default",
        "description": "Bootstrap project for initializing the cloud.",
        "enabled": true,
        "parent_id": "default",
        "is_domain": false,
        "tags": [],
        "links": {
        "self": "http://controller:5000/v3/projects/ded04e0f8ea5491582278519ce380edc"
        }
        },
        {
        "id": "f6faef563147458c8b96022029e33266",
        "name": "service",
        "domain_id": "default",
        "description": "Service Project",
        "enabled": true,
        "parent_id": "default",
        "is_domain": false,
        "tags": [],
        "links": {
        "self": "http://controller:5000/v3/projects/f6faef563147458c8b96022029e33266"
        }
        }
        ],
        "links": {
        "next": null,
        "self": "http://controller:5000/v3/projects",
        "previous": null
        }
        }

        2.2 get/users

          root@controller-01:~# curl -H "X-Auth-Token:$token" -H "Content-Type: application/json" http://controller:5000/v3/users/4b7ecb49e5a7415aa32a63b00eeaa9fc | python3 -m json.tool
          % Total % Received % Xferd Average Speed Time Time Time Current
          Dload Upload Total Spent Left Speed
          100 241 100 241 0 0 948 0 --:--:-- --:--:-- --:--:-- 952
          {
          "user": {
          "id": "4b7ecb49e5a7415aa32a63b00eeaa9fc",
          "name": "nova",
          "domain_id": "default",
          "enabled": true,
          "password_expires_at": null,
          "options": {},
          "links": {
          "self": "http://controller:5000/v3/users/4b7ecb49e5a7415aa32a63b00eeaa9fc"
          }
          }
          }

          三、placement

            root@controller-01:~# curl -H "X-Auth-Token:$token" -H "Content-Type: application/json" http://controller:8778/resource_providers | python3 -m json.tool
            % Total % Received % Xferd Average Speed Time Time Time Current
            Dload Upload Total Spent Left Speed
            100 788 100 788 0 0 2194 0 --:--:-- --:--:-- --:--:-- 2201
            {
            "resource_providers": [
            {
            "uuid": "6d630bc3-cfc6-442f-912d-da2de78ba7c1",
            "name": "compute",
            "generation": 7,
            "links": [
            {
            "rel": "self",
            "href": "/resource_providers/6d630bc3-cfc6-442f-912d-da2de78ba7c1"
            },
            {
            "rel": "inventories",
            "href": "/resource_providers/6d630bc3-cfc6-442f-912d-da2de78ba7c1/inventories"
            },
            {
            "rel": "usages",
            "href": "/resource_providers/6d630bc3-cfc6-442f-912d-da2de78ba7c1/usages"
            }
            ]
            },
            {
            "uuid": "0246419a-ac04-4aa6-a273-df9dcb72a250",
            "name": "compute-02",
            "generation": 12,
            "links": [
            {
            "rel": "self",
            "href": "/resource_providers/0246419a-ac04-4aa6-a273-df9dcb72a250"
            },
            {
            "rel": "inventories",
            "href": "/resource_providers/0246419a-ac04-4aa6-a273-df9dcb72a250/inventories"
            },
            {
            "rel": "usages",
            "href": "/resource_providers/0246419a-ac04-4aa6-a273-df9dcb72a250/usages"
            }
            ]
            }
            ]
            }

            四、nova

            4.1 get/server

              root@controller-01:~# curl -H "X-Auth-Token:$token" -H "Content-Type: application/json" http://controller:8774/v2/servers | python3 -m json.tool
              % Total % Received % Xferd Average Speed Time Time Time Current
              Dload Upload Total Spent Left Speed
              100 285 100 285 0 0 683 0 --:--:-- --:--:-- --:--:-- 683
              {
              "servers": [
              {
              "id": "8dca31c5-09c0-4e00-81ea-c49573c6c5a7",
              "name": "vm",
              "links": [
              {
              "rel": "self",
              "href": "http://controller:8774/v2/servers/8dca31c5-09c0-4e00-81ea-c49573c6c5a7"
              },
              {
              "rel": "bookmark",
              "href": "http://controller:8774/servers/8dca31c5-09c0-4e00-81ea-c49573c6c5a7"
              }
              ]
              }
              ]
              }

              4.2 start server

                root@controller-01:~# curl -X POST -H "X-Auth-Token:$t '{"os-start" : null}' http://controller:8774/v2.1/servers/8dca31c5-09c0-4e00-81ea-c49573c6c5a7/action

                五、neutron

                5.1 get/version

                  root@controller-01:~# curl  -H "X-Auth-Token:$token" -H "Content-Type: application/json"  http://controller:9696  | python3 -m json.tool
                  % Total % Received % Xferd Average Speed Time Time Time Current
                  Dload Upload Total Spent Left Speed
                  100 119 100 119 0 0 14875 0 --:--:-- --:--:-- --:--:-- 14875
                  {
                  "versions": [
                  {
                  "id": "v2.0",
                  "status": "CURRENT",
                  "links": [
                  {
                  "rel": "self",
                  "href": "http://controller:9696/v2.0/"
                  }
                  ]
                  }
                  ]
                  }

                  5.2 get/networks

                    root@controller-01:~# curl  -H "X-Auth-Token:$token" -H "Content-Type: application/json"  http://controller:9696/v2.0/networks  | python3 -m json.tool
                    % Total % Received % Xferd Average Speed Time Time Time Current
                    Dload Upload Total Spent Left Speed
                    100 1395 100 1395 0 0 9823 0 --:--:-- --:--:-- --:--:-- 9823
                    {
                    "networks": [
                    {
                    "id": "42adde0f-95d7-49e0-8b69-3a48276b492d",
                    "name": "selfservice",
                    "tenant_id": "ded04e0f8ea5491582278519ce380edc",
                    "admin_state_up": true,
                    "mtu": 1450,
                    "status": "ACTIVE",
                    "subnets": [
                    "b08bf9e9-2488-45d3-98fa-8720ed7f05f5"
                    ],
                    "shared": false,
                    "availability_zone_hints": [],
                    "availability_zones": [
                    "nova"
                    ],
                    "ipv4_address_scope": null,
                    "ipv6_address_scope": null,
                    "router:external": false,
                    "description": "",
                    "port_security_enabled": true,
                    "dns_domain": "2021.cloud.com.",
                    "tags": [],
                    "created_at": "2021-03-02T13:30:35Z",
                    "updated_at": "2021-03-02T13:37:23Z",
                    "revision_number": 3,
                    "project_id": "ded04e0f8ea5491582278519ce380edc",
                    "provider:network_type": "vxlan",
                    "provider:physical_network": null,
                    "provider:segmentation_id": 1
                    },
                    {
                    "id": "e5874e6a-3282-4bd8-b82a-05b998ee0909",
                    "name": "provider",
                    "tenant_id": "ded04e0f8ea5491582278519ce380edc",
                    "admin_state_up": true,
                    "mtu": 1500,
                    "status": "ACTIVE",
                    "subnets": [
                    "f4bc642c-adb0-48a8-b010-6357dca7f59b"
                    ],
                    "shared": true,
                    "availability_zone_hints": [],
                    "availability_zones": [
                    "nova"
                    ],
                    "ipv4_address_scope": null,
                    "ipv6_address_scope": null,
                    "router:external": true,
                    "description": "",
                    "port_security_enabled": true,
                    "dns_domain": "",
                    "is_default": false,
                    "tags": [],
                    "created_at": "2021-03-02T13:29:30Z",
                    "updated_at": "2021-03-02T13:30:18Z",
                    "revision_number": 2,
                    "project_id": "ded04e0f8ea5491582278519ce380edc",
                    "provider:network_type": "flat",
                    "provider:physical_network": "provider",
                    "provider:segmentation_id": null
                    }
                    ]
                    }

                    5.3 create network

                      root@controller-01:~# curl -X POST http://controller:9696/v2.0/networks     -H "X-Auth-Token:$token" -H "Content-Type: application/json"     -d  '{"network": {"admin_state_up": true, "name": "net1"} }' | python3 -m json.tool
                      % Total % Received % Xferd Average Speed Time Time Time Current
                      Dload Upload Total Spent Left Speed
                      100 705 100 651 100 54 1686 139 --:--:-- --:--:-- --:--:-- 1826
                      {
                      "network": {
                      "id": "74f07f31-e244-40f3-a13f-836b4ad4f3c8",
                      "name": "net1",
                      "tenant_id": "ded04e0f8ea5491582278519ce380edc",
                      "admin_state_up": true,
                      "mtu": 1450,
                      "status": "ACTIVE",
                      "subnets": [],
                      "shared": false,
                      "project_id": "ded04e0f8ea5491582278519ce380edc",
                      "port_security_enabled": true,
                      "dns_domain": "",
                      "router:external": false,
                      "provider:network_type": "vxlan",
                      "provider:physical_network": null,
                      "provider:segmentation_id": 2,
                      "availability_zone_hints": [],
                      "is_default": false,
                      "availability_zones": [],
                      "ipv4_address_scope": null,
                      "ipv6_address_scope": null,
                      "description": "",
                      "tags": [],
                      "created_at": "2021-03-22T06:35:04Z",
                      "updated_at": "2021-03-22T06:35:04Z",
                      "revision_number": 1
                      }
                      }


                      文章转载自运维扫盲人,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

                      评论