以OpenStack环境为例:

1.生成认证所需要的token
#token=`openstack token issue|awk -F \’|\’ \’NR==5{print $3}\’`


2. 执行curl命令发送POST请求,关闭虚拟机
#curl -g -i -X POST http://10.180.204.40/compute/v2.1/servers/7a4968fb-da98-41ae-9413-1e37fd2c5411/action -H “Accept: application/json” -H “User-Agent: python-novaclient” -H “OpenStack-API-Version: compute 2.41” -H “X-OpenStack-Nova-API-Version: 2.41” -H “X-Auth-Token: $token” -H “Content-Type: application/json” -d \'{“os-stop”: {“shutdown”:”soft”}}\’
发送成功,如下图所示:


3.curl发送GET请求,以获取虚拟机列表为例
#curl -g -i -X GET http://10.180.204.40/compute/v2.1/servers -H “Accept: application/json” -H “User-Agent: python-novaclient” -H “OpenStack-API-Version: compute 2.41” -H “X-OpenStack-Nova-API-Version: 2.41” -H “X-Auth-Token: $token” -H “Content-Type: application/json”
获取成功如下图所示:

可以看到response信息如下:
{
    “servers”: [{
            “id”: “7a4968fb-da98-41ae-9413-1e37fd2c5411”,
            “links”: [{
                    “href”: “http://10.180.204.40/compute/v2.1/servers/7a4968fb-da98-41ae-9413-1e37fd2c5411”,
                    “rel”: “self”
                }, {
                    “href”: “http://10.180.204.40/compute/servers/7a4968fb-da98-41ae-9413-1e37fd2c5411”,
                    “rel”: “bookmark”
                }
            ],
            “name”: “zbl”
        }
    ]
}

 

 

版权声明:本文为匿名原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: