{"action":"created","comment":{"url":"https://api.github.com/repos/allegro/ralph/pulls/comments/30509131","id":30509131,"diff_hunk":"@@ -0,0 +1,389 @@\n+# -*- coding: utf-8 -*-\n+\n+from __future__ import absolute_import\n+from __future__ import division\n+from __future__ import print_function\n+from __future__ import unicode_literals\n+\n+import ipaddr\n+\n+from django.db import models\n+from django.core.exceptions import ValidationError\n+from django.utils.encoding import python_2_unicode_compatible\n+from django.utils.translation import ugettext_lazy as _\n+\n+from ralph.assets.models.assets import Asset\n+from ralph.assets.models.mixins import (\n+    LastSeenMixin,\n+    NamedMixin,\n+    TimeStampMixin,\n+)\n+\n+\n+def network_validator(value):\n+    try:\n+        ipaddr.IPv4Network(value)\n+    except ipaddr.NetmaskValueError as exc:\n+        raise ValidationError(exc.message)\n+\n+\n+@python_2_unicode_compatible\n+class NetworkKind(NamedMixin, models.Model):\n+    class Meta:\n+        verbose_name = _('network kind')\n+        verbose_name_plural = _('network kinds')\n+        ordering = ('name',)\n+\n+    def __str__(self):\n+        return self.name\n+\n+\n+@python_2_unicode_compatible\n+class NetworkEnvironment(NamedMixin):\n+    # TODO: more generic\n+    # data_center = models.ForeignKey(\n+    #     'DataCenter',\n+    #     verbose_name=_('data center')\n+    # )\n+    queue = models.ForeignKey(\n+        'DiscoveryQueue',\n+        verbose_name=_('discovery queue'),\n+        null=True,\n+        blank=True,\n+        on_delete=models.SET_NULL,\n+    )\n+    hosts_naming_template = models.CharField(\n+        max_length=30,\n+        help_text=_(\n+            'E.g. h<200,299>.dc|h<400,499>.dc will produce: h200.dc '\n+            'h201.dc ... h299.dc h400.dc h401.dc'\n+        ),\n+    )\n+    next_server = models.CharField(\n+        max_length=32,\n+        blank=True,\n+        default='',\n+        help_text=_('The address for a TFTP server for DHCP.'),\n+    )\n+    domain = models.CharField(\n+        _('domain'),\n+        max_length=255,\n+        blank=True,\n+        null=True,\n+    )\n+    remarks = models.TextField(\n+        verbose_name=_('remarks'),\n+        help_text=_('Additional information.'),\n+        blank=True,\n+        null=True,\n+    )\n+\n+    def __str__(self):\n+        return self.name\n+\n+    class Meta:\n+        ordering = ('name',)\n+\n+\n+@python_2_unicode_compatible\n+class AbstractNetwork(models.Model):\n+    \"\"\"\n+    Abstract class for networks.\n+    \"\"\"\n+    address = models.CharField(\n+        _('network address'),\n+        help_text=_('Presented as string (e.g. 192.168.0.0/24)'),\n+        max_length=len('xxx.xxx.xxx.xxx/xx'), unique=True,\n+        validators=[network_validator]\n+    )\n+    gateway = models.GenericIPAddressField(\n+        _('gateway address'), help_text=_('Presented as string.'), blank=True,\n+        null=True, default=None,\n+    )\n+    gateway_as_int = models.PositiveIntegerField(\n+        _('gateway as int'), null=True, blank=True, default=None,\n+        editable=False,\n+    )\n+    reserved = models.PositiveIntegerField(\n+        _('reserved'), default=10,\n+        help_text=_('Number of addresses to be omitted in the automatic '\n+                    'determination process, counted from the first in range.')\n+    )\n+    reserved_top_margin = models.PositiveIntegerField(\n+        _('reserved (top margin)'), default=0,\n+        help_text=_('Number of addresses to be omitted in the automatic '\n+                    'determination process, counted from the last in range.')\n+    )\n+    remarks = models.TextField(\n+        _('remarks'), help_text=_('Additional information.'), blank=True,\n+        default='',\n+    )\n+    terminators = models.ManyToManyField(\n+        'NetworkTerminator', verbose_name=_('network terminators'),\n+    )\n+    vlan = models.PositiveIntegerField(\n+        _('VLAN number'), null=True, blank=True, default=None,\n+    )\n+    # TODO: delete?\n+    # data_center = models.ForeignKey(\n+    #     'DataCenter',\n+    #     verbose_name=_('data center'),\n+    #     null=True,\n+    #     blank=True,\n+    # )\n+    # TODO: delete?\n+    # racks = models.ManyToManyField(\n+    #     'Rack', verbose_name=_('racks'),\n+    #     # We can't import DeviceType in here, so we use an integer.\n+    # )\n+    # TODO: network env\n+    environment = models.ForeignKey(","path":"src/ralph/assets/models/networks.py","position":140,"original_position":140,"commit_id":"8da67d9b61a8be9405899650cc20636c4849c5ca","original_commit_id":"8da67d9b61a8be9405899650cc20636c4849c5ca","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":"`network_environment` (and foreign key to `NetworkEnvironment`)","created_at":"2015-05-18T13:58:27Z","updated_at":"2015-05-18T13:58:27Z","html_url":"https://github.com/allegro/ralph/pull/1428#discussion_r30509131","pull_request_url":"https://api.github.com/repos/allegro/ralph/pulls/1428","_links":{"self":{"href":"https://api.github.com/repos/allegro/ralph/pulls/comments/30509131"},"html":{"href":"https://github.com/allegro/ralph/pull/1428#discussion_r30509131"},"pull_request":{"href":"https://api.github.com/repos/allegro/ralph/pulls/1428"}}},"pull_request":{"url":"https://api.github.com/repos/allegro/ralph/pulls/1428","id":35630630,"html_url":"https://github.com/allegro/ralph/pull/1428","diff_url":"https://github.com/allegro/ralph/pull/1428.diff","patch_url":"https://github.com/allegro/ralph/pull/1428.patch","issue_url":"https://api.github.com/repos/allegro/ralph/issues/1428","number":1428,"state":"open","locked":false,"title":"WIP Moved networks models","user":{"login":"ar4s","id":351535,"avatar_url":"https://avatars.githubusercontent.com/u/351535?v=3","gravatar_id":"","url":"https://api.github.com/users/ar4s","html_url":"https://github.com/ar4s","followers_url":"https://api.github.com/users/ar4s/followers","following_url":"https://api.github.com/users/ar4s/following{/other_user}","gists_url":"https://api.github.com/users/ar4s/gists{/gist_id}","starred_url":"https://api.github.com/users/ar4s/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ar4s/subscriptions","organizations_url":"https://api.github.com/users/ar4s/orgs","repos_url":"https://api.github.com/users/ar4s/repos","events_url":"https://api.github.com/users/ar4s/events{/privacy}","received_events_url":"https://api.github.com/users/ar4s/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-05-18T12:58:48Z","updated_at":"2015-05-18T13:58:27Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a974dbffdfbb2fb849ce8f49c4f7283468ab018e","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/allegro/ralph/pulls/1428/commits","review_comments_url":"https://api.github.com/repos/allegro/ralph/pulls/1428/comments","review_comment_url":"https://api.github.com/repos/allegro/ralph/pulls/comments{/number}","comments_url":"https://api.github.com/repos/allegro/ralph/issues/1428/comments","statuses_url":"https://api.github.com/repos/allegro/ralph/statuses/8da67d9b61a8be9405899650cc20636c4849c5ca","head":{"label":"ar4s:ng-additional-dc-models","ref":"ng-additional-dc-models","sha":"8da67d9b61a8be9405899650cc20636c4849c5ca","user":{"login":"ar4s","id":351535,"avatar_url":"https://avatars.githubusercontent.com/u/351535?v=3","gravatar_id":"","url":"https://api.github.com/users/ar4s","html_url":"https://github.com/ar4s","followers_url":"https://api.github.com/users/ar4s/followers","following_url":"https://api.github.com/users/ar4s/following{/other_user}","gists_url":"https://api.github.com/users/ar4s/gists{/gist_id}","starred_url":"https://api.github.com/users/ar4s/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ar4s/subscriptions","organizations_url":"https://api.github.com/users/ar4s/orgs","repos_url":"https://api.github.com/users/ar4s/repos","events_url":"https://api.github.com/users/ar4s/events{/privacy}","received_events_url":"https://api.github.com/users/ar4s/received_events","type":"User","site_admin":false},"repo":{"id":19566764,"name":"ralph","full_name":"ar4s/ralph","owner":{"login":"ar4s","id":351535,"avatar_url":"https://avatars.githubusercontent.com/u/351535?v=3","gravatar_id":"","url":"https://api.github.com/users/ar4s","html_url":"https://github.com/ar4s","followers_url":"https://api.github.com/users/ar4s/followers","following_url":"https://api.github.com/users/ar4s/following{/other_user}","gists_url":"https://api.github.com/users/ar4s/gists{/gist_id}","starred_url":"https://api.github.com/users/ar4s/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ar4s/subscriptions","organizations_url":"https://api.github.com/users/ar4s/orgs","repos_url":"https://api.github.com/users/ar4s/repos","events_url":"https://api.github.com/users/ar4s/events{/privacy}","received_events_url":"https://api.github.com/users/ar4s/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ar4s/ralph","description":"Ralph is an asset management system for your data center.","fork":true,"url":"https://api.github.com/repos/ar4s/ralph","forks_url":"https://api.github.com/repos/ar4s/ralph/forks","keys_url":"https://api.github.com/repos/ar4s/ralph/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ar4s/ralph/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ar4s/ralph/teams","hooks_url":"https://api.github.com/repos/ar4s/ralph/hooks","issue_events_url":"https://api.github.com/repos/ar4s/ralph/issues/events{/number}","events_url":"https://api.github.com/repos/ar4s/ralph/events","assignees_url":"https://api.github.com/repos/ar4s/ralph/assignees{/user}","branches_url":"https://api.github.com/repos/ar4s/ralph/branches{/branch}","tags_url":"https://api.github.com/repos/ar4s/ralph/tags","blobs_url":"https://api.github.com/repos/ar4s/ralph/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ar4s/ralph/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ar4s/ralph/git/refs{/sha}","trees_url":"https://api.github.com/repos/ar4s/ralph/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ar4s/ralph/statuses/{sha}","languages_url":"https://api.github.com/repos/ar4s/ralph/languages","stargazers_url":"https://api.github.com/repos/ar4s/ralph/stargazers","contributors_url":"https://api.github.com/repos/ar4s/ralph/contributors","subscribers_url":"https://api.github.com/repos/ar4s/ralph/subscribers","subscription_url":"https://api.github.com/repos/ar4s/ralph/subscription","commits_url":"https://api.github.com/repos/ar4s/ralph/commits{/sha}","git_commits_url":"https://api.github.com/repos/ar4s/ralph/git/commits{/sha}","comments_url":"https://api.github.com/repos/ar4s/ralph/comments{/number}","issue_comment_url":"https://api.github.com/repos/ar4s/ralph/issues/comments{/number}","contents_url":"https://api.github.com/repos/ar4s/ralph/contents/{+path}","compare_url":"https://api.github.com/repos/ar4s/ralph/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ar4s/ralph/merges","archive_url":"https://api.github.com/repos/ar4s/ralph/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ar4s/ralph/downloads","issues_url":"https://api.github.com/repos/ar4s/ralph/issues{/number}","pulls_url":"https://api.github.com/repos/ar4s/ralph/pulls{/number}","milestones_url":"https://api.github.com/repos/ar4s/ralph/milestones{/number}","notifications_url":"https://api.github.com/repos/ar4s/ralph/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ar4s/ralph/labels{/name}","releases_url":"https://api.github.com/repos/ar4s/ralph/releases{/id}","created_at":"2014-05-08T08:48:11Z","updated_at":"2015-04-15T11:59:21Z","pushed_at":"2015-05-18T12:57:36Z","git_url":"git://github.com/ar4s/ralph.git","ssh_url":"git@github.com:ar4s/ralph.git","clone_url":"https://github.com/ar4s/ralph.git","svn_url":"https://github.com/ar4s/ralph","homepage":"http://ralph.allegrogroup.com/","size":20116,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"develop"}},"base":{"label":"allegro:ng","ref":"ng","sha":"9b6f42eb1e531ab5deb3c756be12565c6e1e2781","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-05-14T16:20:20Z","pushed_at":"2015-05-18T13:50:19Z","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://ralph.allegrogroup.com/","size":26698,"stargazers_count":269,"watchers_count":269,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":70,"mirror_url":null,"open_issues_count":45,"forks":70,"open_issues":45,"watchers":269,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/allegro/ralph/pulls/1428"},"html":{"href":"https://github.com/allegro/ralph/pull/1428"},"issue":{"href":"https://api.github.com/repos/allegro/ralph/issues/1428"},"comments":{"href":"https://api.github.com/repos/allegro/ralph/issues/1428/comments"},"review_comments":{"href":"https://api.github.com/repos/allegro/ralph/pulls/1428/comments"},"review_comment":{"href":"https://api.github.com/repos/allegro/ralph/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/allegro/ralph/pulls/1428/commits"},"statuses":{"href":"https://api.github.com/repos/allegro/ralph/statuses/8da67d9b61a8be9405899650cc20636c4849c5ca"}}}}