{"action":"created","comment":{"url":"https://api.github.com/repos/allegro/ralph/pulls/comments/45797631","id":45797631,"diff_hunk":"@@ -0,0 +1,104 @@\n+# -*- coding: utf-8 -*-\n+from django.core.exceptions import ObjectDoesNotExist\n+from django.db import models\n+from django.utils.translation import ugettext_lazy as _\n+\n+from ralph.assets.models.base import BaseObject\n+from ralph.assets.models.choices import ComponentType\n+from ralph.assets.models.components import GenericComponent\n+from ralph.data_center.models.networks import IPAddress\n+from ralph.lib.mixins.models import NamedMixin\n+\n+\n+class CloudProvider(NamedMixin):\n+    class Meta:\n+        verbose_name = _('Cloud provider')\n+        verbose_name_plural = _('Cloud providers')\n+\n+\n+class CloudFlavor(BaseObject):\n+    name = models.CharField(_('name'), max_length=255, unique=True)\n+    cloudprovider = models.ForeignKey(CloudProvider)\n+    flavor_id = models.CharField(unique=True, max_length=100)\n+\n+    def __str__(self):\n+        return format(self.name)\n+\n+    @property\n+    def cores(self):\n+        \"\"\"Number of cores\"\"\"\n+        try:\n+            for component in GenericComponent.objects.filter(asset=self):\n+                if component.model.type == ComponentType.processor:\n+                    return component.model.cores\n+            return None\n+        except ObjectDoesNotExist:\n+            return None\n+\n+    @property\n+    def memory(self):\n+        \"\"\"RAM memory size in MiB\"\"\"\n+        try:\n+            for component in GenericComponent.objects.filter(asset=self):\n+                if component.model.type == ComponentType.memory:\n+                    return component.model.size\n+            return None\n+        except ObjectDoesNotExist:\n+            return None\n+\n+    @property\n+    def disk(self):\n+        \"\"\"Disk size in MiB\"\"\"\n+        try:\n+            for component in GenericComponent.objects.filter(asset=self):\n+                if component.model.type == ComponentType.disk:\n+                    return component.model.size\n+            return None\n+        except ObjectDoesNotExist:\n+            return None\n+\n+\n+class CloudProject(BaseObject):\n+    cloudprovider = models.ForeignKey(CloudProvider)\n+    project_id = models.CharField(unique=True, max_length=100)\n+    name = models.CharField(max_length=100)\n+\n+    def __str__(self):\n+        return 'Cloud Project: {}'.format(self.name)\n+\n+    @property\n+    def cloudhost_set(self):\n+        return CloudHost.objects.filter(parent=self)\n+\n+\n+class CloudHost(BaseObject):\n+    host_id = models.CharField(unique=True, max_length=100)\n+    hostname = models.CharField(max_length=100)\n+    cloudflavor = models.ForeignKey(CloudFlavor, verbose_name='Instance Type')\n+\n+    class Meta:\n+        verbose_name = _('Cloud host')\n+        verbose_name_plural = _('Cloud hosts')\n+\n+    def __str__(self):\n+        return 'Cloud Host: {}'.format(self.hostname)\n+\n+    @property\n+    def ip_addresses(self):\n+        ips = []\n+        for ip in IPAddress.objects.filter(base_object=self):","path":"src/ralph/virtual/models.py","position":89,"original_position":89,"commit_id":"9bd7712cba8dcd661853cc7addc6e5be67dde931","original_commit_id":"9bd7712cba8dcd661853cc7addc6e5be67dde931","user":{"login":"mkurek","id":107437,"avatar_url":"https://avatars.githubusercontent.com/u/107437?v=3","gravatar_id":"","url":"https://api.github.com/users/mkurek","html_url":"https://github.com/mkurek","followers_url":"https://api.github.com/users/mkurek/followers","following_url":"https://api.github.com/users/mkurek/following{/other_user}","gists_url":"https://api.github.com/users/mkurek/gists{/gist_id}","starred_url":"https://api.github.com/users/mkurek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mkurek/subscriptions","organizations_url":"https://api.github.com/users/mkurek/orgs","repos_url":"https://api.github.com/users/mkurek/repos","events_url":"https://api.github.com/users/mkurek/events{/privacy}","received_events_url":"https://api.github.com/users/mkurek/received_events","type":"User","site_admin":false},"body":"`for ip in self.ipaddress_set.all()`","created_at":"2015-11-24T21:30:54Z","updated_at":"2015-11-24T21:30:54Z","html_url":"https://github.com/allegro/ralph/pull/1945#discussion_r45797631","pull_request_url":"https://api.github.com/repos/allegro/ralph/pulls/1945","_links":{"self":{"href":"https://api.github.com/repos/allegro/ralph/pulls/comments/45797631"},"html":{"href":"https://github.com/allegro/ralph/pull/1945#discussion_r45797631"},"pull_request":{"href":"https://api.github.com/repos/allegro/ralph/pulls/1945"}}},"pull_request":{"url":"https://api.github.com/repos/allegro/ralph/pulls/1945","id":51061732,"html_url":"https://github.com/allegro/ralph/pull/1945","diff_url":"https://github.com/allegro/ralph/pull/1945.diff","patch_url":"https://github.com/allegro/ralph/pull/1945.patch","issue_url":"https://api.github.com/repos/allegro/ralph/issues/1945","number":1945,"state":"open","locked":false,"title":"[WIP] Cloud hosts in Ralph & OpenStack sync","user":{"login":"bnogas","id":8866440,"avatar_url":"https://avatars.githubusercontent.com/u/8866440?v=3","gravatar_id":"","url":"https://api.github.com/users/bnogas","html_url":"https://github.com/bnogas","followers_url":"https://api.github.com/users/bnogas/followers","following_url":"https://api.github.com/users/bnogas/following{/other_user}","gists_url":"https://api.github.com/users/bnogas/gists{/gist_id}","starred_url":"https://api.github.com/users/bnogas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bnogas/subscriptions","organizations_url":"https://api.github.com/users/bnogas/orgs","repos_url":"https://api.github.com/users/bnogas/repos","events_url":"https://api.github.com/users/bnogas/events{/privacy}","received_events_url":"https://api.github.com/users/bnogas/received_events","type":"User","site_admin":false},"body":"* add virtual app\r\n* add openstack_sync management script","created_at":"2015-11-18T09:44:53Z","updated_at":"2015-11-24T21:30:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":"15ddda5d5b200e36d7f2210ff8a1c9f9e732c8de","assignee":null,"milestone":{"url":"https://api.github.com/repos/allegro/ralph/milestones/22","html_url":"https://github.com/allegro/ralph/milestones/3.1","labels_url":"https://api.github.com/repos/allegro/ralph/milestones/22/labels","id":1408032,"number":22,"title":"3.1","description":"","creator":{"login":"mkurek","id":107437,"avatar_url":"https://avatars.githubusercontent.com/u/107437?v=3","gravatar_id":"","url":"https://api.github.com/users/mkurek","html_url":"https://github.com/mkurek","followers_url":"https://api.github.com/users/mkurek/followers","following_url":"https://api.github.com/users/mkurek/following{/other_user}","gists_url":"https://api.github.com/users/mkurek/gists{/gist_id}","starred_url":"https://api.github.com/users/mkurek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mkurek/subscriptions","organizations_url":"https://api.github.com/users/mkurek/orgs","repos_url":"https://api.github.com/users/mkurek/repos","events_url":"https://api.github.com/users/mkurek/events{/privacy}","received_events_url":"https://api.github.com/users/mkurek/received_events","type":"User","site_admin":false},"open_issues":3,"closed_issues":0,"state":"open","created_at":"2015-11-12T08:11:15Z","updated_at":"2015-11-19T06:31:31Z","due_on":"2015-12-30T23:00:00Z","closed_at":null},"commits_url":"https://api.github.com/repos/allegro/ralph/pulls/1945/commits","review_comments_url":"https://api.github.com/repos/allegro/ralph/pulls/1945/comments","review_comment_url":"https://api.github.com/repos/allegro/ralph/pulls/comments{/number}","comments_url":"https://api.github.com/repos/allegro/ralph/issues/1945/comments","statuses_url":"https://api.github.com/repos/allegro/ralph/statuses/9bd7712cba8dcd661853cc7addc6e5be67dde931","head":{"label":"bnogas:cloud","ref":"cloud","sha":"9bd7712cba8dcd661853cc7addc6e5be67dde931","user":{"login":"bnogas","id":8866440,"avatar_url":"https://avatars.githubusercontent.com/u/8866440?v=3","gravatar_id":"","url":"https://api.github.com/users/bnogas","html_url":"https://github.com/bnogas","followers_url":"https://api.github.com/users/bnogas/followers","following_url":"https://api.github.com/users/bnogas/following{/other_user}","gists_url":"https://api.github.com/users/bnogas/gists{/gist_id}","starred_url":"https://api.github.com/users/bnogas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bnogas/subscriptions","organizations_url":"https://api.github.com/users/bnogas/orgs","repos_url":"https://api.github.com/users/bnogas/repos","events_url":"https://api.github.com/users/bnogas/events{/privacy}","received_events_url":"https://api.github.com/users/bnogas/received_events","type":"User","site_admin":false},"repo":{"id":45912281,"name":"ralph","full_name":"bnogas/ralph","owner":{"login":"bnogas","id":8866440,"avatar_url":"https://avatars.githubusercontent.com/u/8866440?v=3","gravatar_id":"","url":"https://api.github.com/users/bnogas","html_url":"https://github.com/bnogas","followers_url":"https://api.github.com/users/bnogas/followers","following_url":"https://api.github.com/users/bnogas/following{/other_user}","gists_url":"https://api.github.com/users/bnogas/gists{/gist_id}","starred_url":"https://api.github.com/users/bnogas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bnogas/subscriptions","organizations_url":"https://api.github.com/users/bnogas/orgs","repos_url":"https://api.github.com/users/bnogas/repos","events_url":"https://api.github.com/users/bnogas/events{/privacy}","received_events_url":"https://api.github.com/users/bnogas/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/bnogas/ralph","description":"Ralph is an asset management system for your data center.","fork":true,"url":"https://api.github.com/repos/bnogas/ralph","forks_url":"https://api.github.com/repos/bnogas/ralph/forks","keys_url":"https://api.github.com/repos/bnogas/ralph/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bnogas/ralph/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bnogas/ralph/teams","hooks_url":"https://api.github.com/repos/bnogas/ralph/hooks","issue_events_url":"https://api.github.com/repos/bnogas/ralph/issues/events{/number}","events_url":"https://api.github.com/repos/bnogas/ralph/events","assignees_url":"https://api.github.com/repos/bnogas/ralph/assignees{/user}","branches_url":"https://api.github.com/repos/bnogas/ralph/branches{/branch}","tags_url":"https://api.github.com/repos/bnogas/ralph/tags","blobs_url":"https://api.github.com/repos/bnogas/ralph/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bnogas/ralph/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bnogas/ralph/git/refs{/sha}","trees_url":"https://api.github.com/repos/bnogas/ralph/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bnogas/ralph/statuses/{sha}","languages_url":"https://api.github.com/repos/bnogas/ralph/languages","stargazers_url":"https://api.github.com/repos/bnogas/ralph/stargazers","contributors_url":"https://api.github.com/repos/bnogas/ralph/contributors","subscribers_url":"https://api.github.com/repos/bnogas/ralph/subscribers","subscription_url":"https://api.github.com/repos/bnogas/ralph/subscription","commits_url":"https://api.github.com/repos/bnogas/ralph/commits{/sha}","git_commits_url":"https://api.github.com/repos/bnogas/ralph/git/commits{/sha}","comments_url":"https://api.github.com/repos/bnogas/ralph/comments{/number}","issue_comment_url":"https://api.github.com/repos/bnogas/ralph/issues/comments{/number}","contents_url":"https://api.github.com/repos/bnogas/ralph/contents/{+path}","compare_url":"https://api.github.com/repos/bnogas/ralph/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bnogas/ralph/merges","archive_url":"https://api.github.com/repos/bnogas/ralph/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bnogas/ralph/downloads","issues_url":"https://api.github.com/repos/bnogas/ralph/issues{/number}","pulls_url":"https://api.github.com/repos/bnogas/ralph/pulls{/number}","milestones_url":"https://api.github.com/repos/bnogas/ralph/milestones{/number}","notifications_url":"https://api.github.com/repos/bnogas/ralph/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bnogas/ralph/labels{/name}","releases_url":"https://api.github.com/repos/bnogas/ralph/releases{/id}","created_at":"2015-11-10T13:05:53Z","updated_at":"2015-11-10T13:05:56Z","pushed_at":"2015-11-24T16:35:11Z","git_url":"git://github.com/bnogas/ralph.git","ssh_url":"git@github.com:bnogas/ralph.git","clone_url":"https://github.com/bnogas/ralph.git","svn_url":"https://github.com/bnogas/ralph","homepage":"http://allegro.tech/ralph/","size":20915,"stargazers_count":0,"watchers_count":0,"language":"Python","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":"ng"}},"base":{"label":"allegro:ng","ref":"ng","sha":"7473afa5f0ba945afa7f547cf336c31ddad8ebd2","user":{"login":"allegro","id":562236,"avatar_url":"https://avatars.githubusercontent.com/u/562236?v=3","gravatar_id":"","url":"https://api.github.com/users/allegro","html_url":"https://github.com/allegro","followers_url":"https://api.github.com/users/allegro/followers","following_url":"https://api.github.com/users/allegro/following{/other_user}","gists_url":"https://api.github.com/users/allegro/gists{/gist_id}","starred_url":"https://api.github.com/users/allegro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/allegro/subscriptions","organizations_url":"https://api.github.com/users/allegro/orgs","repos_url":"https://api.github.com/users/allegro/repos","events_url":"https://api.github.com/users/allegro/events{/privacy}","received_events_url":"https://api.github.com/users/allegro/received_events","type":"Organization","site_admin":false},"repo":{"id":4359038,"name":"ralph","full_name":"allegro/ralph","owner":{"login":"allegro","id":562236,"avatar_url":"https://avatars.githubusercontent.com/u/562236?v=3","gravatar_id":"","url":"https://api.github.com/users/allegro","html_url":"https://github.com/allegro","followers_url":"https://api.github.com/users/allegro/followers","following_url":"https://api.github.com/users/allegro/following{/other_user}","gists_url":"https://api.github.com/users/allegro/gists{/gist_id}","starred_url":"https://api.github.com/users/allegro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/allegro/subscriptions","organizations_url":"https://api.github.com/users/allegro/orgs","repos_url":"https://api.github.com/users/allegro/repos","events_url":"https://api.github.com/users/allegro/events{/privacy}","received_events_url":"https://api.github.com/users/allegro/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/allegro/ralph","description":"Ralph is an asset management system for your data center.","fork":false,"url":"https://api.github.com/repos/allegro/ralph","forks_url":"https://api.github.com/repos/allegro/ralph/forks","keys_url":"https://api.github.com/repos/allegro/ralph/keys{/key_id}","collaborators_url":"https://api.github.com/repos/allegro/ralph/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/allegro/ralph/teams","hooks_url":"https://api.github.com/repos/allegro/ralph/hooks","issue_events_url":"https://api.github.com/repos/allegro/ralph/issues/events{/number}","events_url":"https://api.github.com/repos/allegro/ralph/events","assignees_url":"https://api.github.com/repos/allegro/ralph/assignees{/user}","branches_url":"https://api.github.com/repos/allegro/ralph/branches{/branch}","tags_url":"https://api.github.com/repos/allegro/ralph/tags","blobs_url":"https://api.github.com/repos/allegro/ralph/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/allegro/ralph/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/allegro/ralph/git/refs{/sha}","trees_url":"https://api.github.com/repos/allegro/ralph/git/trees{/sha}","statuses_url":"https://api.github.com/repos/allegro/ralph/statuses/{sha}","languages_url":"https://api.github.com/repos/allegro/ralph/languages","stargazers_url":"https://api.github.com/repos/allegro/ralph/stargazers","contributors_url":"https://api.github.com/repos/allegro/ralph/contributors","subscribers_url":"https://api.github.com/repos/allegro/ralph/subscribers","subscription_url":"https://api.github.com/repos/allegro/ralph/subscription","commits_url":"https://api.github.com/repos/allegro/ralph/commits{/sha}","git_commits_url":"https://api.github.com/repos/allegro/ralph/git/commits{/sha}","comments_url":"https://api.github.com/repos/allegro/ralph/comments{/number}","issue_comment_url":"https://api.github.com/repos/allegro/ralph/issues/comments{/number}","contents_url":"https://api.github.com/repos/allegro/ralph/contents/{+path}","compare_url":"https://api.github.com/repos/allegro/ralph/compare/{base}...{head}","merges_url":"https://api.github.com/repos/allegro/ralph/merges","archive_url":"https://api.github.com/repos/allegro/ralph/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/allegro/ralph/downloads","issues_url":"https://api.github.com/repos/allegro/ralph/issues{/number}","pulls_url":"https://api.github.com/repos/allegro/ralph/pulls{/number}","milestones_url":"https://api.github.com/repos/allegro/ralph/milestones{/number}","notifications_url":"https://api.github.com/repos/allegro/ralph/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/allegro/ralph/labels{/name}","releases_url":"https://api.github.com/repos/allegro/ralph/releases{/id}","created_at":"2012-05-17T14:04:57Z","updated_at":"2015-11-23T10:37:21Z","pushed_at":"2015-11-24T16:35:12Z","git_url":"git://github.com/allegro/ralph.git","ssh_url":"git@github.com:allegro/ralph.git","clone_url":"https://github.com/allegro/ralph.git","svn_url":"https://github.com/allegro/ralph","homepage":"http://allegro.tech/ralph/","size":22853,"stargazers_count":338,"watchers_count":338,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":78,"mirror_url":null,"open_issues_count":97,"forks":78,"open_issues":97,"watchers":338,"default_branch":"ng"}},"_links":{"self":{"href":"https://api.github.com/repos/allegro/ralph/pulls/1945"},"html":{"href":"https://github.com/allegro/ralph/pull/1945"},"issue":{"href":"https://api.github.com/repos/allegro/ralph/issues/1945"},"comments":{"href":"https://api.github.com/repos/allegro/ralph/issues/1945/comments"},"review_comments":{"href":"https://api.github.com/repos/allegro/ralph/pulls/1945/comments"},"review_comment":{"href":"https://api.github.com/repos/allegro/ralph/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/allegro/ralph/pulls/1945/commits"},"statuses":{"href":"https://api.github.com/repos/allegro/ralph/statuses/9bd7712cba8dcd661853cc7addc6e5be67dde931"}}}}