{"action":"created","comment":{"url":"https://api.github.com/repos/ansible/ansible-modules-extras/pulls/comments/28253208","id":28253208,"diff_hunk":"@@ -214,110 +214,168 @@\n     print \"failed=True msg='ovirtsdk required for this module'\"\n     sys.exit(1)\n \n-# ------------------------------------------------------------------- #\n-# create connection with API\n-#\n-def conn(url, user, password):\n-    api = API(url=url, username=user, password=password, insecure=True)\n-    try:\n-        value = api.test()\n-    except:\n-        print \"error connecting to the oVirt API\"\n-        sys.exit(1)\n-    return api\n-\n-# ------------------------------------------------------------------- #\n-# Create VM from scratch\n-def create_vm(conn, vmtype, vmname, zone, vmdisk_size, vmcpus, vmnic, vmnetwork, vmmem, vmdisk_alloc, sdomain, vmcores, vmos, vmdisk_int):\n-    if vmdisk_alloc == 'thin':\n+class OvirtConnection(object):\n+\n+    # ------------------------------------------------------------------- #\n+    # create connection with API\n+    #\n+    def __init__(self, url, user, password):\n+        self.conn = API(url=url, username=user, password=password, insecure=True)\n+        try:\n+            value = self.conn.test()\n+        except:\n+            print \"error connecting to the oVirt API\"\n+            sys.exit(1)\n+\n+    # ------------------------------------------------------------------- #\n+    # Create VM from scratch\n+    # Should consider splitting this up into sub steps\n+    def create_vm(self, vmtype, vmname, zone, vmdisk_size, vmcpus, vmnic, \n+            vmnetwork, vmmem, vmdisk_alloc, sdomain, vmcores, vmos, vmdisk_int):\n         # define VM params\n-        vmparams = params.VM(name=vmname,cluster=conn.clusters.get(name=zone),os=params.OperatingSystem(type_=vmos),template=conn.templates.get(name=\"Blank\"),memory=1024 * 1024 * int(vmmem),cpu=params.CPU(topology=params.CpuTopology(cores=int(vmcores))), type_=vmtype)\n-        # define disk params\n-        vmdisk= params.Disk(size=1024 * 1024 * 1024 * int(vmdisk_size), wipe_after_delete=True, sparse=True, interface=vmdisk_int, type_=\"System\", format='cow',\n-        storage_domains=params.StorageDomains(storage_domain=[conn.storagedomains.get(name=sdomain)]))\n+        vmparams = params.VM(\n+            name=vmname,\n+            cluster=self.conn.clusters.get(name=zone),\n+            os=params.OperatingSystem(type_=vmos),\n+            template=conn.templates.get(name=\"Blank\"),\n+            memory=1024 * 1024 * int(vmmem),\n+            cpu=params.CPU(topology=params.CpuTopology(cores=int(vmcores))), \n+            type_=vmtype\n+        )\n         # define network parameters\n         network_net = params.Network(name=vmnetwork)\n         nic_net1 = params.NIC(name='nic1', network=network_net, interface='virtio')\n-    elif vmdisk_alloc == 'preallocated':\n-        # define VM params\n-        vmparams = params.VM(name=vmname,cluster=conn.clusters.get(name=zone),os=params.OperatingSystem(type_=vmos),template=conn.templates.get(name=\"Blank\"),memory=1024 * 1024 * int(vmmem),cpu=params.CPU(topology=params.CpuTopology(cores=int(vmcores))) ,type_=vmtype)\n-        # define disk params\n-        vmdisk= params.Disk(size=1024 * 1024 * 1024 * int(vmdisk_size), wipe_after_delete=True, sparse=False, interface=vmdisk_int, type_=\"System\", format='raw',\n-        storage_domains=params.StorageDomains(storage_domain=[conn.storagedomains.get(name=sdomain)]))\n-        # define network parameters\n-        network_net = params.Network(name=vmnetwork)\n-        nic_net1 = params.NIC(name=vmnic, network=network_net, interface='virtio')\n-        \n-    try:\n-        conn.vms.add(vmparams)\n-    except:\n-        print \"Error creating VM with specified parameters\"\n-        sys.exit(1)\n-    vm = conn.vms.get(name=vmname)\n-    try:\n-        vm.disks.add(vmdisk)\n-    except:\n-        print \"Error attaching disk\"\n-    try:\n-        vm.nics.add(nic_net1)\n-    except:\n-        print \"Error adding nic\"\n-\n-\n-# create an instance from a template\n-def create_vm_template(conn, vmname, image, zone):\n-    vmparams = params.VM(name=vmname, cluster=conn.clusters.get(name=zone), template=conn.templates.get(name=image),disks=params.Disks(clone=True))\n-    try:\n-        conn.vms.add(vmparams)\n-    except:\n-        print 'error adding template %s' % image\n-        sys.exit(1)\n-\n-\n-# start instance\n-def vm_start(conn, vmname):\n-    vm = conn.vms.get(name=vmname)\n-    vm.start()\n-\n-# Stop instance\n-def vm_stop(conn, vmname):\n-    vm = conn.vms.get(name=vmname)\n-    vm.stop()\n-\n-# restart instance\n-def vm_restart(conn, vmname):\n-    state = vm_status(conn, vmname)\n-    vm = conn.vms.get(name=vmname)\n-    vm.stop()\n-    while conn.vms.get(vmname).get_status().get_state() != 'down':\n-        time.sleep(5)\n-    vm.start()\n-\n-# remove an instance\n-def vm_remove(conn, vmname):\n-    vm = conn.vms.get(name=vmname)\n-    vm.delete()\n-\n-# ------------------------------------------------------------------- #\n-# VM statuses\n-#\n-# Get the VMs status\n-def vm_status(conn, vmname):\n-    status = conn.vms.get(name=vmname).status.state\n-    print \"vm status is : %s\" % status\n-    return status\n-\n-\n-# Get VM object and return it's name if object exists\n-def get_vm(conn, vmname):\n-    vm = conn.vms.get(name=vmname)\n-    if vm == None:\n-        name = \"empty\"\n-        print \"vmname: %s\" % name\n-    else:\n-        name = vm.get_name()\n-        print \"vmname: %s\" % name\n-    return name\n+        storage_domains = params.StorageDomains(storage_domain=[self.conn.storagedomains.get(name=sdomain)])\n+        if vmdisk_alloc == 'thin':\n+            # define disk params\n+            vmdisk= params.Disk(\n+                size=1024 * 1024 * 1024 * int(vmdisk_size),\n+                wipe_after_delete=True,\n+                sparse=True,\n+                interface=vmdisk_int,\n+                type_=\"System\",\n+                format='cow', \n+                bootable=True,\n+                storage_domains=storage_domains)\n+        elif vmdisk_alloc == 'preallocated':","path":"cloud/misc/ovirt.py","position":147,"original_position":147,"commit_id":"88ffed5bcb4953a3a6b046c177a1b29c38f92e64","original_commit_id":"88ffed5bcb4953a3a6b046c177a1b29c38f92e64","user":{"login":"bcoca","id":836171,"avatar_url":"https://avatars.githubusercontent.com/u/836171?v=3","gravatar_id":"","url":"https://api.github.com/users/bcoca","html_url":"https://github.com/bcoca","followers_url":"https://api.github.com/users/bcoca/followers","following_url":"https://api.github.com/users/bcoca/following{/other_user}","gists_url":"https://api.github.com/users/bcoca/gists{/gist_id}","starred_url":"https://api.github.com/users/bcoca/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bcoca/subscriptions","organizations_url":"https://api.github.com/users/bcoca/orgs","repos_url":"https://api.github.com/users/bcoca/repos","events_url":"https://api.github.com/users/bcoca/events{/privacy}","received_events_url":"https://api.github.com/users/bcoca/received_events","type":"User","site_admin":false},"body":"if the olny difference here is the sparse parameter, it seems cleaner to just populate a var with it and assign","created_at":"2015-04-13T16:21:30Z","updated_at":"2015-04-13T16:21:30Z","html_url":"https://github.com/ansible/ansible-modules-extras/pull/388#discussion_r28253208","pull_request_url":"https://api.github.com/repos/ansible/ansible-modules-extras/pulls/388","_links":{"self":{"href":"https://api.github.com/repos/ansible/ansible-modules-extras/pulls/comments/28253208"},"html":{"href":"https://github.com/ansible/ansible-modules-extras/pull/388#discussion_r28253208"},"pull_request":{"href":"https://api.github.com/repos/ansible/ansible-modules-extras/pulls/388"}}},"pull_request":{"url":"https://api.github.com/repos/ansible/ansible-modules-extras/pulls/388","id":33117788,"html_url":"https://github.com/ansible/ansible-modules-extras/pull/388","diff_url":"https://github.com/ansible/ansible-modules-extras/pull/388.diff","patch_url":"https://github.com/ansible/ansible-modules-extras/pull/388.patch","issue_url":"https://api.github.com/repos/ansible/ansible-modules-extras/issues/388","number":388,"state":"open","locked":false,"title":"Refactor of the Ovirt module to remove duplicate code and cleanup","user":{"login":"Firstyear","id":271005,"avatar_url":"https://avatars.githubusercontent.com/u/271005?v=3","gravatar_id":"","url":"https://api.github.com/users/Firstyear","html_url":"https://github.com/Firstyear","followers_url":"https://api.github.com/users/Firstyear/followers","following_url":"https://api.github.com/users/Firstyear/following{/other_user}","gists_url":"https://api.github.com/users/Firstyear/gists{/gist_id}","starred_url":"https://api.github.com/users/Firstyear/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Firstyear/subscriptions","organizations_url":"https://api.github.com/users/Firstyear/orgs","repos_url":"https://api.github.com/users/Firstyear/repos","events_url":"https://api.github.com/users/Firstyear/events{/privacy}","received_events_url":"https://api.github.com/users/Firstyear/received_events","type":"User","site_admin":false},"body":"I am cleaning up the ovirt module before I work to add support for new features. This change includes:\r\n\r\n* Move functions into class.\r\n* Fix up various components that relied on these functions.\r\n* Remove duplicate code in create_vm.\r\n* Refactor create_vm.","created_at":"2015-04-12T10:04:15Z","updated_at":"2015-04-13T16:21:30Z","closed_at":null,"merged_at":null,"merge_commit_sha":"de6e8e2f72f621a7b0760cdf1fa672acb01ec7d2","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ansible/ansible-modules-extras/pulls/388/commits","review_comments_url":"https://api.github.com/repos/ansible/ansible-modules-extras/pulls/388/comments","review_comment_url":"https://api.github.com/repos/ansible/ansible-modules-extras/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ansible/ansible-modules-extras/issues/388/comments","statuses_url":"https://api.github.com/repos/ansible/ansible-modules-extras/statuses/88ffed5bcb4953a3a6b046c177a1b29c38f92e64","head":{"label":"Firstyear:devel","ref":"devel","sha":"88ffed5bcb4953a3a6b046c177a1b29c38f92e64","user":{"login":"Firstyear","id":271005,"avatar_url":"https://avatars.githubusercontent.com/u/271005?v=3","gravatar_id":"","url":"https://api.github.com/users/Firstyear","html_url":"https://github.com/Firstyear","followers_url":"https://api.github.com/users/Firstyear/followers","following_url":"https://api.github.com/users/Firstyear/following{/other_user}","gists_url":"https://api.github.com/users/Firstyear/gists{/gist_id}","starred_url":"https://api.github.com/users/Firstyear/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Firstyear/subscriptions","organizations_url":"https://api.github.com/users/Firstyear/orgs","repos_url":"https://api.github.com/users/Firstyear/repos","events_url":"https://api.github.com/users/Firstyear/events{/privacy}","received_events_url":"https://api.github.com/users/Firstyear/received_events","type":"User","site_admin":false},"repo":{"id":33802768,"name":"ansible-modules-extras","full_name":"Firstyear/ansible-modules-extras","owner":{"login":"Firstyear","id":271005,"avatar_url":"https://avatars.githubusercontent.com/u/271005?v=3","gravatar_id":"","url":"https://api.github.com/users/Firstyear","html_url":"https://github.com/Firstyear","followers_url":"https://api.github.com/users/Firstyear/followers","following_url":"https://api.github.com/users/Firstyear/following{/other_user}","gists_url":"https://api.github.com/users/Firstyear/gists{/gist_id}","starred_url":"https://api.github.com/users/Firstyear/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Firstyear/subscriptions","organizations_url":"https://api.github.com/users/Firstyear/orgs","repos_url":"https://api.github.com/users/Firstyear/repos","events_url":"https://api.github.com/users/Firstyear/events{/privacy}","received_events_url":"https://api.github.com/users/Firstyear/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Firstyear/ansible-modules-extras","description":"Ansible extra modules - these modules ship with ansible","fork":true,"url":"https://api.github.com/repos/Firstyear/ansible-modules-extras","forks_url":"https://api.github.com/repos/Firstyear/ansible-modules-extras/forks","keys_url":"https://api.github.com/repos/Firstyear/ansible-modules-extras/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Firstyear/ansible-modules-extras/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Firstyear/ansible-modules-extras/teams","hooks_url":"https://api.github.com/repos/Firstyear/ansible-modules-extras/hooks","issue_events_url":"https://api.github.com/repos/Firstyear/ansible-modules-extras/issues/events{/number}","events_url":"https://api.github.com/repos/Firstyear/ansible-modules-extras/events","assignees_url":"https://api.github.com/repos/Firstyear/ansible-modules-extras/assignees{/user}","branches_url":"https://api.github.com/repos/Firstyear/ansible-modules-extras/branches{/branch}","tags_url":"https://api.github.com/repos/Firstyear/ansible-modules-extras/tags","blobs_url":"https://api.github.com/repos/Firstyear/ansible-modules-extras/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Firstyear/ansible-modules-extras/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Firstyear/ansible-modules-extras/git/refs{/sha}","trees_url":"https://api.github.com/repos/Firstyear/ansible-modules-extras/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Firstyear/ansible-modules-extras/statuses/{sha}","languages_url":"https://api.github.com/repos/Firstyear/ansible-modules-extras/languages","stargazers_url":"https://api.github.com/repos/Firstyear/ansible-modules-extras/stargazers","contributors_url":"https://api.github.com/repos/Firstyear/ansible-modules-extras/contributors","subscribers_url":"https://api.github.com/repos/Firstyear/ansible-modules-extras/subscribers","subscription_url":"https://api.github.com/repos/Firstyear/ansible-modules-extras/subscription","commits_url":"https://api.github.com/repos/Firstyear/ansible-modules-extras/commits{/sha}","git_commits_url":"https://api.github.com/repos/Firstyear/ansible-modules-extras/git/commits{/sha}","comments_url":"https://api.github.com/repos/Firstyear/ansible-modules-extras/comments{/number}","issue_comment_url":"https://api.github.com/repos/Firstyear/ansible-modules-extras/issues/comments{/number}","contents_url":"https://api.github.com/repos/Firstyear/ansible-modules-extras/contents/{+path}","compare_url":"https://api.github.com/repos/Firstyear/ansible-modules-extras/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Firstyear/ansible-modules-extras/merges","archive_url":"https://api.github.com/repos/Firstyear/ansible-modules-extras/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Firstyear/ansible-modules-extras/downloads","issues_url":"https://api.github.com/repos/Firstyear/ansible-modules-extras/issues{/number}","pulls_url":"https://api.github.com/repos/Firstyear/ansible-modules-extras/pulls{/number}","milestones_url":"https://api.github.com/repos/Firstyear/ansible-modules-extras/milestones{/number}","notifications_url":"https://api.github.com/repos/Firstyear/ansible-modules-extras/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Firstyear/ansible-modules-extras/labels{/name}","releases_url":"https://api.github.com/repos/Firstyear/ansible-modules-extras/releases{/id}","created_at":"2015-04-12T04:18:01Z","updated_at":"2015-04-12T11:24:28Z","pushed_at":"2015-04-12T11:24:26Z","git_url":"git://github.com/Firstyear/ansible-modules-extras.git","ssh_url":"git@github.com:Firstyear/ansible-modules-extras.git","clone_url":"https://github.com/Firstyear/ansible-modules-extras.git","svn_url":"https://github.com/Firstyear/ansible-modules-extras","homepage":"","size":15906,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"devel"}},"base":{"label":"ansible:devel","ref":"devel","sha":"04aa579f1f5f122f0c7cf1a6b30dc067d27a2c7b","user":{"login":"ansible","id":1507452,"avatar_url":"https://avatars.githubusercontent.com/u/1507452?v=3","gravatar_id":"","url":"https://api.github.com/users/ansible","html_url":"https://github.com/ansible","followers_url":"https://api.github.com/users/ansible/followers","following_url":"https://api.github.com/users/ansible/following{/other_user}","gists_url":"https://api.github.com/users/ansible/gists{/gist_id}","starred_url":"https://api.github.com/users/ansible/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ansible/subscriptions","organizations_url":"https://api.github.com/users/ansible/orgs","repos_url":"https://api.github.com/users/ansible/repos","events_url":"https://api.github.com/users/ansible/events{/privacy}","received_events_url":"https://api.github.com/users/ansible/received_events","type":"Organization","site_admin":false},"repo":{"id":24474138,"name":"ansible-modules-extras","full_name":"ansible/ansible-modules-extras","owner":{"login":"ansible","id":1507452,"avatar_url":"https://avatars.githubusercontent.com/u/1507452?v=3","gravatar_id":"","url":"https://api.github.com/users/ansible","html_url":"https://github.com/ansible","followers_url":"https://api.github.com/users/ansible/followers","following_url":"https://api.github.com/users/ansible/following{/other_user}","gists_url":"https://api.github.com/users/ansible/gists{/gist_id}","starred_url":"https://api.github.com/users/ansible/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ansible/subscriptions","organizations_url":"https://api.github.com/users/ansible/orgs","repos_url":"https://api.github.com/users/ansible/repos","events_url":"https://api.github.com/users/ansible/events{/privacy}","received_events_url":"https://api.github.com/users/ansible/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ansible/ansible-modules-extras","description":"Ansible extra modules - these modules ship with ansible","fork":false,"url":"https://api.github.com/repos/ansible/ansible-modules-extras","forks_url":"https://api.github.com/repos/ansible/ansible-modules-extras/forks","keys_url":"https://api.github.com/repos/ansible/ansible-modules-extras/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ansible/ansible-modules-extras/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ansible/ansible-modules-extras/teams","hooks_url":"https://api.github.com/repos/ansible/ansible-modules-extras/hooks","issue_events_url":"https://api.github.com/repos/ansible/ansible-modules-extras/issues/events{/number}","events_url":"https://api.github.com/repos/ansible/ansible-modules-extras/events","assignees_url":"https://api.github.com/repos/ansible/ansible-modules-extras/assignees{/user}","branches_url":"https://api.github.com/repos/ansible/ansible-modules-extras/branches{/branch}","tags_url":"https://api.github.com/repos/ansible/ansible-modules-extras/tags","blobs_url":"https://api.github.com/repos/ansible/ansible-modules-extras/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ansible/ansible-modules-extras/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ansible/ansible-modules-extras/git/refs{/sha}","trees_url":"https://api.github.com/repos/ansible/ansible-modules-extras/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ansible/ansible-modules-extras/statuses/{sha}","languages_url":"https://api.github.com/repos/ansible/ansible-modules-extras/languages","stargazers_url":"https://api.github.com/repos/ansible/ansible-modules-extras/stargazers","contributors_url":"https://api.github.com/repos/ansible/ansible-modules-extras/contributors","subscribers_url":"https://api.github.com/repos/ansible/ansible-modules-extras/subscribers","subscription_url":"https://api.github.com/repos/ansible/ansible-modules-extras/subscription","commits_url":"https://api.github.com/repos/ansible/ansible-modules-extras/commits{/sha}","git_commits_url":"https://api.github.com/repos/ansible/ansible-modules-extras/git/commits{/sha}","comments_url":"https://api.github.com/repos/ansible/ansible-modules-extras/comments{/number}","issue_comment_url":"https://api.github.com/repos/ansible/ansible-modules-extras/issues/comments{/number}","contents_url":"https://api.github.com/repos/ansible/ansible-modules-extras/contents/{+path}","compare_url":"https://api.github.com/repos/ansible/ansible-modules-extras/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ansible/ansible-modules-extras/merges","archive_url":"https://api.github.com/repos/ansible/ansible-modules-extras/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ansible/ansible-modules-extras/downloads","issues_url":"https://api.github.com/repos/ansible/ansible-modules-extras/issues{/number}","pulls_url":"https://api.github.com/repos/ansible/ansible-modules-extras/pulls{/number}","milestones_url":"https://api.github.com/repos/ansible/ansible-modules-extras/milestones{/number}","notifications_url":"https://api.github.com/repos/ansible/ansible-modules-extras/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ansible/ansible-modules-extras/labels{/name}","releases_url":"https://api.github.com/repos/ansible/ansible-modules-extras/releases{/id}","created_at":"2014-09-25T20:28:42Z","updated_at":"2015-04-13T16:16:21Z","pushed_at":"2015-04-13T16:16:19Z","git_url":"git://github.com/ansible/ansible-modules-extras.git","ssh_url":"git@github.com:ansible/ansible-modules-extras.git","clone_url":"https://github.com/ansible/ansible-modules-extras.git","svn_url":"https://github.com/ansible/ansible-modules-extras","homepage":"","size":15906,"stargazers_count":166,"watchers_count":166,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":368,"mirror_url":null,"open_issues_count":162,"forks":368,"open_issues":162,"watchers":166,"default_branch":"devel"}},"_links":{"self":{"href":"https://api.github.com/repos/ansible/ansible-modules-extras/pulls/388"},"html":{"href":"https://github.com/ansible/ansible-modules-extras/pull/388"},"issue":{"href":"https://api.github.com/repos/ansible/ansible-modules-extras/issues/388"},"comments":{"href":"https://api.github.com/repos/ansible/ansible-modules-extras/issues/388/comments"},"review_comments":{"href":"https://api.github.com/repos/ansible/ansible-modules-extras/pulls/388/comments"},"review_comment":{"href":"https://api.github.com/repos/ansible/ansible-modules-extras/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ansible/ansible-modules-extras/pulls/388/commits"},"statuses":{"href":"https://api.github.com/repos/ansible/ansible-modules-extras/statuses/88ffed5bcb4953a3a6b046c177a1b29c38f92e64"}}}}