{"id":11243,"date":"2015-11-09T21:23:51","date_gmt":"2015-11-09T12:23:51","guid":{"rendered":"http:\/\/a-tak.com\/blog\/?p=11243"},"modified":"2020-07-13T14:28:23","modified_gmt":"2020-07-13T05:28:23","slug":"gce-template-with-hue","status":"publish","type":"post","link":"https:\/\/a-tak.com\/blog\/2015\/11\/gce-template-with-hue\/","title":{"rendered":"GCE\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u81ea\u52d5\u518d\u751f\u6210\u3057\u7d42\u308f\u3063\u305f\u3089\u96fb\u7403\u5149\u3089\u305b\u308b"},"content":{"rendered":"<div id=\"advads-3329583300\" class=\"advads-before-content-placement advads-entity-placement\" style=\"margin-left: auto;margin-right: auto;text-align: center;\"><div class=\"advads-adlabel\">\u5e83\u544a<\/div><script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js?client=ca-pub-7585646298782746\" crossorigin=\"anonymous\"><\/script><ins class=\"adsbygoogle\" style=\"display:inline-block;width:300px;height:250px;\" \ndata-ad-client=\"ca-pub-7585646298782746\" \ndata-ad-slot=\"6112122906\"><\/ins> \n<script> \n(adsbygoogle = window.adsbygoogle || []).push({}); \n<\/script>\n<\/div><figure><a href=\"https:\/\/i0.wp.com\/a-tak.com\/blog\/wp-content\/uploads\/2015\/11\/20151103gce-01.jpg?ssl=1\" title=\"GCE! Hue!\"><img data-recalc-dims=\"1\" decoding=\"async\" class=\"shadow-img\" src=\"https:\/\/i0.wp.com\/a-tak.com\/blog\/wp-content\/uploads\/2015\/11\/20151103gce-01.jpg?w=700&#038;ssl=1\" alt=\"GCE! Hue!\" title=\"20151103gce-01.jpg\"   \/><\/a>\u2028<\/figure>\n<p>\u3000Google Compute Engine\u306e\u30aa\u30fc\u30c8\u30b9\u30b1\u30fc\u30eb\u306e\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u5165\u308c\u66ff\u3048\u5f8c\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u518d\u751f\u6210\u3092\u30ed\u30fc\u30c9\u30d0\u30e9\u30f3\u30b5\u30fc\u306e\u72b6\u6cc1\u3092\u898b\u306a\u304c\u3089\u81ea\u52d5\u3067\u884c\u3063\u3066\u3001\u5168\u90e8\u518d\u751f\u6210\u7d42\u308f\u3063\u305f\u3089\u3001Philips Hue\u3092\u5149\u3089\u305b\u308b\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u4f5c\u3063\u305f\u3088\u3002<\/p>\n<p><!--more--><\/p>\n<h2>\u8ffd\u8a18[2016-03-06]<\/h2>\n<p>\u3000\u3069\u3046\u3084\u3089Google\u306e\u65b9\u3067Alpha\u7248\u3067\u3059\u304c\u30ed\u30fc\u30ea\u30f3\u30b0\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8\u306eAPI\u304c\u51fa\u6765\u3066\u3044\u308b\u3088\u3046\u3067\u3059\u3002<\/p>\n<p><a class=\"embedly-card\" href=\"https:\/\/cloud.google.com\/compute\/docs\/instance-groups\/updater\/v1beta1\/rollingUpdates\">RollingUpdates<\/a><script async src=\"\/\/cdn.embedly.com\/widgets\/platform.js\" charset=\"UTF-8\"><\/script><\/p>\n<p>\u3000\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u898b\u308b\u9650\u308a\u3067\u306f\u4f3c\u305f\u3088\u3046\u306a\u3053\u3068\u304c\u51fa\u6765\u305d\u3046\u306a\u306e\u3067\u3001\u3053\u3063\u3061\u3092\u4f7f\u3063\u305f\u65b9\u304c\u3088\u3044\u3067\u3057\u3087\u3046\u306d\u3002<\/p>\n<h2>\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u306e\u518d\u751f\u6210\u5f8c\u306bLB\u3067HEALTHY\u306b\u306a\u308b\u306e\u306b\u6642\u9593\u304c\u304b\u304b\u308b<\/h2>\n<p><a class=\"embedly-card\" href=\"https:\/\/a-tak.com\/blog\/2015\/11\/gce-template-update\/\">GCE\u306e\u30aa\u30fc\u30c8\u30b9\u30b1\u30fc\u30eb\u306e\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3092\u30b3\u30de\u30f3\u30c9\u3067\u697d\u306b\u5dee\u3057\u66ff\u3048\u308b | A-tak-dot-com<\/a><script async src=\"\/\/cdn.embedly.com\/widgets\/platform.js\" charset=\"UTF-8\"><\/script><\/p>\n<p>\u3000\u4e0a\u306e\u8a18\u4e8b\u3067\u3082\u66f8\u3044\u3066\u3044\u308b\u3088\u3046\u306b\u3001\u306a\u305c\u304bGCE\u306eHTTP\u8ca0\u8377\u5206\u6563\u306f\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u518d\u751f\u6210\u3057\u305f\u5f8c\u306b\u300110\u5206\u3050\u3089\u3044\u7d4c\u305f\u306a\u3044\u3068\u30d8\u30eb\u30b9\u30c1\u30a7\u30c3\u30af\u3092\u98db\u3070\u3057\u3066\u304f\u308c\u307e\u305b\u3093\u3002\u305d\u306e\u305f\u3081\u524d\u56de\u306fgcloud\u30b3\u30de\u30f3\u30c9\u3067\u30ed\u30fc\u30c9\u30d0\u30e9\u30f3\u30b5\u30fc\u306e\u72b6\u6cc1\u3092\u307f\u3064\u3064\u3001\u624b\u52d5\u3067\u5c11\u3057\u305a\u3064\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u518d\u751f\u6210\u3057\u3001\u5168\u90e8\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u304c\u300cUNHEALTY\u300d\u306e\u72b6\u614b\u306b\u306a\u3089\u306a\u3044\u3088\u3046\u306b\u3057\u3066\u3044\u307e\u3057\u305f\u3002<\/p>\n<h2>\u9762\u5012\u3060\u304b\u3089\u81ea\u52d5\u5316\u3057\u3088\u3046<\/h2>\n<p>\u3000\u9762\u5012\u3060\u3057\u624b\u52d5\u3067\u306f\u30b3\u30de\u30f3\u30c9\u3067\u3084\u3063\u3066\u308b\u306e\u3067\u81ea\u52d5\u5316\u3059\u308b\u3053\u3068\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u3000bash\u30b9\u30af\u30ea\u30d7\u30c8\u3067\u9014\u4e2d\u307e\u3067\u7d44\u3093\u3067\u3044\u307e\u3057\u305f\u304c\u3001\u4eca\u56de\u30eb\u30fc\u30d7\u3092\u7e70\u308a\u8fd4\u3057\u305f\u308a\u3057\u3066\u9762\u5012\u306b\u306a\u3063\u3066\u304d\u305f\u306e\u3067\u3001 Python\u304b\u3089GCE\u3092\u64cd\u4f5c\u3057\u3088\u3046\u3068\u601d\u3044\u307e\u3059\u3002\u3064\u3044\u3067\u306b\u51e6\u7406\u304c\u7d42\u308f\u3063\u305f\u3089\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u304b\u3089\u64cd\u4f5c\u3067\u304d\u308b\u96fb\u7403\u300cHue\u300d\u3092\u5149\u3089\u305b\u3066\u304a\u77e5\u3089\u305b\u3059\u308b\u3068\u3044\u3046\u300c\u304a\u307e\u3051\u300d\u4ed8\u304d\u3067\u3059&#x1f601;<\/p>\n<h2>Python3\u3092Mac\u306b\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h2>\n<p>\u3000Homebrew\u3067\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3067\u3059\u3002\u30d0\u30fc\u30b8\u30e7\u30f3\u306f3\u3092\u4f7f\u3044\u307e\u3057\u305f\u3002<\/p>\n<p>[bash]<br \/>\nbrew update<br \/>\nbrew install python3<br \/>\n[\/bash]<\/p>\n<h2>API Client Library for Python \u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h2>\n<p>\u3000Python\u304b\u3089Google Cloud Platform\u3092\u64cd\u4f5c\u3059\u308b\u305f\u3081\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3067\u3059\u3002<\/p>\n<p><a class=\"embedly-card\" href=\"https:\/\/developers.google.com\/api-client-library\/python\/apis\/compute\/v1\">Compute Engine API Client Library for Python<\/a><script async src=\"\/\/cdn.embedly.com\/widgets\/platform.js\" charset=\"UTF-8\"><\/script><\/p>\n<p>\u3000 \u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u6253\u3064\u3060\u3051\u306a\u306e\u3067\u697d\u52dd\u3002\u79c1\u306fpip3\u3067\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>[bash]<br \/>\npip3 install &#8211;upgrade google-api-python-client<br \/>\n[\/bash]<\/p>\n<h2>Hue\u3092\u64cd\u4f5c\u3059\u308b\u305f\u3081\u306b requests \u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h2>\n<p>\u3000Philips Hue\u306fREST\u3067\u64cd\u4f5c\u3059\u308b\u306e\u3067\u3001requests\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u307e\u3057\u305f\u3002<br \/>\n[bash]<br \/>\npip3 install requests<br \/>\n[\/bash]<\/p>\n<p>\u4ee5\u4e0a\u3002<\/p>\n<h2>Google \u306eAPI\u30a2\u30af\u30c6\u30a3\u30d9\u30fc\u30c8<\/h2>\n<p>\u3000\u300cAPI Manager\u300d\u306e\u4e2d\u304b\u3089\u300cCompute Engine API\u300d\u3092\u6709\u52b9\u5316\u3057\u307e\u3059\u3002\u79c1\u306e\u5834\u5408\u3001\u6700\u521d\u304b\u3089API\u306f\u6709\u52b9\u306b\u306a\u3063\u3066\u3044\u307e\u3057\u305f\u3002<\/p>\n<h2>\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u518d\u751f\u6210\u3059\u308b\u30b9\u30af\u30ea\u30d7\u30c8<\/h2>\n<p>\u3000\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u4f5c\u308a\u307e\u3057\u305f\u3002\u3068\u308a\u3042\u3048\u305a\u52d5\u3051\u3070\u3044\u3044\u3084\u7684\u306a\u611f\u3058\u3067\u4f5c\u3063\u3066\u3044\u308b\u306e\u3067\u3001\u7dba\u9e97\u3067\u306f\u306a\u3044\u3067\u3059\u3002\u30e1\u30c3\u30bb\u30fc\u30b8\u3082\u3067\u305f\u3089\u3081\u82f1\u8a9e\u3067\u3059\u3002\u96f0\u56f2\u6c17\u3067\u611f\u3058\u53d6\u3063\u3066\u3044\u305f\u3060\u3051\u308c\u3070\u3002import\u3057\u3066\u3044\u308bhue\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u30bd\u30fc\u30b9\u306f\u5f8c\u3067\u8aac\u660e\u3057\u307e\u3059\u3002<\/p>\n<p>\u3000\u3042\u3068\u3001\u5148\u306bgcloud init\u3067\u8a8d\u8a3c\u3092\u3057\u3066\u304a\u304f\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>[python title=&#8221;grecreate.py&#8221;]<br \/>\n# coding: UTF-8<br \/>\n#<br \/>\n# Python3<br \/>\n# Python\u547d\u540d\u898f\u5247<br \/>\n# http:\/\/works.surgo.jp\/translation\/pyguide.html<\/p>\n<p>import sys<br \/>\nfrom oauth2client.client import GoogleCredentials<br \/>\nfrom googleapiclient.discovery import build<br \/>\nimport json<br \/>\nimport time<br \/>\nfrom datetime import datetime<br \/>\nfrom datetime import date<br \/>\nimport hue<\/p>\n<p>credentials = GoogleCredentials.get_application_default()<br \/>\ncompute = build(&#8216;compute&#8217;, &#8216;v1&#8217;, credentials=credentials)<br \/>\nproject = &#8216;\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u540d&#8217;<br \/>\nzone = &#8216;\u30be\u30fc\u30f3\u540d&#8217;<br \/>\nins_group_name = &#8216;\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u30b0\u30eb\u30fc\u30d7\u540d&#8217;<br \/>\nbackend = &#8216;\u30d0\u30c3\u30af\u30a8\u30f3\u30c9\u540d&#8217;<br \/>\n#\u6700\u5c0f\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u6570<br \/>\nminmum_ins_num = 1<br \/>\n#\u30a6\u30a7\u30a4\u30c8(\u79d2)<br \/>\nwait = 30<br \/>\n#\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u518d\u751f\u6210\u5f8c\u30a6\u30a7\u30a4\u30c8(break\u3067\u3059\u3050\u306b\u629c\u3051\u308b\u306e\u3067)<br \/>\nrecreate_wait = 30<\/p>\n<p>def main():<\/p>\n<p>\t#\u5f15\u6570\u53d6\u5f97<br \/>\n\tparam = sys.argv<br \/>\n\tif len(param)&lt;=1:<br \/>\n\t\tprint (&#8216;ex. grecreate [target template-name]&#8217;)<br \/>\n\t\tprint (&#8216;InstanceTemplate List:&#8217;)<br \/>\n\t\tfor tmpl in getTemplateList():<br \/>\n\t\t\tprint (tmpl)<br \/>\n\t\tsys.exit()<\/p>\n<p>\ttarget_template = param[1]<br \/>\n\tprint (&#8216;Target Template Name is &#8216; + param[1])<\/p>\n<p>\tstart_time = datetime.now().isoformat()<\/p>\n<p>\tall_clear = False<\/p>\n<p>\twhile all_clear == False:<\/p>\n<p>\t\t#\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u30ea\u30b9\u30c8\u53d6\u5f97<br \/>\n\t\tinstances = getInstanceList()<\/p>\n<p>\t\tall_clear = True<\/p>\n<p>\t\tfor ins in instances:<br \/>\n\t\t\t#\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u540d\u53d6\u5f97<br \/>\n\t\t\ttmpl = getInstanceTemplate(ins)<br \/>\n\t\t\tif tmpl is None:<br \/>\n\t\t\t\t#\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u540d\u304c\u3068\u308c\u306a\u304b\u3063\u305f\u5834\u5408\u306f\u6b21\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3078\u30b9\u30ad\u30c3\u30d7<br \/>\n\t\t\t\tprint (&#8216;Can not get instance-template name&#8217;)<br \/>\n\t\t\t\tall_clear = False<br \/>\n\t\t\t\tcontinue<\/p>\n<p>\t\t\t#\u53e4\u3044\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u304b?<br \/>\n\t\t\tif tmpl != target_template:<br \/>\n\t\t\t\tprint (&#8216;Found recreate target instance : &#8216; + ins)<br \/>\n\t\t\t\t#\u53e4\u3044\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3067\u52d5\u3044\u3066\u3044\u308b\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u304c\u898b\u3064\u304b\u3063\u305f\u3089\u30d5\u30e9\u30b0\u7acb\u3066\u308b<br \/>\n\t\t\t\tall_clear = False<br \/>\n\t\t\t\t#\u6709\u52b9\u306a\u30ce\u30fc\u30c9\u304c\u8907\u6570\u3042\u308b\u304b?<br \/>\n\t\t\t\tstatus = getHttpLoadBalance()<br \/>\n\t\t\t\thealthy_count = 0<br \/>\n\t\t\t\tprint (&#8216;Instance Health Stats:&#8217;)<br \/>\n\t\t\t\tfor s in status:<br \/>\n\t\t\t\t\tprint (&#8216;    &#8216; + s[&#8216;instance&#8217;] + &#8216; : &#8216; + s[&#8216;healthState&#8217;])<br \/>\n\t\t\t\t\tif s[&#8216;healthState&#8217;] == &#8216;HEALTHY&#8217;:<br \/>\n\t\t\t\t\t\thealthy_count += 1<\/p>\n<p>\t\t\t\tif healthy_count &gt; minmum_ins_num:<br \/>\n\t\t\t\t\t#\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u518d\u751f\u6210<br \/>\n\t\t\t\t\tprint (&#8216;Instance &#8216; + ins + &#8216; recreate!&#8217;)<\/p>\n<p>\t\t\t\t\trecreateInstance(ins)<\/p>\n<p>\t\t\t\t\t#\u30d8\u30eb\u30b9\u30c1\u30a7\u30c3\u30af\u306e\u72b6\u614b\u304c\u3059\u3050\u306b\u5909\u308f\u3089\u306a\u3044\u3053\u3068\u3082\u8003\u3048\u3089\u308c\u308b\u305f\u3081\u3057\u3070\u3089\u304f\u5f85\u3064<br \/>\n\t\t\t\t\tprint (&#8216;Instance recreate after wait &#8216; + str(recreate_wait) + &#8216; second&#8217;)<br \/>\n\t\t\t\t\ttime.sleep(recreate_wait)<br \/>\n\t\t\t\telse:<br \/>\n\t\t\t\t\tprint (&#8216;A few HEALTHY instance : &#8216; + str(healthy_count) + &#8216; healthy instance. needs &#8216; + str(minmum_ins_num + 1) + &#8216; instance.&#8217;)<br \/>\n\t\t\t\t\t#HEALTY\u304c\u5c11\u306a\u3051\u308c\u3070\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u306e\u30eb\u30fc\u30d7\u7e70\u308a\u8fd4\u3057\u3066\u3082\u610f\u5473\u304c\u306a\u3044\u306e\u3067\u629c\u3051\u308b<br \/>\n\t\t\t\t\tbreak<br \/>\n\t\tif all_clear == False:<br \/>\n\t\t\t#\u30b9\u30ea\u30fc\u30d7<br \/>\n\t\t\tprint (&#8216;wait &#8216; + str(wait) + &#8216; second.&#8217;)<br \/>\n\t\t\ttime.sleep(wait)<\/p>\n<p>\tprint (&#8216;Recreate Complete!&#8217;)<br \/>\n\tprint (&#8216;Start Time :&#8217; + start_time)<br \/>\n\tprint (&#8216;End Time : &#8216; + datetime.now().isoformat())<\/p>\n<p>\thue.Hue.postAlert()<\/p>\n<p>#\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u518d\u751f\u6210<br \/>\ndef recreateInstance(instance):<br \/>\n\tbody = {<br \/>\n\t\t&#8216;instances&#8217; : [<br \/>\n\t\t\t&#8216;https:\/\/content.googleapis.com\/compute\/v1\/projects\/&#8217; + project+ &#8216;\/zones\/&#8217; + zone + &#8216;\/instances\/&#8217; + instance<br \/>\n\t\t]<br \/>\n\t}<br \/>\n\tres = compute.instanceGroupManagers().recreateInstances(project=project, zone=zone, instanceGroupManager=ins_group_name, body=body).execute()<br \/>\n\tprint (json.dumps(res, sort_keys=True, indent=4))<\/p>\n<p>#HTTP\u8ca0\u8377\u5206\u6563\u306e\u72b6\u6cc1\u3092\u53d6\u5f97<br \/>\ndef getHttpLoadBalance():<br \/>\n\tbody = {<br \/>\n\t\t&#8216;group&#8217; : &#8216;https:\/\/content.googleapis.com\/compute\/v1\/projects\/&#8217; + project+ &#8216;\/zones\/&#8217; + zone + &#8216;\/instanceGroups\/&#8217; + ins_group_name<br \/>\n\t}<br \/>\n\tres = compute.backendServices().getHealth(project=project, backendService=backend, fields=&#8217;healthStatus&#8217;, body=body).execute()<br \/>\n\tstatus = []<br \/>\n\tfor health in res[&#8216;healthStatus&#8217;]:<br \/>\n\t\t#\/\u3067\u533a\u5207\u3063\u306611\u500b\u76ee\u3092\u53d6\u5f97\u3002\u304b\u306a\u308a\u7121\u7406\u77e2\u7406\u611f\u304c\u3002<br \/>\n\t\trow = {&#8216;instance&#8217;:health[&#8216;instance&#8217;].split(&#8216;\/&#8217;)[10], &#8216;healthState&#8217;:health[&#8216;healthState&#8217;]}<br \/>\n\t\tstatus.append(row)<br \/>\n\treturn status<\/p>\n<p>#\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u306e\u30ea\u30b9\u30c8\u3092\u53d6\u5f97\u3059\u308b<br \/>\n#\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u30b0\u30eb\u30fc\u30d7\u306e\u540d\u524d\u304b\u3089\u5bfe\u8c61\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u7d5e\u308a\u8fbc\u3093\u3067\u3044\u308b<br \/>\ndef getInstanceList():<br \/>\n\t# \u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u30ea\u30b9\u30c8\u53d6\u5f97<br \/>\n\tres = compute.instances().list(project=project, zone=zone, filter=&#8217;name eq &#8216; + ins_group_name + &#8216;-.*&#8217;).execute()<br \/>\n\tinstances = []<br \/>\n\tfor ins in res[&#8216;items&#8217;]:<br \/>\n\t\tins_name = ins[&#8216;name&#8217;]<br \/>\n\t\tinstances.append(ins_name)<\/p>\n<p>\treturn instances<\/p>\n<p>#\u6307\u5b9a\u3057\u305f\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u53d6\u5f97\u3059\u308b<br \/>\ndef getInstanceTemplate(ins_name):<br \/>\n\t# \u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u53d6\u5f97<br \/>\n\tres = compute.instances().get(project=project, zone=zone, instance=ins_name).execute()<br \/>\n\tfor tmpl_name in res[&#8216;metadata&#8217;][&#8216;items&#8217;]:<br \/>\n\t\tif tmpl_name[&#8216;key&#8217;] == &#8216;instance-template&#8217;:<br \/>\n\t\t\tstrs = tmpl_name[&#8216;value&#8217;].split(&#8216;\/&#8217;)<br \/>\n\t\t\treturn strs[4]<br \/>\n\tprint (&#8216;instace-template not foud : instance name is &#8216; + ins_name)<br \/>\n\treturn None<\/p>\n<p>#\u5b9a\u7fa9\u6e08\u307f\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30ea\u30b9\u30c8\u3092\u53d6\u5f97\u3059\u308b<br \/>\ndef getTemplateList():<br \/>\n\tres = compute.instanceTemplates().list(project=project).execute()<br \/>\n\ttemplates = []<br \/>\n\tfor tmpl in res[&#8216;items&#8217;]:<br \/>\n\t\ttmpl_name = tmpl[&#8216;name&#8217;]<br \/>\n\t\ttemplates.append(tmpl_name)<br \/>\n\treturn templates<\/p>\n<p>#main\u547c\u3073\u51fa\u3057<br \/>\nif __name__ == &quot;__main__&quot;:<br \/>\n\tmain()<br \/>\n[\/python]<\/p>\n<p>\u3000\u3082\u3063\u3068\u3069\u3046\u306b\u304b\u3057\u305f\u3044\u611f\u3058\u306e\u8907\u96d1\u3055\u3067\u3059\u304c\u52d5\u3044\u3066\u3044\u308b\u306e\u3067\u3088\u3057\u3068\u3057\u307e\u3059\u3002<\/p>\n<p>\u3000\u6700\u521d\u306e\u65b9\u306e project \u3084 zone \u306f\u74b0\u5883\u306b\u5408\u308f\u305b\u3066\u66f8\u304d\u63db\u3048\u3066\u304f\u3060\u3055\u3044\u3002minmum_ins_num \u306f\u4f55\u500b HEALTHY \u306a\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u6b8b\u3057\u3066\u304a\u304f\u304b\u306e\u8a2d\u5b9a\u3067\u3059\u30021\u3092\u6307\u5b9a\u3057\u3066\u304a\u304f\u3068\u3001\u518d\u751f\u6210\u3057\u3066 HEALTHY\u306a\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u304c1\u500b\u3060\u3051\u306b\u306a\u308b\u3068\u518d\u751f\u6210\u3092\u3084\u3081\u307e\u3059\u300230\u79d2\u5f85\u3063\u3066HEALTHY\u306a\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u304c2\u500b\u4ee5\u4e0a\u306b\u306a\u3063\u305f\u3089\u3001\u518d\u751f\u6210\u3092\u518d\u958b\u3059\u308b\u3088\u3046\u306a\u52d5\u304d\u3092\u3057\u307e\u3059\u3002<\/p>\n<p>\u3000\u4e8b\u524d\u306b\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u30b0\u30eb\u30fc\u30d7\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u306b\u65b0\u3057\u3044\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<p>\u3000\u8d77\u52d5\u6642\u306e\u5f15\u6570\u3068\u3057\u3066\u3001\u65b0\u3057\u3044\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u540d\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002\u3053\u3053\u3067\u6307\u5b9a\u3057\u305f\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u4ee5\u5916\u3092\u4f7f\u3063\u3066\u3044\u308b\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u306f\u518d\u751f\u6210\u306e\u5bfe\u8c61\u306b\u306a\u308a\u307e\u3059\u3002\u6700\u7d42\u7684\u306b\u3059\u3079\u3066\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u304c\u6307\u5b9a\u3057\u305f\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u306b\u306a\u3063\u305f\u3089\u30b9\u30af\u30ea\u30d7\u30c8\u306f\u7d42\u4e86\u3057\u307e\u3059\u3002<\/p>\n<h2>\u96fb\u7403\u3092\u5149\u3089\u305b\u308b<\/h2>\n<p>\u3000Hue\u3092\u5149\u3089\u305b\u308b\u30b9\u30af\u30ea\u30d7\u30c8\u3067\u3059\u3002<\/p>\n<p>[python title=&#8221;hue.py&#8221;]<br \/>\n# coding: UTF-8<br \/>\n#<br \/>\n# Python3<br \/>\n# Python\u547d\u540d\u898f\u5247<br \/>\n# http:\/\/works.surgo.jp\/translation\/pyguide.html<\/p>\n<p>import requests<br \/>\nimport json<\/p>\n<p>hue_ip = &#8216;Hue\u306eIP\u30a2\u30c9\u30ec\u30b9&#8217;<br \/>\nuser_id = &#8216;Hue\u304b\u3089\u53d6\u5f97\u3057\u305f\u30e6\u30fc\u30b6\u30fcID&#8217;<br \/>\ntarget_light = &#8216;\u30e9\u30a4\u30c8\u306e\u756a\u53f7&#8217;<\/p>\n<p>def main():<br \/>\n\tHue.postAlert()<\/p>\n<p>class Hue(object):<br \/>\n\tdef postAlert():<br \/>\n\t\turl = &#8216;http:\/\/&#8217; + hue_ip + &#8216;\/api\/&#8217; + user_id + &#8216;\/lights\/&#8217; + target_light + &#8216;\/state&#8217;<br \/>\n\t\tbody = {&#8216;alert&#8217;: &#8216;lselect&#8217;}<br \/>\n\t\tr = requests.put(url,data=json.dumps(body))<br \/>\n\t\tprint (&#8216;Response :&#8217;), r.text<\/p>\n<p>#main\u547c\u3073\u51fa\u3057<br \/>\nif __name__ == &quot;__main__&quot;:<br \/>\n\tmain()<br \/>\n[\/python]<\/p>\n<p>\u3000\u30bd\u30fc\u30b9\u5185\u306e\u300cHue\u306eIP\u30a2\u30c9\u30ec\u30b9\u300d\u3068\u300cHue\u304b\u3089\u53d6\u5f97\u3057\u305f\u30e6\u30fc\u30b6\u30fcID\u300d\u3068\u300c\u30e9\u30a4\u30c8\u306e\u756a\u53f7\u300d\u3092\u66f8\u304d\u63db\u3048\u3066\u304f\u3060\u3055\u3044\u3002\u3053\u308c\u3089\u306b\u3064\u3044\u3066\u306fHue\u306e\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u3092\u8a66\u3059\u3068\u4f55\u3092\u8a2d\u5b9a\u3059\u308c\u3070\u3044\u3044\u304b\u308f\u304b\u308a\u307e\u3059\u300210\u5206\u3050\u3089\u3044\u3067\u5149\u3089\u305b\u308b\u3068\u3053\u308d\u307e\u3067\u3044\u3051\u308b\u3050\u3089\u3044\u7c21\u5358\u3067\u3059\u3002<\/p>\n<p><a class=\"embedly-card\" href=\"http:\/\/www.developers.meethue.com\/documentation\/getting-started\">Getting started<\/a><script async src=\"\/\/cdn.embedly.com\/widgets\/platform.js\" charset=\"UTF-8\"><\/script><\/p>\n<h2>\u81ea\u52d5\u5316\u3067\u304d\u308b\u3068\u697d\u306b\u306a\u308b<\/h2>\n<p>\u3000\u3084\u3063\u305f\u30fc\u3001\u3053\u308c\u3067\u4e00\u3064\u3081\u3093\u3069\u304f\u3055\u3044\u624b\u4f5c\u696d\u304c\u306a\u304f\u306a\u3063\u305f\u3002\u304b\u306d\u3066\u3088\u308a\u3084\u3063\u3066\u307f\u305f\u304b\u3063\u305fHue\u306e\u64cd\u4f5c\u3082\u3067\u304d\u305f\u3057\u3002Google Compute Engine\u3067\u30af\u30e9\u30a6\u30c9\u3092\u4f7f\u3044\u3001IoT\u3082\u7d61\u3081\u3066\u306a\u3093\u3060\u304b\u6700\u5148\u7aef\u3063\u307d\u3044\u3058\u3083\u306a\u3044\u304b&#x1f600;<\/p><div id=\"advads-730548337\" class=\"advads-content-placement-after-3rd-paragraph advads-entity-placement\" style=\"margin-left: auto;margin-right: auto;text-align: center;\"><div class=\"advads-adlabel\">\u5e83\u544a<\/div><script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js?client=ca-pub-7585646298782746\" crossorigin=\"anonymous\"><\/script><ins class=\"adsbygoogle\" style=\"display:inline-block;width:300px;height:250px;\" \ndata-ad-client=\"ca-pub-7585646298782746\" \ndata-ad-slot=\"6112122906\"><\/ins> \n<script> \n(adsbygoogle = window.adsbygoogle || []).push({}); \n<\/script>\n<\/div>\n<div class=\"kaerebalink-box\" style=\"text-align:left;padding-bottom:20px;font-size:small;\/zoom: 1;overflow: hidden;\">\n<div class=\"kaerebalink-image\" style=\"float:left;margin:0 15px 10px 0;\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/ecx.images-amazon.com\/images\/I\/31MoCXyqbGL._SL160_.jpg\" style=\"border: none;\" \/><\/div>\n<div class=\"kaerebalink-info\" style=\"line-height:120%;\/zoom: 1;overflow: hidden;\">\n<div class=\"kaerebalink-name\" style=\"margin-bottom:10px;line-height:120%\">Philips hue(\u30d2\u30e5\u30fc) \u30b9\u30bf\u30fc\u30bf\u30fc\u30bb\u30c3\u30c8 929000259907 \u30ea\u30c6\u30fc\u30eb\u30d1\u30c3\u30b1\u30fc\u30b8<\/p>\n<div class=\"kaerebalink-powered-date\" style=\"font-size:8pt;margin-top:5px;font-family:verdana;line-height:120%\">posted with <a href=\"http:\/\/kaereba.com\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">\u30ab\u30a8\u30ec\u30d0<\/a><\/div>\n<\/div>\n<div class=\"kaerebalink-detail\" style=\"margin-bottom:5px;\"> Philips(\u30d5\u30a3\u30ea\u30c3\u30d7\u30b9) 2014-01-26    <\/div>\n<div class=\"kaerebalink-link1\" style=\"margin-top:10px;\">\n<div class=\"shoplinkamazon\" style=\"display:inline;margin-right:5px\"><a href=\"http:\/\/www.amazon.co.jp\/gp\/search?keywords=Philips%20hue%20%83X%83%5E%81%5B%83%5E%81%5B%83Z%83b%83g&#038;__mk_ja_JP=%83J%83%5E%83J%83i&#038;tag=website1-22\" target=\"_blank\" rel=\"noopener noreferrer\">Amazon<\/a><\/div>\n<div class=\"shoplinkrakuten\" style=\"display:inline;margin-right:5px\"><a href=\"http:\/\/hb.afl.rakuten.co.jp\/hgc\/00c43777.4720bf22.0924f66c.318740e8\/?pc=http%3A%2F%2Fsearch.rakuten.co.jp%2Fsearch%2Fmall%2FPhilips%2520hue%2520%25E3%2582%25B9%25E3%2582%25BF%25E3%2583%25BC%25E3%2582%25BF%25E3%2583%25BC%25E3%2582%25BB%25E3%2583%2583%25E3%2583%2588%2F-%2Ff.1-p.1-s.1-sf.0-st.A-v.2%3Fx%3D0%26scid%3Daf_ich_link_urltxt%26m%3Dhttp%3A%2F%2Fm.rakuten.co.jp%2F\" target=\"_blank\" rel=\"noopener noreferrer\">\u697d\u5929\u5e02\u5834<\/a><\/div>\n<\/div>\n<\/div>\n<div class=\"booklink-footer\" style=\"clear: left\"><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u2028 \u3000Google Compute Engine\u306e\u30aa\u30fc\u30c8\u30b9\u30b1\u30fc\u30eb\u306e\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u5165\u308c\u66ff\u3048\u5f8c\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u518d\u751f\u6210\u3092\u30ed\u30fc\u30c9\u30d0\u30e9\u30f3\u30b5\u30fc\u306e\u72b6\u6cc1\u3092\u898b\u306a\u304c\u3089\u81ea\u52d5\u3067\u884c\u3063\u3066\u3001\u5168\u90e8\u518d\u751f\u6210\u7d42\u308f\u3063\u305f\u3089\u3001Philips Hue\u3092\u5149\u3089\u305b\u308b\u30b9\u30af\u30ea\u30d7\u30c8 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":11248,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[28],"tags":[539,535],"class_list":["post-11243","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-website","tag-google-compute-engine","tag-philips-hue"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/a-tak.com\/blog\/wp-content\/uploads\/2015\/11\/20151103gce-01.jpg?fit=1400%2C1050&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/a-tak.com\/blog\/wp-json\/wp\/v2\/posts\/11243","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/a-tak.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/a-tak.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/a-tak.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/a-tak.com\/blog\/wp-json\/wp\/v2\/comments?post=11243"}],"version-history":[{"count":0,"href":"https:\/\/a-tak.com\/blog\/wp-json\/wp\/v2\/posts\/11243\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/a-tak.com\/blog\/wp-json\/wp\/v2\/media\/11248"}],"wp:attachment":[{"href":"https:\/\/a-tak.com\/blog\/wp-json\/wp\/v2\/media?parent=11243"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/a-tak.com\/blog\/wp-json\/wp\/v2\/categories?post=11243"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/a-tak.com\/blog\/wp-json\/wp\/v2\/tags?post=11243"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}