{"action":"created","comment":{"url":"https://api.github.com/repos/nthomas-redhat/USM/pulls/comments/26302771","id":26302771,"diff_hunk":"@@ -0,0 +1,234 @@\n+import random\n+import logging\n+import uuid\n+import time\n+\n+from usm_rest_api.models import Cluster\n+from usm_rest_api.v1.serializers.serializers import ClusterSerializer\n+from usm_rest_api.models import Host\n+from usm_rest_api.v1.serializers.serializers import HostSerializer\n+\n+from usm_wrappers import salt_wrapper\n+from usm_wrappers import utils as usm_wrapper_utils\n+\n+\n+log = logging.getLogger('django.request')\n+\n+\n+CLUSTER_TYPE_GLUSTER = 1\n+CLUSTER_TYPE_CEPH = 2\n+STORAGE_TYPE_BLOCK = 1\n+STORAGE_TYPE_FILE = 2\n+STORAGE_TYPE_OBJECT = 3\n+STATUS_INACTIVE = 1\n+STATUS_ACTIVE_NOT_AVAILABLE = 2\n+STATUS_ACTIVE_AND_AVAILABLE = 3\n+HOST_TYPE_MONITOR = 1\n+HOST_TYPE_OSD = 2\n+HOST_TYPE_MIXED = 3\n+HOST_TYPE_GLUSTER = 4\n+HOST_STATUS_INACTIVE = 1\n+HOST_STATUS_ACTIVE = 2\n+\n+\n+def peer(hostlist, newNode):\n+    rc = False\n+    if hostlist:\n+        host = random.choice(hostlist)\n+\n+        rc = salt_wrapper.peer(host, newNode)\n+        if rc is True:\n+            return rc\n+        #\n+        # random host is not able to peer probe\n+        # Now try to iterate through the list of hosts\n+        # in the cluster to peer probe until\n+        # the peer probe is successful\n+        #\n+\n+        # No need to send it to host which we already tried\n+        hostlist.remove(host)\n+        for host in hostlist:\n+            rc = salt_wrapper.peer(host, newNode)\n+            if rc is True:\n+                return rc\n+        return rc\n+    else:\n+        return True\n+\n+\n+def create_cluster(cluster_data):\n+    # create the cluster\n+    cluster_data['cluster_id'] = str(uuid.uuid4())\n+    try:\n+        clusterSerilaizer = ClusterSerializer(data=cluster_data)\n+        if clusterSerilaizer.is_valid():\n+            clusterSerilaizer.save()\n+        else:\n+                log.error(\n+                    \"Cluster Creation failed. Invalid clusterSerilaizer\")\n+                log.error(\n+                    \"clusterSerilaizer Err: %s\" % clusterSerilaizer.errors)\n+                raise Exception(\n+                    \"Cluster Creation failed. Invalid clusterSerilaizer\",\n+                    clusterSerilaizer.errors)\n+    except Exception, e:\n+        log.exception(e)\n+        raise e\n+\n+\n+def setup_transport_and_update_db(cluster_data, nodelist):\n+    log.debug(\"Inside setup_transport_and_update_db function\")\n+    failedNodes = []\n+\n+    # Create the Nodes in the cluster\n+    # Setup the host communication channel\n+    # current_task.update_state(state='ESTABLISH_HOST_COMMUNICATION')\n+    minionIds = {}\n+    for node in nodelist:\n+        try:\n+            ssh_fingerprint = usm_wrapper_utils.get_host_ssh_key(\n+                node['management_ip'])\n+            minionIds[node['management_ip']] = salt_wrapper.setup_minion(\n+                node['management_ip'], ssh_fingerprint[0],\n+                node['ssh_username'], node['ssh_password'])\n+        except Exception, e:\n+            log.exception(e)\n+            failedNodes.append(node)\n+    log.debug(minionIds)\n+    # Sleep for sometime to make sure all the restarted minions are back\n+    # online\n+    time.sleep(3)\n+    log.debug(\"Accepting the minions keys\")\n+    # current_task.update_state(state='ADD_MINION_KEYS_AND_DB_UPDATE')\n+\n+    # Accept the keys of the successful minions and add to the DB\n+    for node in nodelist:\n+        try:\n+            if node not in failedNodes:\n+                salt_wrapper.accept_minion(minionIds[node['management_ip']])\n+        except Exception, e:\n+            log.exception(e)\n+            failedNodes.append(node)\n+    log.debug(minionIds)\n+    #\n+    # Wait for some time so that the communication chanel is ready\n+    #\n+    time.sleep(15)","path":"usm_rest_api/v1/views/utils.py","position":117,"original_position":117,"commit_id":"a31a189c653ca72718ca4242176637b82edde38b","original_commit_id":"a31a189c653ca72718ca4242176637b82edde38b","user":{"login":"GregMeno","id":290210,"avatar_url":"https://avatars.githubusercontent.com/u/290210?v=3","gravatar_id":"","url":"https://api.github.com/users/GregMeno","html_url":"https://github.com/GregMeno","followers_url":"https://api.github.com/users/GregMeno/followers","following_url":"https://api.github.com/users/GregMeno/following{/other_user}","gists_url":"https://api.github.com/users/GregMeno/gists{/gist_id}","starred_url":"https://api.github.com/users/GregMeno/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GregMeno/subscriptions","organizations_url":"https://api.github.com/users/GregMeno/orgs","repos_url":"https://api.github.com/users/GregMeno/repos","events_url":"https://api.github.com/users/GregMeno/events{/privacy}","received_events_url":"https://api.github.com/users/GregMeno/received_events","type":"User","site_admin":false},"body":"This sleep got longer. Would you please turn this into a module level \"constant\" with a TODO comment on how you expect this to go away?","created_at":"2015-03-12T14:01:06Z","updated_at":"2015-03-12T14:01:06Z","html_url":"https://github.com/nthomas-redhat/USM/pull/5#discussion_r26302771","pull_request_url":"https://api.github.com/repos/nthomas-redhat/USM/pulls/5","_links":{"self":{"href":"https://api.github.com/repos/nthomas-redhat/USM/pulls/comments/26302771"},"html":{"href":"https://github.com/nthomas-redhat/USM/pull/5#discussion_r26302771"},"pull_request":{"href":"https://api.github.com/repos/nthomas-redhat/USM/pulls/5"}}},"pull_request":{"url":"https://api.github.com/repos/nthomas-redhat/USM/pulls/5","id":30751646,"html_url":"https://github.com/nthomas-redhat/USM/pull/5","diff_url":"https://github.com/nthomas-redhat/USM/pull/5.diff","patch_url":"https://github.com/nthomas-redhat/USM/pull/5.patch","issue_url":"https://api.github.com/repos/nthomas-redhat/USM/issues/5","number":5,"state":"open","locked":false,"title":"USM:Refactor web layer","user":{"login":"nthomas-redhat","id":6671718,"avatar_url":"https://avatars.githubusercontent.com/u/6671718?v=3","gravatar_id":"","url":"https://api.github.com/users/nthomas-redhat","html_url":"https://github.com/nthomas-redhat","followers_url":"https://api.github.com/users/nthomas-redhat/followers","following_url":"https://api.github.com/users/nthomas-redhat/following{/other_user}","gists_url":"https://api.github.com/users/nthomas-redhat/gists{/gist_id}","starred_url":"https://api.github.com/users/nthomas-redhat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nthomas-redhat/subscriptions","organizations_url":"https://api.github.com/users/nthomas-redhat/orgs","repos_url":"https://api.github.com/users/nthomas-redhat/repos","events_url":"https://api.github.com/users/nthomas-redhat/events{/privacy}","received_events_url":"https://api.github.com/users/nthomas-redhat/received_events","type":"User","site_admin":false},"body":"Modifications to account for backend refactoring. Also added\r\nfew utility APIs. Removed create_cluster webservice and cluster\r\ncreation is now part of cluster resource itself. Also added the code\r\nto set the cluster and host status appropriately\r\n\r\nSigned-off-by: nthomas <nishusemail@gmail.com>","created_at":"2015-03-09T11:06:41Z","updated_at":"2015-03-12T14:01:06Z","closed_at":null,"merged_at":null,"merge_commit_sha":"36debbfbb058fc66195fa635ac2000480ed1d826","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/nthomas-redhat/USM/pulls/5/commits","review_comments_url":"https://api.github.com/repos/nthomas-redhat/USM/pulls/5/comments","review_comment_url":"https://api.github.com/repos/nthomas-redhat/USM/pulls/comments{/number}","comments_url":"https://api.github.com/repos/nthomas-redhat/USM/issues/5/comments","statuses_url":"https://api.github.com/repos/nthomas-redhat/USM/statuses/a31a189c653ca72718ca4242176637b82edde38b","head":{"label":"nthomas-redhat:refactor-weblayer","ref":"refactor-weblayer","sha":"a31a189c653ca72718ca4242176637b82edde38b","user":{"login":"nthomas-redhat","id":6671718,"avatar_url":"https://avatars.githubusercontent.com/u/6671718?v=3","gravatar_id":"","url":"https://api.github.com/users/nthomas-redhat","html_url":"https://github.com/nthomas-redhat","followers_url":"https://api.github.com/users/nthomas-redhat/followers","following_url":"https://api.github.com/users/nthomas-redhat/following{/other_user}","gists_url":"https://api.github.com/users/nthomas-redhat/gists{/gist_id}","starred_url":"https://api.github.com/users/nthomas-redhat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nthomas-redhat/subscriptions","organizations_url":"https://api.github.com/users/nthomas-redhat/orgs","repos_url":"https://api.github.com/users/nthomas-redhat/repos","events_url":"https://api.github.com/users/nthomas-redhat/events{/privacy}","received_events_url":"https://api.github.com/users/nthomas-redhat/received_events","type":"User","site_admin":false},"repo":{"id":29519166,"name":"USM","full_name":"nthomas-redhat/USM","owner":{"login":"nthomas-redhat","id":6671718,"avatar_url":"https://avatars.githubusercontent.com/u/6671718?v=3","gravatar_id":"","url":"https://api.github.com/users/nthomas-redhat","html_url":"https://github.com/nthomas-redhat","followers_url":"https://api.github.com/users/nthomas-redhat/followers","following_url":"https://api.github.com/users/nthomas-redhat/following{/other_user}","gists_url":"https://api.github.com/users/nthomas-redhat/gists{/gist_id}","starred_url":"https://api.github.com/users/nthomas-redhat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nthomas-redhat/subscriptions","organizations_url":"https://api.github.com/users/nthomas-redhat/orgs","repos_url":"https://api.github.com/users/nthomas-redhat/repos","events_url":"https://api.github.com/users/nthomas-redhat/events{/privacy}","received_events_url":"https://api.github.com/users/nthomas-redhat/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/nthomas-redhat/USM","description":"Repository Unified Storage Manager Project","fork":false,"url":"https://api.github.com/repos/nthomas-redhat/USM","forks_url":"https://api.github.com/repos/nthomas-redhat/USM/forks","keys_url":"https://api.github.com/repos/nthomas-redhat/USM/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nthomas-redhat/USM/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nthomas-redhat/USM/teams","hooks_url":"https://api.github.com/repos/nthomas-redhat/USM/hooks","issue_events_url":"https://api.github.com/repos/nthomas-redhat/USM/issues/events{/number}","events_url":"https://api.github.com/repos/nthomas-redhat/USM/events","assignees_url":"https://api.github.com/repos/nthomas-redhat/USM/assignees{/user}","branches_url":"https://api.github.com/repos/nthomas-redhat/USM/branches{/branch}","tags_url":"https://api.github.com/repos/nthomas-redhat/USM/tags","blobs_url":"https://api.github.com/repos/nthomas-redhat/USM/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nthomas-redhat/USM/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nthomas-redhat/USM/git/refs{/sha}","trees_url":"https://api.github.com/repos/nthomas-redhat/USM/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nthomas-redhat/USM/statuses/{sha}","languages_url":"https://api.github.com/repos/nthomas-redhat/USM/languages","stargazers_url":"https://api.github.com/repos/nthomas-redhat/USM/stargazers","contributors_url":"https://api.github.com/repos/nthomas-redhat/USM/contributors","subscribers_url":"https://api.github.com/repos/nthomas-redhat/USM/subscribers","subscription_url":"https://api.github.com/repos/nthomas-redhat/USM/subscription","commits_url":"https://api.github.com/repos/nthomas-redhat/USM/commits{/sha}","git_commits_url":"https://api.github.com/repos/nthomas-redhat/USM/git/commits{/sha}","comments_url":"https://api.github.com/repos/nthomas-redhat/USM/comments{/number}","issue_comment_url":"https://api.github.com/repos/nthomas-redhat/USM/issues/comments{/number}","contents_url":"https://api.github.com/repos/nthomas-redhat/USM/contents/{+path}","compare_url":"https://api.github.com/repos/nthomas-redhat/USM/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nthomas-redhat/USM/merges","archive_url":"https://api.github.com/repos/nthomas-redhat/USM/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nthomas-redhat/USM/downloads","issues_url":"https://api.github.com/repos/nthomas-redhat/USM/issues{/number}","pulls_url":"https://api.github.com/repos/nthomas-redhat/USM/pulls{/number}","milestones_url":"https://api.github.com/repos/nthomas-redhat/USM/milestones{/number}","notifications_url":"https://api.github.com/repos/nthomas-redhat/USM/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nthomas-redhat/USM/labels{/name}","releases_url":"https://api.github.com/repos/nthomas-redhat/USM/releases{/id}","created_at":"2015-01-20T08:17:17Z","updated_at":"2015-02-27T15:00:55Z","pushed_at":"2015-03-12T07:33:24Z","git_url":"git://github.com/nthomas-redhat/USM.git","ssh_url":"git@github.com:nthomas-redhat/USM.git","clone_url":"https://github.com/nthomas-redhat/USM.git","svn_url":"https://github.com/nthomas-redhat/USM","homepage":null,"size":376,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":3,"forks":2,"open_issues":3,"watchers":0,"default_branch":"master"}},"base":{"label":"nthomas-redhat:master","ref":"master","sha":"1444335503347572d9110c572efc0706ed05d16d","user":{"login":"nthomas-redhat","id":6671718,"avatar_url":"https://avatars.githubusercontent.com/u/6671718?v=3","gravatar_id":"","url":"https://api.github.com/users/nthomas-redhat","html_url":"https://github.com/nthomas-redhat","followers_url":"https://api.github.com/users/nthomas-redhat/followers","following_url":"https://api.github.com/users/nthomas-redhat/following{/other_user}","gists_url":"https://api.github.com/users/nthomas-redhat/gists{/gist_id}","starred_url":"https://api.github.com/users/nthomas-redhat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nthomas-redhat/subscriptions","organizations_url":"https://api.github.com/users/nthomas-redhat/orgs","repos_url":"https://api.github.com/users/nthomas-redhat/repos","events_url":"https://api.github.com/users/nthomas-redhat/events{/privacy}","received_events_url":"https://api.github.com/users/nthomas-redhat/received_events","type":"User","site_admin":false},"repo":{"id":29519166,"name":"USM","full_name":"nthomas-redhat/USM","owner":{"login":"nthomas-redhat","id":6671718,"avatar_url":"https://avatars.githubusercontent.com/u/6671718?v=3","gravatar_id":"","url":"https://api.github.com/users/nthomas-redhat","html_url":"https://github.com/nthomas-redhat","followers_url":"https://api.github.com/users/nthomas-redhat/followers","following_url":"https://api.github.com/users/nthomas-redhat/following{/other_user}","gists_url":"https://api.github.com/users/nthomas-redhat/gists{/gist_id}","starred_url":"https://api.github.com/users/nthomas-redhat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nthomas-redhat/subscriptions","organizations_url":"https://api.github.com/users/nthomas-redhat/orgs","repos_url":"https://api.github.com/users/nthomas-redhat/repos","events_url":"https://api.github.com/users/nthomas-redhat/events{/privacy}","received_events_url":"https://api.github.com/users/nthomas-redhat/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/nthomas-redhat/USM","description":"Repository Unified Storage Manager Project","fork":false,"url":"https://api.github.com/repos/nthomas-redhat/USM","forks_url":"https://api.github.com/repos/nthomas-redhat/USM/forks","keys_url":"https://api.github.com/repos/nthomas-redhat/USM/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nthomas-redhat/USM/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nthomas-redhat/USM/teams","hooks_url":"https://api.github.com/repos/nthomas-redhat/USM/hooks","issue_events_url":"https://api.github.com/repos/nthomas-redhat/USM/issues/events{/number}","events_url":"https://api.github.com/repos/nthomas-redhat/USM/events","assignees_url":"https://api.github.com/repos/nthomas-redhat/USM/assignees{/user}","branches_url":"https://api.github.com/repos/nthomas-redhat/USM/branches{/branch}","tags_url":"https://api.github.com/repos/nthomas-redhat/USM/tags","blobs_url":"https://api.github.com/repos/nthomas-redhat/USM/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nthomas-redhat/USM/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nthomas-redhat/USM/git/refs{/sha}","trees_url":"https://api.github.com/repos/nthomas-redhat/USM/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nthomas-redhat/USM/statuses/{sha}","languages_url":"https://api.github.com/repos/nthomas-redhat/USM/languages","stargazers_url":"https://api.github.com/repos/nthomas-redhat/USM/stargazers","contributors_url":"https://api.github.com/repos/nthomas-redhat/USM/contributors","subscribers_url":"https://api.github.com/repos/nthomas-redhat/USM/subscribers","subscription_url":"https://api.github.com/repos/nthomas-redhat/USM/subscription","commits_url":"https://api.github.com/repos/nthomas-redhat/USM/commits{/sha}","git_commits_url":"https://api.github.com/repos/nthomas-redhat/USM/git/commits{/sha}","comments_url":"https://api.github.com/repos/nthomas-redhat/USM/comments{/number}","issue_comment_url":"https://api.github.com/repos/nthomas-redhat/USM/issues/comments{/number}","contents_url":"https://api.github.com/repos/nthomas-redhat/USM/contents/{+path}","compare_url":"https://api.github.com/repos/nthomas-redhat/USM/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nthomas-redhat/USM/merges","archive_url":"https://api.github.com/repos/nthomas-redhat/USM/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nthomas-redhat/USM/downloads","issues_url":"https://api.github.com/repos/nthomas-redhat/USM/issues{/number}","pulls_url":"https://api.github.com/repos/nthomas-redhat/USM/pulls{/number}","milestones_url":"https://api.github.com/repos/nthomas-redhat/USM/milestones{/number}","notifications_url":"https://api.github.com/repos/nthomas-redhat/USM/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nthomas-redhat/USM/labels{/name}","releases_url":"https://api.github.com/repos/nthomas-redhat/USM/releases{/id}","created_at":"2015-01-20T08:17:17Z","updated_at":"2015-02-27T15:00:55Z","pushed_at":"2015-03-12T07:33:24Z","git_url":"git://github.com/nthomas-redhat/USM.git","ssh_url":"git@github.com:nthomas-redhat/USM.git","clone_url":"https://github.com/nthomas-redhat/USM.git","svn_url":"https://github.com/nthomas-redhat/USM","homepage":null,"size":376,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":3,"forks":2,"open_issues":3,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/nthomas-redhat/USM/pulls/5"},"html":{"href":"https://github.com/nthomas-redhat/USM/pull/5"},"issue":{"href":"https://api.github.com/repos/nthomas-redhat/USM/issues/5"},"comments":{"href":"https://api.github.com/repos/nthomas-redhat/USM/issues/5/comments"},"review_comments":{"href":"https://api.github.com/repos/nthomas-redhat/USM/pulls/5/comments"},"review_comment":{"href":"https://api.github.com/repos/nthomas-redhat/USM/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/nthomas-redhat/USM/pulls/5/commits"},"statuses":{"href":"https://api.github.com/repos/nthomas-redhat/USM/statuses/a31a189c653ca72718ca4242176637b82edde38b"}}}}