Merge branch 'acb-develop'
diff --git a/xos/configurations/cord-pod/cdn/cmi-settings.sh b/xos/configurations/cord-pod/cdn/cmi-settings.sh
index cf05a27..283d7e6 100644
--- a/xos/configurations/cord-pod/cdn/cmi-settings.sh
+++ b/xos/configurations/cord-pod/cdn/cmi-settings.sh
@@ -2,6 +2,6 @@
 # It will be used by setup-cmi.sh and ssh-cmi.sh
 
 COMPUTE_NODE=cp-2.smbaker-xos-vtn.xos-pg0.clemson.cloudlab.us
-MGMT_IP=172.27.0.17
-NODE_KEY=/root/setup/id_rsa.sh
+MGMT_IP=172.27.0.22
+NODE_KEY=/root/setup/id_rsa
 VM_KEY=cmi_id_rsa
diff --git a/xos/configurations/cord-pod/cdn/cmi.yaml b/xos/configurations/cord-pod/cdn/cmi.yaml
index 206f89b..3876de4 100644
--- a/xos/configurations/cord-pod/cdn/cmi.yaml
+++ b/xos/configurations/cord-pod/cdn/cmi.yaml
@@ -12,20 +12,22 @@
     cdn_name: CoBlitz
     gateway_ip: 10.124.0.1
     gateway_mac: 00:8c:fa:5b:09:d8
-    node_hostname: xos-cloudlab-cmi-vtn.opencloud.us
+    node_hostname: xos-cloudlab-node1-vtn.opencloud.us
   tasks:
-#  - name: fix the networking
-#    shell: "{{ item }}"
-#    with_items:
-#      - ip route del default || true
-#      - ip route add default via {{ gateway_ip }}
-#      - arp -s {{ gateway_ip }} {{ gateway_mac }}
+  - name: fix the networking
+    shell: "{{ item }}"
+    with_items:
+      - ip route del default || true
+      - ip route add default via {{ gateway_ip }}
+      - arp -s {{ gateway_ip }} {{ gateway_mac }}
 
-#  - name: copy over setup answers
-#    template: src=templates/setup_answers.txt dest=/root/setup_answers.txt
+  - name: copy over setup answers
+    template: src=templates/setup_answers.txt dest=/root/setup_answers.txt
 
-#  - name: run the setup script
-#    shell: /a/sbin/setup.sh < /root/setup_answers.txt
+  - name: run the setup script
+    shell: /a/sbin/setup.sh < /root/setup_answers.txt
+    args:
+        creates: /a/var/log/setup.log
 
   - name: fix onevapi CDNPrefix bug
     shell: sed -i 's/hostname/str/g' /vservers/coplc/usr/share/cob_api/COB/PublicObjects/CDNPrefix.py
@@ -36,5 +38,34 @@
   - name: copy over cmi setup template
     template: src=templates/setup_cmi_onevsh.sh dest=/vservers/coplc/root/setup_cmi_onevsh.sh
 
+  - name: run cmi setup script
+    command: vserver coplc exec onevsh /root/setup_cmi_onevsh.sh
+
   - name: copy over cmi node setup template
-    template: src=templates/setup_cmi_node.sh dest=/vservers/coplc/root/setup_cdmi_node.sh
+    template: src=templates/setup_cmi_node.sh dest=/vservers/coplc/root/setup_cmi_node.sh
+
+  - name: run node setup script
+    command: vserver coplc exec plcsh /root/setup_cmi_node.sh
+    args:
+        creates: /vservers/coplc/root/takeover-{{ node_hostname }}
+
+  - name: retrieve node takeover script
+    fetch: src=/vservers/coplc/root/takeover-{{ node_hostname }} dest=takeovers/takeover-{{ node_hostname }}
+
+  - name: copy over cmi logical interface template
+    template: src=templates/setup_cmi_logicalinterfaces.sh dest=/vservers/coplc/root/setup_cmi_logicalinterfaces.sh
+
+  - name: run logical interface script
+    command: vserver coplc exec onevsh /root/setup_cmi_logicalinterfaces.sh
+
+  - name: update all keys script
+    copy: src=private/allkeys.template dest=/vservers/coplc/etc/onevantage/services/HPC/templates/usr/local/CoBlitz/var/allkeys.template
+
+  - name: install keygen
+    copy: src=private/keygen dest=/vservers/coplc/etc/onevantage/services/HPC/templates/usr/local/CoBlitz/var/keygen mode=0755
+
+  - name: download socat
+    get_url: url=http://pkgs.repoforge.org/socat/socat-1.7.2.1-1.el6.rf.x86_64.rpm dest=/root/socat-1.7.2.1-1.el6.rf.x86_64.rpm
+ 
+  - name: install socat
+    yum: name=/root/socat-1.7.2.1-1.el6.rf.x86_64.rpm state=present
diff --git a/xos/configurations/cord-pod/cdn/setup-cmi.sh b/xos/configurations/cord-pod/cdn/setup-cmi.sh
index 5f18ddc..8cfe11c 100644
--- a/xos/configurations/cord-pod/cdn/setup-cmi.sh
+++ b/xos/configurations/cord-pod/cdn/setup-cmi.sh
@@ -17,4 +17,4 @@
 export ANSIBLE_CONFIG=cmi.conf
 export ANSIBLE_HOSTS=cmi.hosts
 
-ansible-playbook -vvvv cmi.yaml
+ansible-playbook -v cmi.yaml
diff --git a/xos/configurations/cord-pod/cdn/templates/setup_cmi_logicalinterfaces.sh b/xos/configurations/cord-pod/cdn/templates/setup_cmi_logicalinterfaces.sh
new file mode 100644
index 0000000..2ac8422
--- /dev/null
+++ b/xos/configurations/cord-pod/cdn/templates/setup_cmi_logicalinterfaces.sh
@@ -0,0 +1,14 @@
+lab="External"
+for service in ["HyperCache", "RequestRouter"]:
+    for node in ListAll("Node"):
+        node_id = node["node_id"]
+        for interface_id in node["interface_ids"]:
+            iface=Read("Interface", interface_id)
+            if iface["is_primary"] and len(iface["ip_address_ids"])==1:
+                ip_id = iface["ip_address_ids"][0]
+                if ListAll("LogicalInterface", {"node_id": node_id, "ip_address_ids": [ip_id], "label": lab, "service": service}):
+                    print "External label exists for node", node_id, "ip", ip_id, "service", service
+                else:
+                    print "Adding external label for node", node_id, "ip", ip_id, "service", service
+                    li = Create("LogicalInterface", {"node_id": node_id, "label": lab, "service": service})
+	            Bind("LogicalInterface", li, "IpAddress", ip_id)
diff --git a/xos/configurations/cord-pod/cdn/templates/setup_cmi_node.sh b/xos/configurations/cord-pod/cdn/templates/setup_cmi_node.sh
index 4c1abed..93435a3 100644
--- a/xos/configurations/cord-pod/cdn/templates/setup_cmi_node.sh
+++ b/xos/configurations/cord-pod/cdn/templates/setup_cmi_node.sh
@@ -10,3 +10,11 @@
 ip_id = AddIpAddress(i_id, ipinfo)
 routeinfo = {'interface_id': i_id, 'next_hop': "127.0.0.127", 'subnet': '0.0.0.0', 'metric': 1}
 r_id = AddRoute(n_id, routeinfo)
+hpc_slice_id = GetSlices({"name": "co_coblitz"})[0]["slice_id"]
+AddSliceToNodes(hpc_slice_id, [n_id])
+dnsdemux_slice_id = GetSlices({"name": "co_dnsdemux"})[0]["slice_id"]
+dnsredir_slice_id = GetSlices({"name": "co_dnsredir_coblitz"})[0]["slice_id"]
+AddSliceToNodes(dnsdemux_slice_id, [n_id])
+AddSliceToNodes(dnsredir_slice_id, [n_id])
+takeoverscript=GetBootMedium(n_id, "node-cloudinit", '')
+file("/root/takeover-{{ node_hostname }}","w").write(takeoverscript)
diff --git a/xos/configurations/cord-pod/cdn/templates/setup_cmi_onevsh.sh b/xos/configurations/cord-pod/cdn/templates/setup_cmi_onevsh.sh
index d5ef513..996093d 100644
--- a/xos/configurations/cord-pod/cdn/templates/setup_cmi_onevsh.sh
+++ b/xos/configurations/cord-pod/cdn/templates/setup_cmi_onevsh.sh
@@ -1,4 +1,16 @@
-sp=Create("ServiceProvider", {"account": "openstack", "name": "openstack", "enabled": True})
-cp=Create("ContentProvider", {"account": "test", "name": "test", "enabled": True, "service_provider_id": sp})
-ors=Create("OriginServer", {"url": "http://www.cs.arizona.edu/", "content_provider_id": cp, "service_type": "HyperCache"})
-pre=Create("CDNPrefix", {"service": "HyperCache", "enabled": True, "content_provider_id": cp, "cdn_prefix": "test.vicci.org", "default_origin_server": "http://www.cs.arizona.edu/"})
+def CreateOrFind(kind, args):
+    objs=ListAll(kind, args.copy())
+    if objs:
+        id_name = {"ServiceProvider": "service_provider_id",
+                   "ContentProvider": "content_provider_id",
+                   "OriginServer": "origin_server_id",
+                   "CDNPrefix": "cdn_prefix_id"}
+        print kind, "exists with args", args
+        return objs[0].get(id_name[kind])
+    else:
+	print "create", kind, "with args", args
+        return Create(kind, args)
+sp=CreateOrFind("ServiceProvider", {"account": "cord", "name": "cord", "enabled": True})
+cp=CreateOrFind("ContentProvider", {"account": "test", "name": "test", "enabled": True, "service_provider_id": sp})
+ors=CreateOrFind("OriginServer", {"url": "http://www.cs.arizona.edu", "content_provider_id": cp, "service_type": "HyperCache"})
+pre=CreateOrFind("CDNPrefix", {"service": "HyperCache", "enabled": True, "content_provider_id": cp, "cdn_prefix": "test.vicci.org", "default_origin_server": "http://www.cs.arizona.edu"})