nodejsは、OpenStackのAPIキーストーンのログイン認証(III)を呼び出し:すべてのテスト画像を取得します

すべての画像のリストを取得します。 

function image_server(x_subject_token) {

    var options = {
        host: 'xxx.xx.xxx.xx',
        port: 9292,
        path: '/v2/images',
        method: 'GET',
        headers: {
            'Content-Type': 'application/json',
            'X-Auth-Token': x_subject_token,
        }
    };

    console.log(options);

    var req = http.request(options, function (res) {
        res.setEncoding('utf8');
        var rawData = '';

        res.on('data', function (chunk) {
            rawData += chunk;
        });
        res.on('end', function () {
            try{
                console.log("rawData::"+rawData);
                const parsedData = JSON.parse(rawData);
            } catch (e) {
                console.error(e.message);
                // cb('error');
            }
        });
    });
    req.on('error', function (e) {
        console.log(e)
    });

    req.end();
}

結果:

rawData::{"images": [{"status": "active", "name": "centos_7", "tags": [], "container_format": "bare", "created_at": "2019-12-28T09:32:05Z", "size": 1264951296, "disk_forma
t": "iso", "updated_at": "2019-12-28T09:32:15Z", "visibility": "public", "self": "/v2/images/254f2311-9fb0-4a47-b080-0bc4d6c78129", "min_disk": 0, "protected": false, "id"
: "254f2311-9fb0-4a47-b080-0bc4d6c78129", "file": "/v2/images/254f2311-9fb0-4a47-b080-0bc4d6c78129/file", "checksum": "5ca9487516d9d499abc38bcd6d42c852", "owner": "9a89c5f
a0ed541b493b88408dea4e43c", "virtual_size": null, "min_ram": 0, "schema": "/v2/schemas/image"}, {"status": "active", "name": "vfw", "tags": [], "container_format": "bare",
 "created_at": "2019-12-28T09:25:14Z", "size": 298811392, "disk_format": "iso", "updated_at": "2019-12-28T09:25:16Z", "visibility": "public", "self": "/v2/images/950dfe24-
d4bd-4b3b-8a6f-f7b752c79175", "min_disk": 0, "protected": false, "id": "950dfe24-d4bd-4b3b-8a6f-f7b752c79175", "file": "/v2/images/950dfe24-d4bd-4b3b-8a6f-f7b752c79175/fil
e", "checksum": "c12a729704810b0777b488eca6a48e66", "owner": "9a89c5fa0ed541b493b88408dea4e43c", "virtual_size": null, "min_ram": 0, "schema": "/v2/schemas/image"}, {"stat
us": "active", "virtual_size": null, "description": "vControoler", "tags": [], "container_format": "ova", "created_at": "2019-12-28T09:15:44Z", "size": 3584762368, "disk_f
ormat": "vmdk", "updated_at": "2019-12-28T09:16:01Z", "visibility": "public", "self": "/v2/images/41daa344-a9cf-4cdb-a3b2-358a9beb6433", "min_disk": 0, "protected": false,
 "id": "41daa344-a9cf-4cdb-a3b2-358a9beb6433", "file": "/v2/images/41daa344-a9cf-4cdb-a3b2-358a9beb6433/file", "checksum": "986ba080c93a76048c1fd0310dd50f86", "owner": "9a
89c5fa0ed541b493b88408dea4e43c", "schema": "/v2/schemas/image", "min_ram": 0, "name": "vControoler"}, {"status": "active", "name": "waf", "tags": [], "container_format": "
bare", "created_at": "2019-12-28T08:51:32Z", "size": 3102146560, "disk_format": "qcow2", "updated_at": "2019-12-28T08:51:46Z", "visibility": "public", "self": "/v2/images/
b01127c5-b306-4b1e-b461-0412f43fc555", "min_disk": 0, "protected": false, "id": "b01127c5-b306-4b1e-b461-0412f43fc555", "file": "/v2/images/b01127c5-b306-4b1e-b461-0412f43
fc555/file", "checksum": "c85a241430444134bac49da5d6e4627d", "owner": "9a89c5fa0ed541b493b88408dea4e43c", "virtual_size": null, "min_ram": 0, "schema": "/v2/schemas/image"
}], "schema": "/v2/schemas/images", "first": "/v2/images"}

 

しかし、研究は、バージョン情報を調べる必要があります:パス:「/ V2 /画像」、デバッグv2の良いする必要があり、そのバージョンが渡されていないではない場合、あなたは次のパスの内容にバージョン番号のすべてを取得することができます

var options = {
        host: 'xx.xx.xx.xx',
        port: 9292,
        path: '/images',
        method: 'GET',
        headers: {
            'Content-Type': 'application/json',
            'X-Auth-Token': x_subject_token,
        }
    };

 結果:

gAAAAABeB7rBoZ9Q-jrku0n6gujeJuS1x454XpHJoiVw0wCoX55_ELH3p-BbV-QRHBo05nckijGfYbYf7CRXlrohILtzkOZ3ULRDmBURj_xLF_nbjlhH25GimD3iKgZysj0Zk-StmQG2L0dfjFg7Un-WaMYFFxSbXg
rawData::{"versions": [{"status": "CURRENT", "id": "v2.6", "links": [{"href": "http://xx.xx.xx.xx:9292/v2/", "rel": "self"}]}, {"status": "SUPPORTED", "id": "v2.5", "lin
ks": [{"href": "http://xx.xx.xx.xx:9292/v2/", "rel": "self"}]}, {"status": "SUPPORTED", "id": "v2.4", "links": [{"href": "http://xx.xx.xx.xx:9292/v2/", "rel": "self"}]
}, {"status": "SUPPORTED", "id": "v2.3", "links": [{"href": "http://xx.xx.xx..xx:9292/v2/", "rel": "self"}]}, {"status": "SUPPORTED", "id": "v2.2", "links": [{"href": "ht
tp://xx.xx.xx.xx:9292/v2/", "rel": "self"}]}, {"status": "SUPPORTED", "id": "v2.1", "links": [{"href": "http://xx.xx.xx.xx:9292/v2/", "rel": "self"}]}, {"status": "SUP
PORTED", "id": "v2.0", "links": [{"href": "http://xx.xx.xx.xx:9292/v2/", "rel": "self"}]}, {"status": "DEPRECATED", "id": "v1.1", "links": [{"href": "http://xx.xx.xx.xx:9292/v1/", "rel": "self"}]}, {"status": "DEPRECATED", "id": "v1.0", "links": [{"href": "http://xx.xx.xx.xx:9292/v1/", "rel": "self"}]}]}
xxxxx[object Object]
{

しかし、それは403エラーが報告されます

{
  forbidden: {
    message: "Policy doesn't allow os_compute_api:os-hypervisors to be performed.",
    code: 403
  }
}

 

 

公開された127元の記事 ウォン称賛35 ビュー10万+

おすすめ

転載: blog.csdn.net/shunzi2016/article/details/103750754