{"id":1047,"date":"2017-02-01T09:18:35","date_gmt":"2017-02-01T15:18:35","guid":{"rendered":"http:\/\/blog.ls-al.com\/?p=1047"},"modified":"2017-02-01T09:38:09","modified_gmt":"2017-02-01T15:38:09","slug":"system-administration-with-fabric-and-ovm","status":"publish","type":"post","link":"https:\/\/blog.ls-al.com\/system-administration-with-fabric-and-ovm\/","title":{"rendered":"System Administration with Fabric and OVM"},"content":{"rendered":"
I recently tried fabric for a few automation tasks and could use it to interact with the Oracle VM CLI. \u00a0I am using the OVM Rest API whenever possible but in some cases this may work for you. \u00a0Also I was having issues with the REST API and POST type calls so needed another method. \u00a0I have expect also for CLI interaction but fabric is a lot more python like and powerful.<\/p>\n
In addition not in this use case with OVM but if you use fabric to run against many hosts you could pretty easily get it to do parallel execution with a bit of python magic. CHeck here for great example: https:\/\/dmsimard.com\/2013\/11\/29\/capture-output-from-parallel-execution-with-fabric\/<\/p>\n
Example fabfile:<\/p>\n
\r\nimport os\r\nfrom fabric.api import *\r\nfrom fabric.colors import red, green\r\nimport re\r\n\r\ndef getprop(item,tag):\r\n item = item + ' '\r\n s=tag + ":(.*?) "\r\n ovmprop=re.findall(s, item)\r\n return ovmprop[0]\r\n\r\n\r\nenv.user = os.getenv('SSH_USER', 'admin')\r\nenv.password = os.getenv('SSH_PASSWORD', 'Welcome')\r\n\r\n# http:\/\/docs.oracle.com\/cd\/E35328_01\/E35336\/E35336.pdf\r\ndef vm_list_raw():\r\n vms=run('list vm', shell=False)\r\n print(green(vms))\r\n\r\ndef vm_create(name):\r\n run('create Vm name=' + name + ' domainType=XEN_HVM repository=ovs2 on ServerPool name=ovsPool1', shell=False)\r\n\r\ndef vm_list():\r\n with settings(hide('running', 'commands', 'stdout', 'stderr')):\r\n vms=run('list vm', shell=False).split('\\n\\r')\r\n #print(green(vms))\r\n\r\n for line in vms:\r\n if 'id' in line:\r\n id=getprop(line,'id')\r\n name=getprop(line,'name')\r\n print '{:20} {:20}'.format(id,name) \r\n<\/pre>\nExamples:<\/p>\n
\r\n$ fab -H 192.168.1.223:10000 vm_list\r\n[192.168.1.223:10000] Executing task 'vm_list'\r\n0004fb000006000048e25da9faac0ac6 VM1 \r\n\r\nDone.\r\nDisconnecting from 192.168.1.223:10000... done.\r\n\r\n$ fab -H 192.168.1.223:10000 vm_create:"name=VM6"\r\n[192.168.1.223:10000] Executing task 'vm_create'\r\n[192.168.1.223:10000] run: create Vm name=VM6 domainType=XEN_HVM repository=ovs2 on ServerPool name=ovsPool1\r\n[192.168.1.223:10000] out: OVM> create Vm name=VM6 domainType=XEN_HVM repository=ovs2 on ServerPool name=ovsPool1\r\n[192.168.1.223:10000] out: \r\n[192.168.1.223:10000] out: Command: create Vm name=VM6 domainType=XEN_HVM repository=ovs2 on ServerPool name=ovsPool1\r\n[192.168.1.223:10000] out: \r\n[192.168.1.223:10000] out: Status: Success\r\n[192.168.1.223:10000] out: \r\n[192.168.1.223:10000] out: Time: 2017-02-01 09:04:26,212 CST\r\n[192.168.1.223:10000] out: \r\n[192.168.1.223:10000] out: JobId: 1485961465970\r\n[192.168.1.223:10000] out: \r\n[192.168.1.223:10000] out: Data: \r\n[192.168.1.223:10000] out: \r\n[192.168.1.223:10000] out: id:0004fb00000600007f77133a8d591c19 name:VM6\r\n[192.168.1.223:10000] out: \r\n[192.168.1.223:10000] out: OVM> Connection closed.\r\n[192.168.1.223:10000] out: \r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"I recently tried fabric for a few automation tasks and could use it to interact with the Oracle VM CLI.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[75,29],"tags":[],"class_list":["post-1047","post","type-post","status-publish","format-standard","hentry","category-fabric","category-ovm"],"_links":{"self":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts\/1047","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/comments?post=1047"}],"version-history":[{"count":0,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts\/1047\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/media?parent=1047"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/categories?post=1047"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/tags?post=1047"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}