MCP pipeline library merged with ccp-pipeline-libs repo.

Change-Id: I74080e18c5a482b7bf44b5516228b7bfe1fe3586
diff --git a/src/com/mirantis/mk/Orchestrate.groovy b/src/com/mirantis/mk/Orchestrate.groovy
new file mode 100644
index 0000000..a7637e4
--- /dev/null
+++ b/src/com/mirantis/mk/Orchestrate.groovy
@@ -0,0 +1,212 @@
+package com.mirantis.mk
+/**
+ * Orchestration functions
+ *
+*/
+
+def validateFoundationInfra(master) {
+    def salt = new com.mirantis.mk.Salt()
+    salt.runSaltProcessStep(master, 'I@salt:master', 'cmd.run', ['salt-key'])
+    salt.runSaltProcessStep(master, 'I@salt:minion', 'test.version')
+    salt.runSaltProcessStep(master, 'I@salt:master', 'cmd.run', ['reclass-salt --top'])
+    salt.runSaltProcessStep(master, 'I@reclass:storage', 'reclass.inventory')
+    salt.runSaltProcessStep(master, 'I@salt:minion', 'state.show_top')
+}
+
+
+def installFoundationInfra(master) {
+    def salt = new com.mirantis.mk.Salt()
+    salt.runSaltProcessStep(master, 'I@salt:master', 'state.sls', ['salt.master,reclass'])
+    salt.runSaltProcessStep(master, 'I@linux:system', 'saltutil.refresh_pillar')
+    salt.runSaltProcessStep(master, 'I@linux:system', 'saltutil.sync_all')
+    salt.runSaltProcessStep(master, 'I@linux:system', 'state.sls', ['linux,openssh,salt.minion,ntp'])
+}
+
+
+def installOpenstackMkInfra(master) {
+    def salt = new com.mirantis.mk.Salt()
+    // Install keepaliveds
+    //runSaltProcessStep(master, 'I@keepalived:cluster', 'state.sls', ['keepalived'], 1)
+    salt.runSaltProcessStep(master, 'ctl01*', 'state.sls', ['keepalived'])
+    salt.runSaltProcessStep(master, 'I@keepalived:cluster', 'state.sls', ['keepalived'])
+    // Check the keepalived VIPs
+    salt.runSaltProcessStep(master, 'I@keepalived:cluster', 'cmd.run', ['ip a | grep 172.16.10.2'])
+    // Install glusterfs
+    salt.runSaltProcessStep(master, 'I@glusterfs:server', 'state.sls', ['glusterfs.server.service'])
+    //runSaltProcessStep(master, 'I@glusterfs:server', 'state.sls', ['glusterfs.server.setup'], 1)
+    salt.runSaltProcessStep(master, 'ctl01*', 'state.sls', ['glusterfs.server.setup'])
+    salt.runSaltProcessStep(master, 'ctl02*', 'state.sls', ['glusterfs.server.setup'])
+    salt.runSaltProcessStep(master, 'ctl03*', 'state.sls', ['glusterfs.server.setup'])
+    salt.runSaltProcessStep(master, 'I@glusterfs:server', 'cmd.run', ['gluster peer status'])
+    salt.runSaltProcessStep(master, 'I@glusterfs:server', 'cmd.run', ['gluster volume status'])
+    // Install rabbitmq
+    salt.runSaltProcessStep(master, 'I@rabbitmq:server', 'state.sls', ['rabbitmq'])
+    // Check the rabbitmq status
+    salt.runSaltProcessStep(master, 'I@rabbitmq:server', 'cmd.run', ['rabbitmqctl cluster_status'])
+    // Install galera
+    salt.runSaltProcessStep(master, 'I@galera:master', 'state.sls', ['galera'])
+    salt.runSaltProcessStep(master, 'I@galera:slave', 'state.sls', ['galera'])
+    // Check galera status
+    salt.runSaltProcessStep(master, 'I@galera:master', 'mysql.status')
+    salt.runSaltProcessStep(master, 'I@galera:slave', 'mysql.status')
+    // Install haproxy
+    salt.runSaltProcessStep(master, 'I@haproxy:proxy', 'state.sls', ['haproxy'])
+    salt.runSaltProcessStep(master, 'I@haproxy:proxy', 'service.status', ['haproxy'])
+    salt.runSaltProcessStep(master, 'I@haproxy:proxy', 'service.restart', ['rsyslog'])
+    // Install memcached
+    salt.runSaltProcessStep(master, 'I@memcached:server', 'state.sls', ['memcached'])
+}
+
+
+def installOpenstackMkControl(master) {
+    def salt = new com.mirantis.mk.Salt()
+    // setup keystone service
+    //runSaltProcessStep(master, 'I@keystone:server', 'state.sls', ['keystone.server'], 1)
+    salt.runSaltProcessStep(master, 'ctl01*', 'state.sls', ['keystone.server'])
+    salt.runSaltProcessStep(master, 'I@keystone:server', 'state.sls', ['keystone.server'])
+    // populate keystone services/tenants/roles/users
+    salt.runSaltProcessStep(master, 'I@keystone:client', 'state.sls', ['keystone.client'])
+    salt.runSaltProcessStep(master, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; keystone service-list'])
+    // Install glance and ensure glusterfs clusters
+    //runSaltProcessStep(master, 'I@glance:server', 'state.sls', ['glance.server'], 1)
+    salt.runSaltProcessStep(master, 'ctl01*', 'state.sls', ['glance.server'])
+    salt.runSaltProcessStep(master, 'I@glance:server', 'state.sls', ['glance.server'])
+    salt.runSaltProcessStep(master, 'I@glance:server', 'state.sls', ['glusterfs.client'])
+    // Update fernet tokens before doing request on keystone server
+    salt.runSaltProcessStep(master, 'I@keystone:server', 'state.sls', ['keystone.server'])
+    // Check glance service
+    salt.runSaltProcessStep(master, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; glance image-list'])
+    // Install and check nova service
+    //runSaltProcessStep(master, 'I@nova:controller', 'state.sls', ['nova'], 1)
+    salt.runSaltProcessStep(master, 'ctl01*', 'state.sls', ['nova'])
+    salt.runSaltProcessStep(master, 'I@nova:controller', 'state.sls', ['nova'])
+    salt.runSaltProcessStep(master, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; nova service-list'])
+    // Install and check cinder service
+    //runSaltProcessStep(master, 'I@cinder:controller', 'state.sls', ['cinder'], 1)
+    salt.runSaltProcessStep(master, 'ctl01*', 'state.sls', ['cinder'])
+    salt.runSaltProcessStep(master, 'I@cinder:controller', 'state.sls', ['cinder'])
+    salt.runSaltProcessStep(master, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; cinder list'])
+    // Install neutron service
+    //runSaltProcessStep(master, 'I@neutron:server', 'state.sls', ['neutron'], 1)
+    salt.runSaltProcessStep(master, 'ctl01*', 'state.sls', ['neutron'])
+    salt.runSaltProcessStep(master, 'I@neutron:server', 'state.sls', ['neutron'])
+    salt.runSaltProcessStep(master, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; neutron agent-list'])
+    // Install heat service
+    //runSaltProcessStep(master, 'I@heat:server', 'state.sls', ['heat'], 1)
+    salt.runSaltProcessStep(master, 'ctl01*', 'state.sls', ['heat'])
+    salt.runSaltProcessStep(master, 'I@heat:server', 'state.sls', ['heat'])
+    salt.runSaltProcessStep(master, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; heat resource-type-list'])
+    // Install horizon dashboard
+    runSaltProcessStep(master, 'I@horizon:server', 'state.sls', ['horizon'])
+    runSaltProcessStep(master, 'I@nginx:server', 'state.sls', ['nginx'])
+}
+
+
+def installOpenstackMkNetwork(master) {
+    def salt = new com.mirantis.mk.Salt()
+    // Install opencontrail database services
+    //runSaltProcessStep(master, 'I@opencontrail:database', 'state.sls', ['opencontrail.database'], 1)
+    salt.runSaltProcessStep(master, 'ntw01*', 'state.sls', ['opencontrail.database'])
+    salt.runSaltProcessStep(master, 'I@opencontrail:database', 'state.sls', ['opencontrail.database'])
+    // Install opencontrail control services
+    //runSaltProcessStep(master, 'I@opencontrail:control', 'state.sls', ['opencontrail'], 1)
+    salt.runSaltProcessStep(master, 'ntw01*', 'state.sls', ['opencontrail'])
+    salt.runSaltProcessStep(master, 'I@opencontrail:control', 'state.sls', ['opencontrail'])
+    // Provision opencontrail control services
+    salt.runSaltProcessStep(master, 'I@opencontrail:control:id:1', 'cmd.run', ['/usr/share/contrail-utils/provision_control.py --api_server_ip 172.16.10.254 --api_server_port 8082 --host_name ctl01 --host_ip 172.16.10.101 --router_asn 64512 --admin_password workshop --admin_user admin --admin_tenant_name admin --oper add'])
+    salt.runSaltProcessStep(master, 'I@opencontrail:control:id:1', 'cmd.run', ['/usr/share/contrail-utils/provision_control.py --api_server_ip 172.16.10.254 --api_server_port 8082 --host_name ctl02 --host_ip 172.16.10.102 --router_asn 64512 --admin_password workshop --admin_user admin --admin_tenant_name admin --oper add'])
+    salt.runSaltProcessStep(master, 'I@opencontrail:control:id:1', 'cmd.run', ['/usr/share/contrail-utils/provision_control.py --api_server_ip 172.16.10.254 --api_server_port 8082 --host_name ctl03 --host_ip 172.16.10.103 --router_asn 64512 --admin_password workshop --admin_user admin --admin_tenant_name admin --oper add'])
+    // Test opencontrail
+    salt.runSaltProcessStep(master, 'I@opencontrail:control', 'cmd.run', ['contrail-status'])
+    salt.runSaltProcessStep(master, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; neutron net-list'])
+    salt.runSaltProcessStep(master, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; nova net-list'])
+}
+
+
+def installOpenstackMkCompute(master) {
+     def salt = new com.mirantis.mk.Salt()
+    // Configure compute nodes
+    salt.runSaltProcessStep(master, 'I@nova:compute', 'state.apply')
+    salt.runSaltProcessStep(master, 'I@nova:compute', 'state.apply')
+    // Provision opencontrail virtual routers
+    salt.runSaltProcessStep(master, 'I@opencontrail:control:id:1', 'cmd.run', ['/usr/share/contrail-utils/provision_vrouter.py --host_name cmp01 --host_ip 172.16.10.105 --api_server_ip 172.16.10.254 --oper add --admin_user admin --admin_password workshop --admin_tenant_name admin'])
+    salt.runSaltProcessStep(master, 'I@nova:compute', 'system.reboot')
+}
+
+
+def installOpenstackMcpInfra(master) {
+     def salt = new com.mirantis.mk.Salt()
+    // Comment nameserver
+    salt.runSaltProcessStep(master, 'I@kubernetes:master', 'cmd.run', ["sed -i 's/nameserver 10.254.0.10/#nameserver 10.254.0.10/g' /etc/resolv.conf"])
+    // Install glusterfs
+    salt.runSaltProcessStep(master, 'I@glusterfs:server', 'state.sls', ['glusterfs.server.service'])
+    // Install keepalived
+    salt.runSaltProcessStep(master, 'ctl01*', 'state.sls', ['keepalived'])
+    salt.runSaltProcessStep(master, 'I@keepalived:cluster', 'state.sls', ['keepalived'])
+    // Check the keepalived VIPs
+    salt.runSaltProcessStep(master, 'I@keepalived:cluster', 'cmd.run', ['ip a | grep 172.16.10.2'])
+    // Setup glusterfs
+    salt.runSaltProcessStep(master, 'ctl01*', 'state.sls', ['glusterfs.server.setup'])
+    salt.runSaltProcessStep(master, 'ctl02*', 'state.sls', ['glusterfs.server.setup'])
+    salt.runSaltProcessStep(master, 'ctl03*', 'state.sls', ['glusterfs.server.setup'])
+    salt.runSaltProcessStep(master, 'I@glusterfs:server', 'cmd.run', ['gluster peer status'])
+    salt.runSaltProcessStep(master, 'I@glusterfs:server', 'cmd.run', ['gluster volume status'])
+    // Install haproxy
+    salt.runSaltProcessStep(master, 'I@haproxy:proxy', 'state.sls', ['haproxy'])
+    salt.runSaltProcessStep(master, 'I@haproxy:proxy', 'service.status', ['haproxy'])
+    // Install docker
+    salt.runSaltProcessStep(master, 'I@docker:host', 'state.sls', ['docker.host'])
+    salt.runSaltProcessStep(master, 'I@docker:host', 'cmd.run', ['docker ps'])
+    // Install bird
+    salt.runSaltProcessStep(master, 'I@bird:server', 'state.sls', ['bird'])
+    // Install etcd
+    salt.runSaltProcessStep(master, 'I@etcd:server', 'state.sls', ['etcd.server.service'])
+    salt.runSaltProcessStep(master, 'I@etcd:server', 'cmd.run', ['etcdctl cluster-health'])
+}
+
+
+def installOpenstackMcpControl(master) {
+    def salt = new com.mirantis.mk.Salt()
+    // Install Kubernetes pool and Calico
+    salt.runSaltProcessStep(master, 'I@kubernetes:pool', 'state.sls', ['kubernetes.pool'])
+    salt.runSaltProcessStep(master, 'I@kubernetes:pool', 'cmd.run', ['calicoctl node status'])
+
+    // Setup etcd server
+    salt.runSaltProcessStep(master, 'I@kubernetes:master', 'state.sls', ['etcd.server.setup'])
+
+    // Run k8s without master.setup
+    salt.runSaltProcessStep(master, 'I@kubernetes:master', 'state.sls', ['kubernetes', 'exclude=kubernetes.master.setup'])
+
+    // Run k8s master setup
+    salt.runSaltProcessStep(master, 'ctl01*', 'state.sls', ['kubernetes.master.setup'])
+
+    // Revert comment nameserver
+    salt.runSaltProcessStep(master, 'I@kubernetes:master', 'cmd.run', ["sed -i 's/nameserver 10.254.0.10/#nameserver 10.254.0.10/g' /etc/resolv.conf"])
+
+    // Set route
+    salt.runSaltProcessStep(master, 'I@kubernetes:pool', 'cmd.run', ['ip r a 10.254.0.0/16 dev ens4'])
+
+    // Restart kubelet
+    salt.runSaltProcessStep(master, 'I@kubernetes:pool', 'service.restart', ['kubelet'])
+}
+
+
+def installOpenstackMcpCompute(master) {
+    def salt = new com.mirantis.mk.Salt();
+    // Install opencontrail
+    salt.runSaltProcessStep(master, 'I@opencontrail:compute', 'state.sls', ['opencontrail'])
+    // Reboot compute nodes
+    salt.runSaltProcessStep(master, 'I@opencontrail:compute', 'system.reboot')
+}
+
+
+def installStacklightControl(master) {
+    def salt = new com.mirantis.mk.Salt();
+    salt.runSaltProcessStep(master, 'I@elasticsearch:server', 'state.sls', ['elasticsearch.server'])
+    salt.runSaltProcessStep(master, 'I@influxdb:server', 'state.sls', ['influxdb'])
+    salt.runSaltProcessStep(master, 'I@kibana:server', 'state.sls', ['kibana.server'])
+    salt.runSaltProcessStep(master, 'I@grafana:server', 'state.sls', ['grafana'])
+    salt.runSaltProcessStep(master, 'I@nagios:server', 'state.sls', ['nagios'])
+    salt.runSaltProcessStep(master, 'I@elasticsearch:client', 'state.sls', ['elasticsearch.client'])
+    salt.runSaltProcessStep(master, 'I@kibana:client', 'state.sls', ['kibana.client'])
+}
\ No newline at end of file