{"action":"created","comment":{"url":"https://api.github.com/repos/xapi-project/xen-api/pulls/comments/37403452","id":37403452,"diff_hunk":"@@ -23,6 +23,87 @@ open Threadext\n module D=Debug.Make(struct let name=\"xapi\" end)\n open D\n \n+(* Attach the rrd-stats vdi to dom0 and get the device *)\n+let get_rrd_vdi_device ~__context ~vdi =\n+\tlet open Db_filter_types in\n+\tlet vbds = Db.VBD.get_refs_where ~__context ~expr:(And (\n+\t\tEq (Field \"VDI\", Literal (Ref.string_of vdi)),\n+\t\tEq (Field \"currently_attached\", Literal \"true\"))\n+\t) in\n+\tlet (vbd, device) =\n+\t\tmatch vbds with\n+\t\t| vbd :: _ -> (vbd, Db.VBD.get_device ~__context ~self:vbd)\n+\t\t| [] -> begin\n+\t\t\tlet dom0 = Helpers.get_domain_zero ~__context in\n+\t\t\tlet vbd = Helpers.call_api_functions ~__context (fun rpc session_id ->\n+\t\t\t\tClient.VBD.create ~rpc ~session_id ~vM:dom0 ~vDI:vdi ~mode:`RW ~_type:`Disk\n+\t\t\t\t~empty:false ~userdevice:\"autodetect\" ~bootable:false ~unpluggable:true\n+\t\t\t\t~qos_algorithm_type:\"\" ~qos_algorithm_params:[] ~other_config:[] )\n+\t\t\tin\n+\t\t\tHelpers.call_api_functions ~__context (fun rpc session_id ->\n+\t\t\t\tClient.VBD.plug ~rpc ~session_id ~self:vbd);\n+\t\t\t(vbd, Db.VBD.get_device ~__context ~self:vbd)\n+\t\tend\n+\tin\n+\t(vbd, device)\n+\n+(* Detach the rrd-stats vdi *)\n+let detach_rrd_vdi ~__context ~vbd =\n+\tHelpers.call_api_functions ~__context (fun rpc session_id ->\n+\t\tClient.VBD.unplug ~rpc ~session_id ~self:vbd);\n+\tHelpers.call_api_functions ~__context (fun rpc session_id ->\n+\t\tClient.VBD.destroy ~rpc ~session_id ~self:vbd)\n+\n+(* Construct the CStruct for the rrd-stats vdi *)\n+let open_rrd_file ~device ~mode =\n+\tlet path = \"/dev/\" ^ device in\n+\tlet fd = Unix.openfile path mode 0 in\n+\tlet size = 4194304 in\n+\tlet mapping = Bigarray.(Array1.map_file fd char c_layout true size) in\n+\tUnix.close fd;\n+\tlet cstruct = Cstruct.of_bigarray mapping in\n+\tcstruct\n+\n+let format_rrd_vdi ~cstruct ~magic_number =\n+\tlet version = 1 and length = 0 in\n+\tCstruct.BE.set_uint32 cstruct 0 magic_number;\n+\tCstruct.BE.set_uint32 cstruct 4 (Int32.of_int version);\n+\tCstruct.BE.set_uint32 cstruct 8 (Int32.of_int length)\n+\n+(* Write the rrd stats to the rrd-stats vdi *)\n+let write_rrd ~__context ~sr ~vdi ~text =\n+\tlet magic_number = (Int32.of_int 0x7ada7ada) in","path":"ocaml/xapi/xapi_vdi_helpers.ml","position":53,"original_position":53,"commit_id":"2429b45b37bf08d6cc2a21319df5d48498b7f8c5","original_commit_id":"2429b45b37bf08d6cc2a21319df5d48498b7f8c5","user":{"login":"euanh","id":789066,"avatar_url":"https://avatars.githubusercontent.com/u/789066?v=3","gravatar_id":"","url":"https://api.github.com/users/euanh","html_url":"https://github.com/euanh","followers_url":"https://api.github.com/users/euanh/followers","following_url":"https://api.github.com/users/euanh/following{/other_user}","gists_url":"https://api.github.com/users/euanh/gists{/gist_id}","starred_url":"https://api.github.com/users/euanh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/euanh/subscriptions","organizations_url":"https://api.github.com/users/euanh/orgs","repos_url":"https://api.github.com/users/euanh/repos","events_url":"https://api.github.com/users/euanh/events{/privacy}","received_events_url":"https://api.github.com/users/euanh/received_events","type":"User","site_admin":false},"body":"This magic number is used below.   Can you pull it out into a single definition?","created_at":"2015-08-19T11:15:50Z","updated_at":"2015-08-19T11:15:50Z","html_url":"https://github.com/xapi-project/xen-api/pull/2338#discussion_r37403452","pull_request_url":"https://api.github.com/repos/xapi-project/xen-api/pulls/2338","_links":{"self":{"href":"https://api.github.com/repos/xapi-project/xen-api/pulls/comments/37403452"},"html":{"href":"https://github.com/xapi-project/xen-api/pull/2338#discussion_r37403452"},"pull_request":{"href":"https://api.github.com/repos/xapi-project/xen-api/pulls/2338"}}},"pull_request":{"url":"https://api.github.com/repos/xapi-project/xen-api/pulls/2338","id":42434330,"html_url":"https://github.com/xapi-project/xen-api/pull/2338","diff_url":"https://github.com/xapi-project/xen-api/pull/2338.diff","patch_url":"https://github.com/xapi-project/xen-api/pull/2338.patch","issue_url":"https://api.github.com/repos/xapi-project/xen-api/issues/2338","number":2338,"state":"open","locked":false,"title":"CP-13491: Read-Write RRDs into the RRD VDI","user":{"login":"sharady","id":4865661,"avatar_url":"https://avatars.githubusercontent.com/u/4865661?v=3","gravatar_id":"","url":"https://api.github.com/users/sharady","html_url":"https://github.com/sharady","followers_url":"https://api.github.com/users/sharady/followers","following_url":"https://api.github.com/users/sharady/following{/other_user}","gists_url":"https://api.github.com/users/sharady/gists{/gist_id}","starred_url":"https://api.github.com/users/sharady/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sharady/subscriptions","organizations_url":"https://api.github.com/users/sharady/orgs","repos_url":"https://api.github.com/users/sharady/repos","events_url":"https://api.github.com/users/sharady/events{/privacy}","received_events_url":"https://api.github.com/users/sharady/received_events","type":"User","site_admin":false},"body":"1) New API write_rrd: will append the RRDs to the rrd-stats VDI\r\n2) New API read_rrd: will read the RRDs from the rrd-stats VDI\r\n\r\nSigned-off-by: Sharad Yadav <sharad.yadav@citrix.com>","created_at":"2015-08-14T08:34:51Z","updated_at":"2015-08-19T11:15:50Z","closed_at":null,"merged_at":null,"merge_commit_sha":"344600c521bb2f952e53963b88ea7f95ec353abd","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/xapi-project/xen-api/pulls/2338/commits","review_comments_url":"https://api.github.com/repos/xapi-project/xen-api/pulls/2338/comments","review_comment_url":"https://api.github.com/repos/xapi-project/xen-api/pulls/comments{/number}","comments_url":"https://api.github.com/repos/xapi-project/xen-api/issues/2338/comments","statuses_url":"https://api.github.com/repos/xapi-project/xen-api/statuses/2429b45b37bf08d6cc2a21319df5d48498b7f8c5","head":{"label":"sharady:CP-13491","ref":"CP-13491","sha":"2429b45b37bf08d6cc2a21319df5d48498b7f8c5","user":{"login":"sharady","id":4865661,"avatar_url":"https://avatars.githubusercontent.com/u/4865661?v=3","gravatar_id":"","url":"https://api.github.com/users/sharady","html_url":"https://github.com/sharady","followers_url":"https://api.github.com/users/sharady/followers","following_url":"https://api.github.com/users/sharady/following{/other_user}","gists_url":"https://api.github.com/users/sharady/gists{/gist_id}","starred_url":"https://api.github.com/users/sharady/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sharady/subscriptions","organizations_url":"https://api.github.com/users/sharady/orgs","repos_url":"https://api.github.com/users/sharady/repos","events_url":"https://api.github.com/users/sharady/events{/privacy}","received_events_url":"https://api.github.com/users/sharady/received_events","type":"User","site_admin":false},"repo":{"id":24841127,"name":"xen-api","full_name":"sharady/xen-api","owner":{"login":"sharady","id":4865661,"avatar_url":"https://avatars.githubusercontent.com/u/4865661?v=3","gravatar_id":"","url":"https://api.github.com/users/sharady","html_url":"https://github.com/sharady","followers_url":"https://api.github.com/users/sharady/followers","following_url":"https://api.github.com/users/sharady/following{/other_user}","gists_url":"https://api.github.com/users/sharady/gists{/gist_id}","starred_url":"https://api.github.com/users/sharady/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sharady/subscriptions","organizations_url":"https://api.github.com/users/sharady/orgs","repos_url":"https://api.github.com/users/sharady/repos","events_url":"https://api.github.com/users/sharady/events{/privacy}","received_events_url":"https://api.github.com/users/sharady/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/sharady/xen-api","description":"The Xapi Project's XenAPI Server","fork":true,"url":"https://api.github.com/repos/sharady/xen-api","forks_url":"https://api.github.com/repos/sharady/xen-api/forks","keys_url":"https://api.github.com/repos/sharady/xen-api/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sharady/xen-api/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sharady/xen-api/teams","hooks_url":"https://api.github.com/repos/sharady/xen-api/hooks","issue_events_url":"https://api.github.com/repos/sharady/xen-api/issues/events{/number}","events_url":"https://api.github.com/repos/sharady/xen-api/events","assignees_url":"https://api.github.com/repos/sharady/xen-api/assignees{/user}","branches_url":"https://api.github.com/repos/sharady/xen-api/branches{/branch}","tags_url":"https://api.github.com/repos/sharady/xen-api/tags","blobs_url":"https://api.github.com/repos/sharady/xen-api/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sharady/xen-api/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sharady/xen-api/git/refs{/sha}","trees_url":"https://api.github.com/repos/sharady/xen-api/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sharady/xen-api/statuses/{sha}","languages_url":"https://api.github.com/repos/sharady/xen-api/languages","stargazers_url":"https://api.github.com/repos/sharady/xen-api/stargazers","contributors_url":"https://api.github.com/repos/sharady/xen-api/contributors","subscribers_url":"https://api.github.com/repos/sharady/xen-api/subscribers","subscription_url":"https://api.github.com/repos/sharady/xen-api/subscription","commits_url":"https://api.github.com/repos/sharady/xen-api/commits{/sha}","git_commits_url":"https://api.github.com/repos/sharady/xen-api/git/commits{/sha}","comments_url":"https://api.github.com/repos/sharady/xen-api/comments{/number}","issue_comment_url":"https://api.github.com/repos/sharady/xen-api/issues/comments{/number}","contents_url":"https://api.github.com/repos/sharady/xen-api/contents/{+path}","compare_url":"https://api.github.com/repos/sharady/xen-api/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sharady/xen-api/merges","archive_url":"https://api.github.com/repos/sharady/xen-api/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sharady/xen-api/downloads","issues_url":"https://api.github.com/repos/sharady/xen-api/issues{/number}","pulls_url":"https://api.github.com/repos/sharady/xen-api/pulls{/number}","milestones_url":"https://api.github.com/repos/sharady/xen-api/milestones{/number}","notifications_url":"https://api.github.com/repos/sharady/xen-api/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sharady/xen-api/labels{/name}","releases_url":"https://api.github.com/repos/sharady/xen-api/releases{/id}","created_at":"2014-10-06T10:05:17Z","updated_at":"2014-09-25T07:06:19Z","pushed_at":"2015-08-19T05:40:07Z","git_url":"git://github.com/sharady/xen-api.git","ssh_url":"git@github.com:sharady/xen-api.git","clone_url":"https://github.com/sharady/xen-api.git","svn_url":"https://github.com/sharady/xen-api","homepage":"http://xenproject.org/developers/teams/xapi.html","size":28405,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"xapi-project:master","ref":"master","sha":"3f25415420a215728a618e9dde3493ed54eae2f8","user":{"login":"xapi-project","id":317268,"avatar_url":"https://avatars.githubusercontent.com/u/317268?v=3","gravatar_id":"","url":"https://api.github.com/users/xapi-project","html_url":"https://github.com/xapi-project","followers_url":"https://api.github.com/users/xapi-project/followers","following_url":"https://api.github.com/users/xapi-project/following{/other_user}","gists_url":"https://api.github.com/users/xapi-project/gists{/gist_id}","starred_url":"https://api.github.com/users/xapi-project/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xapi-project/subscriptions","organizations_url":"https://api.github.com/users/xapi-project/orgs","repos_url":"https://api.github.com/users/xapi-project/repos","events_url":"https://api.github.com/users/xapi-project/events{/privacy}","received_events_url":"https://api.github.com/users/xapi-project/received_events","type":"Organization","site_admin":false},"repo":{"id":960233,"name":"xen-api","full_name":"xapi-project/xen-api","owner":{"login":"xapi-project","id":317268,"avatar_url":"https://avatars.githubusercontent.com/u/317268?v=3","gravatar_id":"","url":"https://api.github.com/users/xapi-project","html_url":"https://github.com/xapi-project","followers_url":"https://api.github.com/users/xapi-project/followers","following_url":"https://api.github.com/users/xapi-project/following{/other_user}","gists_url":"https://api.github.com/users/xapi-project/gists{/gist_id}","starred_url":"https://api.github.com/users/xapi-project/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xapi-project/subscriptions","organizations_url":"https://api.github.com/users/xapi-project/orgs","repos_url":"https://api.github.com/users/xapi-project/repos","events_url":"https://api.github.com/users/xapi-project/events{/privacy}","received_events_url":"https://api.github.com/users/xapi-project/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/xapi-project/xen-api","description":"The Xapi Project's XenAPI Server","fork":false,"url":"https://api.github.com/repos/xapi-project/xen-api","forks_url":"https://api.github.com/repos/xapi-project/xen-api/forks","keys_url":"https://api.github.com/repos/xapi-project/xen-api/keys{/key_id}","collaborators_url":"https://api.github.com/repos/xapi-project/xen-api/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/xapi-project/xen-api/teams","hooks_url":"https://api.github.com/repos/xapi-project/xen-api/hooks","issue_events_url":"https://api.github.com/repos/xapi-project/xen-api/issues/events{/number}","events_url":"https://api.github.com/repos/xapi-project/xen-api/events","assignees_url":"https://api.github.com/repos/xapi-project/xen-api/assignees{/user}","branches_url":"https://api.github.com/repos/xapi-project/xen-api/branches{/branch}","tags_url":"https://api.github.com/repos/xapi-project/xen-api/tags","blobs_url":"https://api.github.com/repos/xapi-project/xen-api/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/xapi-project/xen-api/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/xapi-project/xen-api/git/refs{/sha}","trees_url":"https://api.github.com/repos/xapi-project/xen-api/git/trees{/sha}","statuses_url":"https://api.github.com/repos/xapi-project/xen-api/statuses/{sha}","languages_url":"https://api.github.com/repos/xapi-project/xen-api/languages","stargazers_url":"https://api.github.com/repos/xapi-project/xen-api/stargazers","contributors_url":"https://api.github.com/repos/xapi-project/xen-api/contributors","subscribers_url":"https://api.github.com/repos/xapi-project/xen-api/subscribers","subscription_url":"https://api.github.com/repos/xapi-project/xen-api/subscription","commits_url":"https://api.github.com/repos/xapi-project/xen-api/commits{/sha}","git_commits_url":"https://api.github.com/repos/xapi-project/xen-api/git/commits{/sha}","comments_url":"https://api.github.com/repos/xapi-project/xen-api/comments{/number}","issue_comment_url":"https://api.github.com/repos/xapi-project/xen-api/issues/comments{/number}","contents_url":"https://api.github.com/repos/xapi-project/xen-api/contents/{+path}","compare_url":"https://api.github.com/repos/xapi-project/xen-api/compare/{base}...{head}","merges_url":"https://api.github.com/repos/xapi-project/xen-api/merges","archive_url":"https://api.github.com/repos/xapi-project/xen-api/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/xapi-project/xen-api/downloads","issues_url":"https://api.github.com/repos/xapi-project/xen-api/issues{/number}","pulls_url":"https://api.github.com/repos/xapi-project/xen-api/pulls{/number}","milestones_url":"https://api.github.com/repos/xapi-project/xen-api/milestones{/number}","notifications_url":"https://api.github.com/repos/xapi-project/xen-api/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/xapi-project/xen-api/labels{/name}","releases_url":"https://api.github.com/repos/xapi-project/xen-api/releases{/id}","created_at":"2010-10-04T10:52:57Z","updated_at":"2015-08-18T13:09:12Z","pushed_at":"2015-08-19T05:40:53Z","git_url":"git://github.com/xapi-project/xen-api.git","ssh_url":"git@github.com:xapi-project/xen-api.git","clone_url":"https://github.com/xapi-project/xen-api.git","svn_url":"https://github.com/xapi-project/xen-api","homepage":"http://xenproject.org/developers/teams/xapi.html","size":40416,"stargazers_count":186,"watchers_count":186,"language":"OCaml","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":136,"mirror_url":null,"open_issues_count":33,"forks":136,"open_issues":33,"watchers":186,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/xapi-project/xen-api/pulls/2338"},"html":{"href":"https://github.com/xapi-project/xen-api/pull/2338"},"issue":{"href":"https://api.github.com/repos/xapi-project/xen-api/issues/2338"},"comments":{"href":"https://api.github.com/repos/xapi-project/xen-api/issues/2338/comments"},"review_comments":{"href":"https://api.github.com/repos/xapi-project/xen-api/pulls/2338/comments"},"review_comment":{"href":"https://api.github.com/repos/xapi-project/xen-api/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/xapi-project/xen-api/pulls/2338/commits"},"statuses":{"href":"https://api.github.com/repos/xapi-project/xen-api/statuses/2429b45b37bf08d6cc2a21319df5d48498b7f8c5"}}}}