Created
February 17, 2016 06:13
-
-
Save masanoriyamaguchi/2a3fa7f3a3a57d5989bb to your computer and use it in GitHub Desktop.
Mackerel向けOpenStack snapshotチェック用のスクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# -*- coding: utf-8 -*- | |
require 'httpclient' | |
require 'json' | |
class Nova | |
def keystone | |
auth_request_json = '{ | |
"auth" : { "tenantName" : "FvTenant", | |
"passwordCredentials" : { "username" : "admin", "password" : "FvAdmin999!" } | |
} | |
}' | |
keystone_client = HTTPClient.new | |
keystone_endpoint_uri = 'http://fv-ops01:35357/v2.0/tokens' | |
keystone_response = keystone_client.post_content(keystone_endpoint_uri, auth_request_json, 'Content-Type' => 'application/json' ) | |
keystone_response_hashed = JSON.parse(keystone_response) | |
keystone_response_endpoint_parsed = keystone_response_hashed['access']['serviceCatalog'][0]['endpoints'][0] | |
@nova_endpoint_uri = keystone_response_endpoint_parsed.values[0] | |
@keystone_auth_token = keystone_response_hashed['access']['token']['id'] | |
end | |
def nova_images | |
keystone | |
nova_images_client = HTTPClient.new(default_header: {"X-Auth-Token" => @keystone_auth_token }) | |
nova_images_endpoint_uri = @nova_endpoint_uri + "/images/detail" | |
nova_images_response = nova_images_client.get_content(nova_images_endpoint_uri, "q" => "status" ) | |
nova_images_response_hasged = JSON.parse(nova_images_response) | |
return nova_images_response_hasged | |
end | |
end | |
i = 0 | |
image_init = Nova.new | |
image_parsed = image_init.nova_images["images"] | |
image_status = "none" | |
while image_parsed.size > i do | |
if image_parsed[i]["status"] != "ACTIVE" | |
image_status = image_parsed[i]["name"] + " is " + image_parsed[i]["status"] | |
end | |
i += 1 | |
end | |
p "snapshots are all active." if image_status == "none" | |
exit (image_status != "none" ? 2 : image_status == "none" ? 0 : 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment