check point commit to ensure things are saved in more than one place. this commit contains the first integration of the docker build artifacts as well as the first integration of an automation test environment for MAAS based on virtual box

Change-Id: I236f12392501b4ed589aba2b748ba0c45e148f2e
diff --git a/roles/compute-node/tasks/i40e_driver.yml b/roles/compute-node/tasks/i40e_driver.yml
index 5f6b199..69c14cd 100644
--- a/roles/compute-node/tasks/i40e_driver.yml
+++ b/roles/compute-node/tasks/i40e_driver.yml
@@ -2,15 +2,15 @@
 - name: Copy i40e Interface Driver
   unarchive:
     src=files/i40e-1.4.25.tar.gz
-    dest={{ ansible_env.HOME }}
-    owner=ubuntu
-    group=ubuntu
+    dest=/home/{{ ansible_user }}
+    owner={{ ansible_user }}
+    group={{ ansible_user }}
 
 - name: Build i40e Driver
   command: make
   args:
     chdir: i40e-1.4.25/src
-    creates: "{{ ansible_env.HOME }}/i40e-1.4.25/src/i40e/i40e.ko"
+    creates: /home/{{ ansible_user }}/i40e-1.4.25/src/i40e/i40e.ko
 
 - name: Unload i40e Driver
   become: yes
@@ -36,5 +36,5 @@
 
 - name: Remove Build Files
   file:
-    path={{ ansible_env.HOME }}/i40e-1.4.25
+    path=/home/{{ ansible_user }}/i40e-1.4.25
     state=absent
diff --git a/roles/compute-node/tasks/main.yml b/roles/compute-node/tasks/main.yml
index f3ee4aa..f8edc77 100644
--- a/roles/compute-node/tasks/main.yml
+++ b/roles/compute-node/tasks/main.yml
@@ -8,29 +8,29 @@
 - name: Set Default Password
   become: yes
   user:
-    name=ubuntu
+    name={{ ansible_user }}
     password="$6$TjhJuOgh8xp.v$z/4GwFbn5koVmkD6Ex9wY7bgP7L3uP2ujZkZSs1HNdzQdz9YclbnZH9GvqMC/M1iwC0MceL05.13HoFz/bai0/"
 
 - name: Authorize SSH Key
   become: yes
   authorized_key:
     key="{{ pub_ssh_key }}"
-    user=ubuntu
+    user={{ ansible_user }}
     state=present
 
 - name: Verify Private SSH Key
   become: yes
   stat:
-    path=/home/ubuntu/.ssh/id_rsa
+    path=/home/{{ ansible_user }}/.ssh/id_rsa
   register: private_key
 
-- name: Ensure Private SSH Key
+- name: Ensure SSH Key
   become: yes
   copy:
     src=files/{{ item }}
-    dest=/home/ubuntu/.ssh/{{ item }}
-    owner=ubuntu
-    group=ubuntu
+    dest=/home/{{ ansible_user }}/.ssh/{{ item }}
+    owner={{ ansible_user }}
+    group={{ ansible_user }}
     mode=0600
   with_items:
     - id_rsa
@@ -49,6 +49,7 @@
   command: modinfo --field=version i40e
   register: i40e_version
   changed_when: False
+  failed_when: False
   tags:
     - interface_config
 
