{"id":1325,"date":"2012-07-30T12:50:03","date_gmt":"2012-07-30T03:50:03","guid":{"rendered":"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/?p=1325"},"modified":"2016-08-29T10:03:40","modified_gmt":"2016-08-29T10:03:40","slug":"python-%e3%81%ae%e3%81%82%e3%82%8c%e3%81%93%e3%82%8c%ef%bc%88%e3%83%a2%e3%82%b8%e3%83%a5%e3%83%bc%e3%83%ab%ef%bc%89","status":"publish","type":"post","link":"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/?p=1325","title":{"rendered":"python \u306e\u3042\u308c\u3053\u308c\uff08\u30e2\u30b8\u30e5\u30fc\u30eb, path, libvirt\uff09"},"content":{"rendered":"<p>(text by kondo)<\/p>\n<p>&nbsp;<\/p>\n<p>\u30d0\u30fc\u30c1\u30e3\u30eb\u30de\u30b7\u30f3\u3092\u30b3\u30f3\u30c8\u30ed\u30fc\u30eb\u3059\u308b\u65b9\u6cd5\u3092\u63a2\u3063\u3066\u3044\u307e\u3059\u3002libvirt \u3092\u5229\u7528\u3059\u308b\u3053\u3068\u3092\u8003\u3048\u3066\u3044\u307e\u3059\u3002<\/p>\n<p style=\"padding-left: 30px;\">libvirt : <span style=\"color: #0000ff;\"><a href=\"http:\/\/libvirt.org\/\"><span style=\"color: #0000ff;\">http:\/\/libvirt.org\/<\/span><\/a><\/span><\/p>\n<p>python \u304b\u3089\u5229\u7528\u3059\u308b<span style=\"color: #0000ff;\"><a href=\"http:\/\/www.ibm.com\/developerworks\/jp\/opensource\/library\/os-python-kvm-scripting1\/\"><span style=\"color: #0000ff;\">\u8a18\u4e8b<\/span><\/a><\/span>\u3092\u898b\u3066\u3001python \u306eIDLE \u3067\u5229\u7528\u3057\u3088\u3046\u3068\u3057\u305f\u3089\u3001\u3044\u304d\u306a\u308a import libvirt \u304c\u30a8\u30e9\u30fc\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<p><a href=\"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/wp-content\/uploads\/2012\/07\/IDLE_error.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-1347\" title=\"IDLE_error\" src=\"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/wp-content\/uploads\/2012\/07\/IDLE_error-292x300.png\" alt=\"\" width=\"292\" height=\"300\" \/><\/a><\/p>\n<p>\u307e\u305a\u306f\u3001\u3069\u3093\u306a\u30e2\u30b8\u30e5\u30fc\u30eb\u304c\u3042\u308b\u304b\u8abf\u3079\u3066\u307f\u308b\u30b3\u30de\u30f3\u30c9\u3067\u3059\u3002<\/p>\n<p style=\"padding-left: 30px;\">help(&#8216;modules&#8217;)<\/p>\n<p>&nbsp;<\/p>\n<p>\u30d1\u30b9\u3092\u901a\u3057\u3066\u307f\u307e\u3057\u305f\u3002\u305f\u3076\u3093\u6b64\u51e6\u3060\u3068\u601d\u3046\u306e\u3067\u3059\u304c . . .<\/p>\n<p style=\"padding-left: 30px;\">import sys<\/p>\n<p style=\"padding-left: 30px;\">sys.path.append(&#8216;\/usr\/share\/pyshared&#8217;)<\/p>\n<p>\u7d50\u5c40\u3001\u3088\u304f\u5206\u304b\u3089\u306a\u304f\u3066\u3001IDLE (using Python-3.2) \u3068\u8868\u793a\u3055\u308c\u308b\u3082\u306e\u3067\u306f\u306a\u304f\u3001IDLE\u3068\u3060\u3051\u8868\u793a\u3055\u308c\u308b\u3082\u306e\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u3001libvirt \u304c\u6a5f\u80fd\u3059\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002\u4e0b\u306e\u56f3\u306e\u3088\u3046\u306b\u4f55\u500b\u304b\u3001IDLE\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p><a href=\"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/wp-content\/uploads\/2012\/07\/IDLE.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-1343\" title=\"IDLE\" src=\"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/wp-content\/uploads\/2012\/07\/IDLE-300x208.png\" alt=\"\" width=\"300\" height=\"208\" \/><\/a><\/p>\n<p>\u4ee5\u4e0b\u3001\u8abf\u3079\u305f\u3053\u3068\u3092\u4e26\u3079\u307e\u3059\u3002<\/p>\n<p>(1) \u5b9a\u7fa9\u3055\u308c\u305f\u30c9\u30e1\u30a4\u30f3\u3092\u8abf\u3079\u308b\uff08python \u30b7\u30a7\u30eb\u306e\u4e2d\u3067\u6253\u3064\uff09\u3002<\/p>\n<p style=\"padding-left: 30px;\">\u53c2\u7167\u30b5\u30a4\u30c8(<span style=\"color: #0000ff;\"><a href=\"http:\/\/www.ibm.com\/developerworks\/jp\/opensource\/library\/os-python-kvm-scripting1\/\"><span style=\"color: #0000ff;\">http:\/\/www.ibm.com\/developerworks\/jp\/opensource\/library\/os-python-kvm-scripting1\/<\/span><\/a><\/span>)<\/p>\n<pre style=\"padding-left: 60px;\">Python 2.7.3 (default, Apr 20 2012, 22:39:59)\n[GCC 4.6.3] on linux2\nType \"copyright\", \"credits\" or \"license()\" for more information.\n==== No Subprocess ====\n&gt;&gt;&gt; import libvirt\n&gt;&gt;&gt; conn=libvirt.open(\"qemu:\/\/\/system\")\n&gt;&gt;&gt; names = conn.listDefinedDomains()\n&gt;&gt;&gt; print names\n['sid2']\n&gt;&gt;&gt;<\/pre>\n<p>\u4eca\u306e\u3068\u3053\u308d\u3001sid2 \u3068\u3044\u3046\u540d\u524d\u306e\u30c9\u30e1\u30a4\u30f3\u304c\u3072\u3068\u3064\u3060\u3051\u306a\u306e\u3067\u3001\u4e0a\u8a18\u306e\u3088\u3046\u306b\u8868\u793a\u3055\u308c\u307e\u3059\u3002\u30c9\u30e1\u30a4\u30f3\u3068\u306f\u30d0\u30fc\u30c1\u30e3\u30eb\u30de\u30b7\u30f3\u306e\u3053\u3068\u3067\u3059\u3002<\/p>\n<p>\u95a2\u4fc2\u306a\u3044\u3051\u3069\u3001\u30ad\u30e3\u30d7\u30c1\u30e3\u30fc\u753b\u9762\u3002<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/wp-content\/uploads\/2012\/07\/libvirt.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-1334\" title=\"libvirt\" src=\"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/wp-content\/uploads\/2012\/07\/libvirt-294x300.png\" alt=\"\" width=\"294\" height=\"300\" \/><\/a><\/p>\n<p>(2) \u30d0\u30fc\u30c1\u30e3\u30eb\u30de\u30b7\u30f3\u306e\u8d77\u52d5\u3068\u505c\u6b62\uff08python \u30b7\u30a7\u30eb\u306e\u4e2d\u3067\u6253\u3064\uff09<\/p>\n<p style=\"padding-left: 30px;\">\u53c2\u8003\u30b5\u30a4\u30c8(<span style=\"color: #0000ff;\"><a href=\"http:\/\/cloud.watch.impress.co.jp\/docs\/column\/euca_iaas\/20110819_466965.html\"><span style=\"color: #0000ff;\">http:\/\/cloud.watch.impress.co.jp\/docs\/column\/euca_iaas\/20110819_466965.html<\/span><\/a><\/span>)<\/p>\n<p style=\"padding-left: 60px;\">&gt;&gt;&gt; import libvirt<br \/>\n&gt;&gt;&gt; conn=libvirt.open(&#8220;qemu:\/\/\/system&#8221;)<br \/>\n&gt;&gt;&gt; names = conn.listDefinedDomains()<br \/>\n&gt;&gt;&gt; print names<br \/>\n[&#8216;sid2&#8217;]<br \/>\n&gt;&gt;&gt; vm = conn.lookupByName(&#8216;sid2&#8217;)<br \/>\n&gt;&gt;&gt; vm.create()<br \/>\n0<br \/>\n&gt;&gt;&gt; vm.shutdown()<br \/>\n0<br \/>\n&gt;&gt;&gt;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>(text by kondo) &nbsp; \u30d0\u30fc\u30c1\u30e3\u30eb\u30de\u30b7\u30f3\u3092\u30b3\u30f3\u30c8\u30ed\u30fc\u30eb\u3059\u308b &#8230; <a class=\"more-link\" href=\"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/?p=1325\">Read More &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-1325","post","type-post","status-publish","format-standard","hentry","category-column"],"_links":{"self":[{"href":"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1325","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1325"}],"version-history":[{"count":1,"href":"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1325\/revisions"}],"predecessor-version":[{"id":4181,"href":"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1325\/revisions\/4181"}],"wp:attachment":[{"href":"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1325"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1325"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1325"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}