{"action":"created","comment":{"url":"https://api.github.com/repos/theforeman/foreman/pulls/comments/32503961","id":32503961,"diff_hunk":"@@ -60,20 +63,52 @@ def zone=(zone)\n       self.url = zone\n     end\n \n-    def create_vm(args = {})\n-      #Dot are not allowed in names\n+    def new_vm(args = {})\n+      # convert rails nested_attributes into a plain hash\n+      [:volumes].each do |collection|\n+        nested_attrs = args.delete(\"#{collection}_attributes\".to_sym)\n+        args[collection] = nested_attributes_for(collection, nested_attrs) if nested_attrs\n+      end\n+\n+      # Dots are not allowed in names\n       args[:name]        = args[:name].parameterize if args[:name].present?\n-      args[:external_ip] = args[:external_ip] != '0'\n-      args[:image_name]  = args[:image_id]\n+      args[:external_ip] = args[:external_ip] == '1'\n+      # GCE network interfaces cannot be defined though Foreman yet\n+      args[:network_interfaces] = nil\n+\n+      if args[:volumes].present?\n+        if args[:image_id].present?\n+          args[:volumes].first[:source_image] = client.images.select { |i| i.id == args[:image_id] }.first.name\n+        end\n+        args[:disks] = []\n+        args[:volumes].each_with_index do |vol_args,i|\n+          args[:disks] << new_volume(vol_args.merge(:name => \"#{args[:name]}-disk#{i+1}\"))\n+        end\n+      end\n+\n+      super(args)\n+    end\n+\n+    def create_vm(args = {})\n+      new_vm(args)\n+      create_volumes(args)\n \n       username = images.where(:uuid => args[:image_name]).first.try(:username)\n       ssh      = { :username => username, :public_key => key_pair.public }\n-      super(args.merge(ssh))\n+      vm = super(args.merge(ssh))\n+      vm.disks.each { |disk| vm.set_disk_auto_delete(true, disk['deviceName']) }","path":"app/models/compute_resources/foreman/model/gce.rb","position":64,"original_position":64,"commit_id":"ab502edd6f07e1807480d31df449be4cbace2a53","original_commit_id":"ab502edd6f07e1807480d31df449be4cbace2a53","user":{"login":"domcleal","id":482089,"avatar_url":"https://avatars.githubusercontent.com/u/482089?v=3","gravatar_id":"","url":"https://api.github.com/users/domcleal","html_url":"https://github.com/domcleal","followers_url":"https://api.github.com/users/domcleal/followers","following_url":"https://api.github.com/users/domcleal/following{/other_user}","gists_url":"https://api.github.com/users/domcleal/gists{/gist_id}","starred_url":"https://api.github.com/users/domcleal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/domcleal/subscriptions","organizations_url":"https://api.github.com/users/domcleal/orgs","repos_url":"https://api.github.com/users/domcleal/repos","events_url":"https://api.github.com/users/domcleal/events{/privacy}","received_events_url":"https://api.github.com/users/domcleal/received_events","type":"User","site_admin":false},"body":"Nice fix!","created_at":"2015-06-16T09:22:34Z","updated_at":"2015-06-16T09:22:34Z","html_url":"https://github.com/theforeman/foreman/pull/2214#discussion_r32503961","pull_request_url":"https://api.github.com/repos/theforeman/foreman/pulls/2214","_links":{"self":{"href":"https://api.github.com/repos/theforeman/foreman/pulls/comments/32503961"},"html":{"href":"https://github.com/theforeman/foreman/pull/2214#discussion_r32503961"},"pull_request":{"href":"https://api.github.com/repos/theforeman/foreman/pulls/2214"}}},"pull_request":{"url":"https://api.github.com/repos/theforeman/foreman/pulls/2214","id":30241572,"html_url":"https://github.com/theforeman/foreman/pull/2214","diff_url":"https://github.com/theforeman/foreman/pull/2214.diff","patch_url":"https://github.com/theforeman/foreman/pull/2214.patch","issue_url":"https://api.github.com/repos/theforeman/foreman/issues/2214","number":2214,"state":"open","locked":false,"title":"Fixes #4551 - GCE provisioning support","user":{"login":"eLobato","id":598891,"avatar_url":"https://avatars.githubusercontent.com/u/598891?v=3","gravatar_id":"","url":"https://api.github.com/users/eLobato","html_url":"https://github.com/eLobato","followers_url":"https://api.github.com/users/eLobato/followers","following_url":"https://api.github.com/users/eLobato/following{/other_user}","gists_url":"https://api.github.com/users/eLobato/gists{/gist_id}","starred_url":"https://api.github.com/users/eLobato/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eLobato/subscriptions","organizations_url":"https://api.github.com/users/eLobato/orgs","repos_url":"https://api.github.com/users/eLobato/repos","events_url":"https://api.github.com/users/eLobato/events{/privacy}","received_events_url":"https://api.github.com/users/eLobato/received_events","type":"User","site_admin":false},"body":"Enable provisioning of VMs through Google Compute Engine. Volume-wise,\r\nthis is currently limited to creating a VM with an attached disk that\r\ncontains the image specified. Future enhancements should include\r\nchoosing any available disks to auto-attach the VM and not force the\r\nuser to create a new one through Foreman.\r\n\r\nI thought about removing disks when removing the VM as well, since disks are created at the same time as the VM. However users might attach their own disks through the GCE console and we don't want to destroy these.","created_at":"2015-03-01T12:54:41Z","updated_at":"2015-06-16T09:22:34Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d4866e81a20042ac67d01f66e3da60be09e51474","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/theforeman/foreman/pulls/2214/commits","review_comments_url":"https://api.github.com/repos/theforeman/foreman/pulls/2214/comments","review_comment_url":"https://api.github.com/repos/theforeman/foreman/pulls/comments{/number}","comments_url":"https://api.github.com/repos/theforeman/foreman/issues/2214/comments","statuses_url":"https://api.github.com/repos/theforeman/foreman/statuses/ab502edd6f07e1807480d31df449be4cbace2a53","head":{"label":"eLobato:4551","ref":"4551","sha":"ab502edd6f07e1807480d31df449be4cbace2a53","user":{"login":"eLobato","id":598891,"avatar_url":"https://avatars.githubusercontent.com/u/598891?v=3","gravatar_id":"","url":"https://api.github.com/users/eLobato","html_url":"https://github.com/eLobato","followers_url":"https://api.github.com/users/eLobato/followers","following_url":"https://api.github.com/users/eLobato/following{/other_user}","gists_url":"https://api.github.com/users/eLobato/gists{/gist_id}","starred_url":"https://api.github.com/users/eLobato/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eLobato/subscriptions","organizations_url":"https://api.github.com/users/eLobato/orgs","repos_url":"https://api.github.com/users/eLobato/repos","events_url":"https://api.github.com/users/eLobato/events{/privacy}","received_events_url":"https://api.github.com/users/eLobato/received_events","type":"User","site_admin":false},"repo":{"id":5842097,"name":"foreman","full_name":"eLobato/foreman","owner":{"login":"eLobato","id":598891,"avatar_url":"https://avatars.githubusercontent.com/u/598891?v=3","gravatar_id":"","url":"https://api.github.com/users/eLobato","html_url":"https://github.com/eLobato","followers_url":"https://api.github.com/users/eLobato/followers","following_url":"https://api.github.com/users/eLobato/following{/other_user}","gists_url":"https://api.github.com/users/eLobato/gists{/gist_id}","starred_url":"https://api.github.com/users/eLobato/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eLobato/subscriptions","organizations_url":"https://api.github.com/users/eLobato/orgs","repos_url":"https://api.github.com/users/eLobato/repos","events_url":"https://api.github.com/users/eLobato/events{/privacy}","received_events_url":"https://api.github.com/users/eLobato/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/eLobato/foreman","description":"an application that automates the lifecycle of servers ","fork":true,"url":"https://api.github.com/repos/eLobato/foreman","forks_url":"https://api.github.com/repos/eLobato/foreman/forks","keys_url":"https://api.github.com/repos/eLobato/foreman/keys{/key_id}","collaborators_url":"https://api.github.com/repos/eLobato/foreman/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/eLobato/foreman/teams","hooks_url":"https://api.github.com/repos/eLobato/foreman/hooks","issue_events_url":"https://api.github.com/repos/eLobato/foreman/issues/events{/number}","events_url":"https://api.github.com/repos/eLobato/foreman/events","assignees_url":"https://api.github.com/repos/eLobato/foreman/assignees{/user}","branches_url":"https://api.github.com/repos/eLobato/foreman/branches{/branch}","tags_url":"https://api.github.com/repos/eLobato/foreman/tags","blobs_url":"https://api.github.com/repos/eLobato/foreman/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/eLobato/foreman/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/eLobato/foreman/git/refs{/sha}","trees_url":"https://api.github.com/repos/eLobato/foreman/git/trees{/sha}","statuses_url":"https://api.github.com/repos/eLobato/foreman/statuses/{sha}","languages_url":"https://api.github.com/repos/eLobato/foreman/languages","stargazers_url":"https://api.github.com/repos/eLobato/foreman/stargazers","contributors_url":"https://api.github.com/repos/eLobato/foreman/contributors","subscribers_url":"https://api.github.com/repos/eLobato/foreman/subscribers","subscription_url":"https://api.github.com/repos/eLobato/foreman/subscription","commits_url":"https://api.github.com/repos/eLobato/foreman/commits{/sha}","git_commits_url":"https://api.github.com/repos/eLobato/foreman/git/commits{/sha}","comments_url":"https://api.github.com/repos/eLobato/foreman/comments{/number}","issue_comment_url":"https://api.github.com/repos/eLobato/foreman/issues/comments{/number}","contents_url":"https://api.github.com/repos/eLobato/foreman/contents/{+path}","compare_url":"https://api.github.com/repos/eLobato/foreman/compare/{base}...{head}","merges_url":"https://api.github.com/repos/eLobato/foreman/merges","archive_url":"https://api.github.com/repos/eLobato/foreman/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/eLobato/foreman/downloads","issues_url":"https://api.github.com/repos/eLobato/foreman/issues{/number}","pulls_url":"https://api.github.com/repos/eLobato/foreman/pulls{/number}","milestones_url":"https://api.github.com/repos/eLobato/foreman/milestones{/number}","notifications_url":"https://api.github.com/repos/eLobato/foreman/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/eLobato/foreman/labels{/name}","releases_url":"https://api.github.com/repos/eLobato/foreman/releases{/id}","created_at":"2012-09-17T14:23:49Z","updated_at":"2015-05-06T16:17:15Z","pushed_at":"2015-06-15T22:06:18Z","git_url":"git://github.com/eLobato/foreman.git","ssh_url":"git@github.com:eLobato/foreman.git","clone_url":"https://github.com/eLobato/foreman.git","svn_url":"https://github.com/eLobato/foreman","homepage":"http://theforeman.org","size":30113,"stargazers_count":1,"watchers_count":1,"language":"Ruby","has_issues":false,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":1,"default_branch":"develop"}},"base":{"label":"theforeman:develop","ref":"develop","sha":"7561872425f89155bd0306e986320753df1ff7cd","user":{"login":"theforeman","id":1439844,"avatar_url":"https://avatars.githubusercontent.com/u/1439844?v=3","gravatar_id":"","url":"https://api.github.com/users/theforeman","html_url":"https://github.com/theforeman","followers_url":"https://api.github.com/users/theforeman/followers","following_url":"https://api.github.com/users/theforeman/following{/other_user}","gists_url":"https://api.github.com/users/theforeman/gists{/gist_id}","starred_url":"https://api.github.com/users/theforeman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/theforeman/subscriptions","organizations_url":"https://api.github.com/users/theforeman/orgs","repos_url":"https://api.github.com/users/theforeman/repos","events_url":"https://api.github.com/users/theforeman/events{/privacy}","received_events_url":"https://api.github.com/users/theforeman/received_events","type":"Organization","site_admin":false},"repo":{"id":258750,"name":"foreman","full_name":"theforeman/foreman","owner":{"login":"theforeman","id":1439844,"avatar_url":"https://avatars.githubusercontent.com/u/1439844?v=3","gravatar_id":"","url":"https://api.github.com/users/theforeman","html_url":"https://github.com/theforeman","followers_url":"https://api.github.com/users/theforeman/followers","following_url":"https://api.github.com/users/theforeman/following{/other_user}","gists_url":"https://api.github.com/users/theforeman/gists{/gist_id}","starred_url":"https://api.github.com/users/theforeman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/theforeman/subscriptions","organizations_url":"https://api.github.com/users/theforeman/orgs","repos_url":"https://api.github.com/users/theforeman/repos","events_url":"https://api.github.com/users/theforeman/events{/privacy}","received_events_url":"https://api.github.com/users/theforeman/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/theforeman/foreman","description":"an application that automates the lifecycle of servers ","fork":false,"url":"https://api.github.com/repos/theforeman/foreman","forks_url":"https://api.github.com/repos/theforeman/foreman/forks","keys_url":"https://api.github.com/repos/theforeman/foreman/keys{/key_id}","collaborators_url":"https://api.github.com/repos/theforeman/foreman/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/theforeman/foreman/teams","hooks_url":"https://api.github.com/repos/theforeman/foreman/hooks","issue_events_url":"https://api.github.com/repos/theforeman/foreman/issues/events{/number}","events_url":"https://api.github.com/repos/theforeman/foreman/events","assignees_url":"https://api.github.com/repos/theforeman/foreman/assignees{/user}","branches_url":"https://api.github.com/repos/theforeman/foreman/branches{/branch}","tags_url":"https://api.github.com/repos/theforeman/foreman/tags","blobs_url":"https://api.github.com/repos/theforeman/foreman/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/theforeman/foreman/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/theforeman/foreman/git/refs{/sha}","trees_url":"https://api.github.com/repos/theforeman/foreman/git/trees{/sha}","statuses_url":"https://api.github.com/repos/theforeman/foreman/statuses/{sha}","languages_url":"https://api.github.com/repos/theforeman/foreman/languages","stargazers_url":"https://api.github.com/repos/theforeman/foreman/stargazers","contributors_url":"https://api.github.com/repos/theforeman/foreman/contributors","subscribers_url":"https://api.github.com/repos/theforeman/foreman/subscribers","subscription_url":"https://api.github.com/repos/theforeman/foreman/subscription","commits_url":"https://api.github.com/repos/theforeman/foreman/commits{/sha}","git_commits_url":"https://api.github.com/repos/theforeman/foreman/git/commits{/sha}","comments_url":"https://api.github.com/repos/theforeman/foreman/comments{/number}","issue_comment_url":"https://api.github.com/repos/theforeman/foreman/issues/comments{/number}","contents_url":"https://api.github.com/repos/theforeman/foreman/contents/{+path}","compare_url":"https://api.github.com/repos/theforeman/foreman/compare/{base}...{head}","merges_url":"https://api.github.com/repos/theforeman/foreman/merges","archive_url":"https://api.github.com/repos/theforeman/foreman/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/theforeman/foreman/downloads","issues_url":"https://api.github.com/repos/theforeman/foreman/issues{/number}","pulls_url":"https://api.github.com/repos/theforeman/foreman/pulls{/number}","milestones_url":"https://api.github.com/repos/theforeman/foreman/milestones{/number}","notifications_url":"https://api.github.com/repos/theforeman/foreman/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/theforeman/foreman/labels{/name}","releases_url":"https://api.github.com/repos/theforeman/foreman/releases{/id}","created_at":"2009-07-23T15:07:00Z","updated_at":"2015-06-15T05:29:05Z","pushed_at":"2015-06-16T09:18:33Z","git_url":"git://github.com/theforeman/foreman.git","ssh_url":"git@github.com:theforeman/foreman.git","clone_url":"https://github.com/theforeman/foreman.git","svn_url":"https://github.com/theforeman/foreman","homepage":"http://theforeman.org","size":81106,"stargazers_count":777,"watchers_count":777,"language":"Ruby","has_issues":false,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":399,"mirror_url":null,"open_issues_count":86,"forks":399,"open_issues":86,"watchers":777,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/theforeman/foreman/pulls/2214"},"html":{"href":"https://github.com/theforeman/foreman/pull/2214"},"issue":{"href":"https://api.github.com/repos/theforeman/foreman/issues/2214"},"comments":{"href":"https://api.github.com/repos/theforeman/foreman/issues/2214/comments"},"review_comments":{"href":"https://api.github.com/repos/theforeman/foreman/pulls/2214/comments"},"review_comment":{"href":"https://api.github.com/repos/theforeman/foreman/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/theforeman/foreman/pulls/2214/commits"},"statuses":{"href":"https://api.github.com/repos/theforeman/foreman/statuses/ab502edd6f07e1807480d31df449be4cbace2a53"}}}}