diff --git a/roles/maas/files/amt.template b/roles/maas/files/amt.template
new file mode 100755
index 0000000..2f2df8c
--- /dev/null
+++ b/roles/maas/files/amt.template
@@ -0,0 +1,48 @@
+#!/bin/bash
+
+POWER_ADDRESS={{power_address}}
+POWER_CHANGE={{power_change}}
+POWER_PASS={{power_pass}}
+POWER_MAC={{mac_address}}
+IP_ADDRESS={{ip_address}}
+BOOT_MODE={{boot_mode}}
+
+get_uuid () {
+    local DATA=$(echo -n "$1" | sed -e 's/://g')
+    echo $(ssh $POWER_PASS@$POWER_ADDRESS vboxmanage list vms | grep "$DATA" | awk '{print $NF}' | sed -e 's/[{}]//g')
+}
+
+query_state () {
+    local state=$(ssh $POWER_PASS@$POWER_ADDRESS vboxmanage showvminfo $1 | grep "^State" | grep -i running | wc -l)
+    if [ $state -eq 1 ]; then
+        echo 'on'
+    else
+        echo 'off'
+    fi
+}
+
+power_on () {
+    ssh $POWER_PASS@$POWER_ADDRESS vboxmanage startvm $1
+    return 0
+}
+
+power_off () {
+    ssh $POWER_PASS@$POWER_ADDRESS vboxmanage controlvm $1 poweroff
+    return 0
+}
+
+main () {
+    case "${POWER_CHANGE}" in
+    'on')
+        power_on "$1"
+        ;;
+    'off')
+        power_off "$1"
+        ;;
+    'query')
+        query_state "$1"
+        ;;
+    esac
+}
+
+main "$(get_uuid $POWER_MAC)" "$POWER_CHANGE"
diff --git a/roles/maas/files/ssh_config b/roles/maas/files/ssh_config
new file mode 100644
index 0000000..f30d239
--- /dev/null
+++ b/roles/maas/files/ssh_config
@@ -0,0 +1,2 @@
+Host *
+    StrictHostKeyChecking no
diff --git a/roles/maas/tasks/main.yml b/roles/maas/tasks/main.yml
index c5be210..65edae6 100644
--- a/roles/maas/tasks/main.yml
+++ b/roles/maas/tasks/main.yml
@@ -158,6 +158,8 @@
   with_items:
     - { url : "https://www.dropbox.com/s/eqxs4kx84omtkha/onie-installer-x86_64-accton_as6712_32x-r0?dl=1", dest : "onie-installer-x86_64-accton_as6712_32x-r0" }
     - { url : "https://www.dropbox.com/s/eqxs4kx84omtkha/onie-installer-x86_64-accton_as6712_32x-r0?dl=1", dest : "onie-installer-x86_64-accton_as5712_54x-r0" }
+  tags:
+    - switch_support
 
 - name: Wait for MAAS to Intialize (start)
   pause:
@@ -166,7 +168,7 @@
 
 - name: Configure MAAS
   become: yes
-  command: docker run -ti ciena/cord-maas-bootstrap:0.1-prerelease --apikey='{{apikey.stdout}}' --sshkey='{{maas.user_sshkey}}' --url='http://{{mgmt_ip_address.stdout}}/MAAS/api/1.0' --network='{{networks.management}}' --interface='{{interfaces.management}}' --zone='administrative' --cluster='Cluster master' --domain='{{maas.domain}}' --bridge='{{networks.bridge_name}}' --bridge-subnet='{{networks.bridge}}'
+  command: docker run ciena/cord-maas-bootstrap:0.1-prerelease --apikey='{{apikey.stdout}}' --sshkey='{{maas.user_sshkey}}' --url='http://{{mgmt_ip_address.stdout}}/MAAS/api/1.0' --network='{{networks.management}}' --interface='{{interfaces.management}}' --zone='administrative' --cluster='Cluster master' --domain='{{maas.domain}}' --bridge='{{networks.bridge_name}}' --bridge-subnet='{{networks.bridge}}'
   register: maas_config_result
   changed_when: maas_config_result.stdout.find("CHANGED") != -1
   failed_when: "'ERROR' in maas_config_result.stdout"
@@ -194,6 +196,33 @@
   register: dns_template_changed
   changed_when: dns_template_changed.stdout == 'true'
 
