{"action":"created","comment":{"url":"https://api.github.com/repos/openstack-charmers/charms.openstack/pulls/comments/65683178","id":65683178,"diff_hunk":"@@ -83,6 +89,102 @@ def hosts(self):\n             return None\n \n \n+class PeerHARelationAdapter(OpenStackRelationAdapter):\n+    \"\"\"\n+    Adapter for cluster relation of nodes of the same service\n+    \"\"\"\n+\n+    interface_type = \"cluster\"\n+\n+    def __init__(self, relation):\n+        super(PeerHARelationAdapter, self).__init__(relation)\n+        self.config = charmhelpers.core.hookenv.config()\n+        self.local_address = APIConfigurationAdapter().local_address\n+        self.local_unit_name = APIConfigurationAdapter().local_unit_name\n+        self.cluster_hosts = {}\n+        self.add_network_split_addresses()\n+        self.add_default_addresses()\n+\n+    @staticmethod\n+    def local_network_split_addresses():\n+        \"\"\"Map of local units addresses for each address type\n+\n+           NOTE: This excludes private-address\n+           @return dict of backends and networks for local unit e.g.\n+               {'this_unit_admin_addr': {\n+                    'backends': {\n+                        'this_unit-1': 'this_unit_admin_addr'},\n+                    'network': 'this_unit_admin_addr/admin_netmask'},\n+                'this_unit_internal_addr': {\n+                    'backends': {\n+                        'this_unit-1': 'this_unit_internal_addr'},\n+                    'network': 'this_unit_internal_addr/internal_netmask'},\n+                'this_unit_public_addr': {\n+                    'backends': {\n+                        'this_unit-1': 'this_unit_public_addr'},\n+                    'network': 'this_unit_public_addr/public_netmask'}}\n+        \"\"\"\n+        config = charmhelpers.core.hookenv.config()\n+        local_unit_name = APIConfigurationAdapter().local_unit_name\n+        _cluster_hosts = {}\n+        for addr_type in ADDRESS_TYPES:\n+            cfg_opt = 'os-{}-network'.format(addr_type)\n+            laddr = ch_ip.get_address_in_network(config.get(cfg_opt))\n+            if laddr:\n+                netmask = ch_ip.get_netmask_for_address(laddr)\n+                _cluster_hosts[laddr] = {\n+                    'network': \"{}/{}\".format(laddr, netmask),\n+                    'backends': {local_unit_name: laddr}}\n+        return _cluster_hosts\n+\n+    @staticmethod\n+    def local_default_addresses():\n+        \"\"\"Map of local units private address\n+\n+           @return dict of private address info local unit e.g.\n+               {'this_unit_private_addr': {\n+                    'backends': {\n+                        'this_unit-1': 'this_unit_private_addr'},\n+                    'network': 'this_unit_private_addr/private_netmask'}}\n+\n+        \"\"\"\n+        local_unit_name = APIConfigurationAdapter().local_unit_name\n+        local_address = APIConfigurationAdapter().local_address","path":"charms_openstack/adapters.py","position":79,"original_position":79,"commit_id":"81e34f166f67d1aa58c0a7bb181d75443a89c96e","original_commit_id":"81e34f166f67d1aa58c0a7bb181d75443a89c96e","user":{"login":"ajkavanagh","id":567675,"avatar_url":"https://avatars.githubusercontent.com/u/567675?v=3","gravatar_id":"","url":"https://api.github.com/users/ajkavanagh","html_url":"https://github.com/ajkavanagh","followers_url":"https://api.github.com/users/ajkavanagh/followers","following_url":"https://api.github.com/users/ajkavanagh/following{/other_user}","gists_url":"https://api.github.com/users/ajkavanagh/gists{/gist_id}","starred_url":"https://api.github.com/users/ajkavanagh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ajkavanagh/subscriptions","organizations_url":"https://api.github.com/users/ajkavanagh/orgs","repos_url":"https://api.github.com/users/ajkavanagh/repos","events_url":"https://api.github.com/users/ajkavanagh/events{/privacy}","received_events_url":"https://api.github.com/users/ajkavanagh/received_events","type":"User","site_admin":false},"body":"use `self.local_unit_name` and `self.local_address` and drop the `@staticmethod` ?","created_at":"2016-06-03T09:53:12Z","updated_at":"2016-06-03T09:53:12Z","html_url":"https://github.com/openstack-charmers/charms.openstack/pull/8#discussion_r65683178","pull_request_url":"https://api.github.com/repos/openstack-charmers/charms.openstack/pulls/8","_links":{"self":{"href":"https://api.github.com/repos/openstack-charmers/charms.openstack/pulls/comments/65683178"},"html":{"href":"https://github.com/openstack-charmers/charms.openstack/pull/8#discussion_r65683178"},"pull_request":{"href":"https://api.github.com/repos/openstack-charmers/charms.openstack/pulls/8"}}},"pull_request":{"url":"https://api.github.com/repos/openstack-charmers/charms.openstack/pulls/8","id":72468507,"html_url":"https://github.com/openstack-charmers/charms.openstack/pull/8","diff_url":"https://github.com/openstack-charmers/charms.openstack/pull/8.diff","patch_url":"https://github.com/openstack-charmers/charms.openstack/pull/8.patch","issue_url":"https://api.github.com/repos/openstack-charmers/charms.openstack/issues/8","number":8,"state":"open","locked":false,"title":"Add Support for clustering units","user":{"login":"gnuoy","id":6472064,"avatar_url":"https://avatars.githubusercontent.com/u/6472064?v=3","gravatar_id":"","url":"https://api.github.com/users/gnuoy","html_url":"https://github.com/gnuoy","followers_url":"https://api.github.com/users/gnuoy/followers","following_url":"https://api.github.com/users/gnuoy/following{/other_user}","gists_url":"https://api.github.com/users/gnuoy/gists{/gist_id}","starred_url":"https://api.github.com/users/gnuoy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gnuoy/subscriptions","organizations_url":"https://api.github.com/users/gnuoy/orgs","repos_url":"https://api.github.com/users/gnuoy/repos","events_url":"https://api.github.com/users/gnuoy/events{/privacy}","received_events_url":"https://api.github.com/users/gnuoy/received_events","type":"User","site_admin":false},"body":"Apologies for the large diff.\r\n\r\nI've added a PeerHARelationAdapter adapter which handles querying the IP addresses of its peers and compiling them into a dictionary that the haproxy template can then consume. It has two static methods for querying local unit data as these are used to populate the 'cluster' adapter namespace when the cluster relation has not yet been initialised.\r\n\r\nThe APIConfigurationAdapter extends the ConfigurationAdapter class and adds properties which are common across Openstack API charms.\r\n\r\nI've also added methods for determining the restart_map and list of packages to be installed as these often need to be constructed dynamically at runtime rather than defined statically.","created_at":"2016-06-03T08:05:59Z","updated_at":"2016-06-03T09:53:12Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d321301ccfe0fca6d977b6192caa9fe7f3ff1708","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/openstack-charmers/charms.openstack/pulls/8/commits","review_comments_url":"https://api.github.com/repos/openstack-charmers/charms.openstack/pulls/8/comments","review_comment_url":"https://api.github.com/repos/openstack-charmers/charms.openstack/pulls/comments{/number}","comments_url":"https://api.github.com/repos/openstack-charmers/charms.openstack/issues/8/comments","statuses_url":"https://api.github.com/repos/openstack-charmers/charms.openstack/statuses/81e34f166f67d1aa58c0a7bb181d75443a89c96e","head":{"label":"gnuoy:feature/ha-support","ref":"feature/ha-support","sha":"81e34f166f67d1aa58c0a7bb181d75443a89c96e","user":{"login":"gnuoy","id":6472064,"avatar_url":"https://avatars.githubusercontent.com/u/6472064?v=3","gravatar_id":"","url":"https://api.github.com/users/gnuoy","html_url":"https://github.com/gnuoy","followers_url":"https://api.github.com/users/gnuoy/followers","following_url":"https://api.github.com/users/gnuoy/following{/other_user}","gists_url":"https://api.github.com/users/gnuoy/gists{/gist_id}","starred_url":"https://api.github.com/users/gnuoy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gnuoy/subscriptions","organizations_url":"https://api.github.com/users/gnuoy/orgs","repos_url":"https://api.github.com/users/gnuoy/repos","events_url":"https://api.github.com/users/gnuoy/events{/privacy}","received_events_url":"https://api.github.com/users/gnuoy/received_events","type":"User","site_admin":false},"repo":{"id":59750339,"name":"charms.openstack","full_name":"gnuoy/charms.openstack","owner":{"login":"gnuoy","id":6472064,"avatar_url":"https://avatars.githubusercontent.com/u/6472064?v=3","gravatar_id":"","url":"https://api.github.com/users/gnuoy","html_url":"https://github.com/gnuoy","followers_url":"https://api.github.com/users/gnuoy/followers","following_url":"https://api.github.com/users/gnuoy/following{/other_user}","gists_url":"https://api.github.com/users/gnuoy/gists{/gist_id}","starred_url":"https://api.github.com/users/gnuoy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gnuoy/subscriptions","organizations_url":"https://api.github.com/users/gnuoy/orgs","repos_url":"https://api.github.com/users/gnuoy/repos","events_url":"https://api.github.com/users/gnuoy/events{/privacy}","received_events_url":"https://api.github.com/users/gnuoy/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/gnuoy/charms.openstack","description":"","fork":true,"url":"https://api.github.com/repos/gnuoy/charms.openstack","forks_url":"https://api.github.com/repos/gnuoy/charms.openstack/forks","keys_url":"https://api.github.com/repos/gnuoy/charms.openstack/keys{/key_id}","collaborators_url":"https://api.github.com/repos/gnuoy/charms.openstack/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/gnuoy/charms.openstack/teams","hooks_url":"https://api.github.com/repos/gnuoy/charms.openstack/hooks","issue_events_url":"https://api.github.com/repos/gnuoy/charms.openstack/issues/events{/number}","events_url":"https://api.github.com/repos/gnuoy/charms.openstack/events","assignees_url":"https://api.github.com/repos/gnuoy/charms.openstack/assignees{/user}","branches_url":"https://api.github.com/repos/gnuoy/charms.openstack/branches{/branch}","tags_url":"https://api.github.com/repos/gnuoy/charms.openstack/tags","blobs_url":"https://api.github.com/repos/gnuoy/charms.openstack/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/gnuoy/charms.openstack/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/gnuoy/charms.openstack/git/refs{/sha}","trees_url":"https://api.github.com/repos/gnuoy/charms.openstack/git/trees{/sha}","statuses_url":"https://api.github.com/repos/gnuoy/charms.openstack/statuses/{sha}","languages_url":"https://api.github.com/repos/gnuoy/charms.openstack/languages","stargazers_url":"https://api.github.com/repos/gnuoy/charms.openstack/stargazers","contributors_url":"https://api.github.com/repos/gnuoy/charms.openstack/contributors","subscribers_url":"https://api.github.com/repos/gnuoy/charms.openstack/subscribers","subscription_url":"https://api.github.com/repos/gnuoy/charms.openstack/subscription","commits_url":"https://api.github.com/repos/gnuoy/charms.openstack/commits{/sha}","git_commits_url":"https://api.github.com/repos/gnuoy/charms.openstack/git/commits{/sha}","comments_url":"https://api.github.com/repos/gnuoy/charms.openstack/comments{/number}","issue_comment_url":"https://api.github.com/repos/gnuoy/charms.openstack/issues/comments{/number}","contents_url":"https://api.github.com/repos/gnuoy/charms.openstack/contents/{+path}","compare_url":"https://api.github.com/repos/gnuoy/charms.openstack/compare/{base}...{head}","merges_url":"https://api.github.com/repos/gnuoy/charms.openstack/merges","archive_url":"https://api.github.com/repos/gnuoy/charms.openstack/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/gnuoy/charms.openstack/downloads","issues_url":"https://api.github.com/repos/gnuoy/charms.openstack/issues{/number}","pulls_url":"https://api.github.com/repos/gnuoy/charms.openstack/pulls{/number}","milestones_url":"https://api.github.com/repos/gnuoy/charms.openstack/milestones{/number}","notifications_url":"https://api.github.com/repos/gnuoy/charms.openstack/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/gnuoy/charms.openstack/labels{/name}","releases_url":"https://api.github.com/repos/gnuoy/charms.openstack/releases{/id}","deployments_url":"https://api.github.com/repos/gnuoy/charms.openstack/deployments","created_at":"2016-05-26T12:56:45Z","updated_at":"2016-05-26T12:56:46Z","pushed_at":"2016-06-03T08:01:24Z","git_url":"git://github.com/gnuoy/charms.openstack.git","ssh_url":"git@github.com:gnuoy/charms.openstack.git","clone_url":"https://github.com/gnuoy/charms.openstack.git","svn_url":"https://github.com/gnuoy/charms.openstack","homepage":null,"size":77,"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":"master"}},"base":{"label":"openstack-charmers:master","ref":"master","sha":"cb9cb367e110601a46e7a6e8049cd1c106939c65","user":{"login":"openstack-charmers","id":12201962,"avatar_url":"https://avatars.githubusercontent.com/u/12201962?v=3","gravatar_id":"","url":"https://api.github.com/users/openstack-charmers","html_url":"https://github.com/openstack-charmers","followers_url":"https://api.github.com/users/openstack-charmers/followers","following_url":"https://api.github.com/users/openstack-charmers/following{/other_user}","gists_url":"https://api.github.com/users/openstack-charmers/gists{/gist_id}","starred_url":"https://api.github.com/users/openstack-charmers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openstack-charmers/subscriptions","organizations_url":"https://api.github.com/users/openstack-charmers/orgs","repos_url":"https://api.github.com/users/openstack-charmers/repos","events_url":"https://api.github.com/users/openstack-charmers/events{/privacy}","received_events_url":"https://api.github.com/users/openstack-charmers/received_events","type":"Organization","site_admin":false},"repo":{"id":59580485,"name":"charms.openstack","full_name":"openstack-charmers/charms.openstack","owner":{"login":"openstack-charmers","id":12201962,"avatar_url":"https://avatars.githubusercontent.com/u/12201962?v=3","gravatar_id":"","url":"https://api.github.com/users/openstack-charmers","html_url":"https://github.com/openstack-charmers","followers_url":"https://api.github.com/users/openstack-charmers/followers","following_url":"https://api.github.com/users/openstack-charmers/following{/other_user}","gists_url":"https://api.github.com/users/openstack-charmers/gists{/gist_id}","starred_url":"https://api.github.com/users/openstack-charmers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openstack-charmers/subscriptions","organizations_url":"https://api.github.com/users/openstack-charmers/orgs","repos_url":"https://api.github.com/users/openstack-charmers/repos","events_url":"https://api.github.com/users/openstack-charmers/events{/privacy}","received_events_url":"https://api.github.com/users/openstack-charmers/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/openstack-charmers/charms.openstack","description":"","fork":false,"url":"https://api.github.com/repos/openstack-charmers/charms.openstack","forks_url":"https://api.github.com/repos/openstack-charmers/charms.openstack/forks","keys_url":"https://api.github.com/repos/openstack-charmers/charms.openstack/keys{/key_id}","collaborators_url":"https://api.github.com/repos/openstack-charmers/charms.openstack/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/openstack-charmers/charms.openstack/teams","hooks_url":"https://api.github.com/repos/openstack-charmers/charms.openstack/hooks","issue_events_url":"https://api.github.com/repos/openstack-charmers/charms.openstack/issues/events{/number}","events_url":"https://api.github.com/repos/openstack-charmers/charms.openstack/events","assignees_url":"https://api.github.com/repos/openstack-charmers/charms.openstack/assignees{/user}","branches_url":"https://api.github.com/repos/openstack-charmers/charms.openstack/branches{/branch}","tags_url":"https://api.github.com/repos/openstack-charmers/charms.openstack/tags","blobs_url":"https://api.github.com/repos/openstack-charmers/charms.openstack/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/openstack-charmers/charms.openstack/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/openstack-charmers/charms.openstack/git/refs{/sha}","trees_url":"https://api.github.com/repos/openstack-charmers/charms.openstack/git/trees{/sha}","statuses_url":"https://api.github.com/repos/openstack-charmers/charms.openstack/statuses/{sha}","languages_url":"https://api.github.com/repos/openstack-charmers/charms.openstack/languages","stargazers_url":"https://api.github.com/repos/openstack-charmers/charms.openstack/stargazers","contributors_url":"https://api.github.com/repos/openstack-charmers/charms.openstack/contributors","subscribers_url":"https://api.github.com/repos/openstack-charmers/charms.openstack/subscribers","subscription_url":"https://api.github.com/repos/openstack-charmers/charms.openstack/subscription","commits_url":"https://api.github.com/repos/openstack-charmers/charms.openstack/commits{/sha}","git_commits_url":"https://api.github.com/repos/openstack-charmers/charms.openstack/git/commits{/sha}","comments_url":"https://api.github.com/repos/openstack-charmers/charms.openstack/comments{/number}","issue_comment_url":"https://api.github.com/repos/openstack-charmers/charms.openstack/issues/comments{/number}","contents_url":"https://api.github.com/repos/openstack-charmers/charms.openstack/contents/{+path}","compare_url":"https://api.github.com/repos/openstack-charmers/charms.openstack/compare/{base}...{head}","merges_url":"https://api.github.com/repos/openstack-charmers/charms.openstack/merges","archive_url":"https://api.github.com/repos/openstack-charmers/charms.openstack/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/openstack-charmers/charms.openstack/downloads","issues_url":"https://api.github.com/repos/openstack-charmers/charms.openstack/issues{/number}","pulls_url":"https://api.github.com/repos/openstack-charmers/charms.openstack/pulls{/number}","milestones_url":"https://api.github.com/repos/openstack-charmers/charms.openstack/milestones{/number}","notifications_url":"https://api.github.com/repos/openstack-charmers/charms.openstack/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/openstack-charmers/charms.openstack/labels{/name}","releases_url":"https://api.github.com/repos/openstack-charmers/charms.openstack/releases{/id}","deployments_url":"https://api.github.com/repos/openstack-charmers/charms.openstack/deployments","created_at":"2016-05-24T14:30:03Z","updated_at":"2016-05-31T12:36:20Z","pushed_at":"2016-06-03T08:05:59Z","git_url":"git://github.com/openstack-charmers/charms.openstack.git","ssh_url":"git@github.com:openstack-charmers/charms.openstack.git","clone_url":"https://github.com/openstack-charmers/charms.openstack.git","svn_url":"https://github.com/openstack-charmers/charms.openstack","homepage":null,"size":31,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":1,"forks":3,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/openstack-charmers/charms.openstack/pulls/8"},"html":{"href":"https://github.com/openstack-charmers/charms.openstack/pull/8"},"issue":{"href":"https://api.github.com/repos/openstack-charmers/charms.openstack/issues/8"},"comments":{"href":"https://api.github.com/repos/openstack-charmers/charms.openstack/issues/8/comments"},"review_comments":{"href":"https://api.github.com/repos/openstack-charmers/charms.openstack/pulls/8/comments"},"review_comment":{"href":"https://api.github.com/repos/openstack-charmers/charms.openstack/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/openstack-charmers/charms.openstack/pulls/8/commits"},"statuses":{"href":"https://api.github.com/repos/openstack-charmers/charms.openstack/statuses/81e34f166f67d1aa58c0a7bb181d75443a89c96e"}}}}
{"actor":{"display_login":"ajkavanagh"}}