+- name: Ensure Nameserver
+  become: yes
+  lineinfile:
+    dest: /etc/resolvconf/resolv.conf.d/head
+    state: present
+    insertafter: EOF
+    line: "nameserver {{ mgmt_ip_address.stdout }}" 
+  register: ns_nameserver
+
+- name: Ensure Domain Search
+  become: yes
+  lineinfile:
+    dest: /etc/resolvconf/resolv.conf.d/base
+    state: present
+    insertafter: EOF
+    line: 'search cord.lab'
+  register: ns_search
+
+- name: Ensure DNS
+  become: yes
+  command: resolvconf -u
+  when: ns_nameserver.changed or ns_search.changed
+
+- name: Ensure VirtualBox Power Management
+  include: virtualbox.yml
+  when: virtualbox_support is defined
+
 - name: Custom Automation Compose Configurations
   become: yes
   template:
diff --git a/roles/maas/tasks/virtualbox.yml b/roles/maas/tasks/virtualbox.yml
new file mode 100644
index 0000000..b263886
--- /dev/null
+++ b/roles/maas/tasks/virtualbox.yml
@@ -0,0 +1,38 @@
+- name: VirtualBox Power Support
+  become: yes
+  apt: name={{ item }} state=latest
+  with_items:
+    - amtterm
+    - wsmancli
+
+- name: VirtualBox Power Script
+  become: yes
+  copy:
+    src: files/amt.template
+    dest: /etc/maas/templates/power/amt.template
+    owner: maas
+    group: maas
+    mode: 0755
+
+- name: Ensure SSH Directory
+  become: yes
+  file:
+    path: /var/lib/maas/.ssh
+    state: directory
+    owner: maas
+    group: maas
+    mode: 0700
+
+- name: VirtualBox SSH Support
+  become: yes
+  copy:
+    src: files/{{ item.src }}
+    dest: /var/lib/maas/.ssh/{{ item.dest }}
+    owner: maas
+    group: maas
+    mode: 0600
+  with_items:
+    - { src: cord_id_rsa, dest: id_rsa }
+    - { src: cord_id_rsa.pub, dest: id_rsa.pub }
+    - { src: ssh_config, dest: config }
+
diff --git a/roles/onos-fabric/tasks/main.yml b/roles/onos-fabric/tasks/main.yml
index b2bccc5..74b07e8 100644
--- a/roles/onos-fabric/tasks/main.yml
+++ b/roles/onos-fabric/tasks/main.yml
@@ -1,18 +1,18 @@
 ---
 - name: User Local bin directory
   file:
-    path={{ ansible_env.HOME }}/bin
+    path=/home/{{ ansible_user }}/bin
     state=directory
-    owner=ubuntu
-    group=ubuntu
+    owner={{ ansible_user }}
+    group={{ ansible_user }}
     mode=0755
 
 - name: Copy Utility Commands
   copy:
     src=files/bin/{{ item }}
-    dest={{ ansible_env.HOME }}/bin
-    owner=ubuntu
-    group=ubuntu
+    dest=/home/{{ ansible_user }}/bin
+    owner={{ ansible_user }}
+    group={{ ansible_user }}
     mode=0755
   with_items:
     - minify
@@ -23,7 +23,7 @@
 
 - name: Include Utility Commands in User Path
   lineinfile:
-    dest={{ ansible_env.HOME }}/.bashrc
+    dest=/home/{{ ansible_user }}/.bashrc
     line="PATH=$HOME/bin:$PATH"
     state=present
     insertafter=EOF
@@ -31,15 +31,15 @@
 - name: Custom ONOS
   unarchive:
     src=files/onos-1.6.0.ubuntu.tar.gz
-    dest={{ ansible_env.HOME }}
-    owner=ubuntu
-    group=ubuntu
+    dest=/home/{{ ansible_user }}
+    owner={{ ansible_user }}
+    group={{ ansible_user }}
 
 - name: ONOS Fabric Configuration
   template:
     src=templates/fabric-network-config.json.j2
-    dest={{ ansible_env.HOME }}/fabric-network.config.json
-    owner=ubuntu
-    group=ubuntu
+    dest=/home/{{ ansible_user }}/fabric-network.config.json
+    owner={{ ansible_user }}
+    group={{ ansible_user }}
     mode=0644