diff options
Diffstat (limited to 'deploy/adapters')
20 files changed, 250 insertions, 149 deletions
diff --git a/deploy/adapters/ansible/openstack_juno/.gitkeep b/deploy/adapters/ansible/openstack_juno/.gitkeep new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/deploy/adapters/ansible/openstack_juno/.gitkeep diff --git a/deploy/adapters/ansible/openstack_kilo/.gitkeep b/deploy/adapters/ansible/openstack_kilo/.gitkeep new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/deploy/adapters/ansible/openstack_kilo/.gitkeep diff --git a/deploy/adapters/ansible/roles/cinder-controller/templates/cinder_init.sh b/deploy/adapters/ansible/roles/cinder-controller/templates/cinder_init.sh index abe4d06a..bc92bac0 100644 --- a/deploy/adapters/ansible/roles/cinder-controller/templates/cinder_init.sh +++ b/deploy/adapters/ansible/roles/cinder-controller/templates/cinder_init.sh @@ -2,5 +2,5 @@ keystone --os-token={{ ADMIN_TOKEN }} --os-endpoint=http://{{ internal_vip.ip }} keystone --os-token={{ ADMIN_TOKEN }} --os-endpoint=http://{{ internal_vip.ip }}:35357/v2.0 user-role-add --user=cinder --tenant=service --role=admin keystone --os-token={{ ADMIN_TOKEN }} --os-endpoint=http://{{ internal_vip.ip }}:35357/v2.0 service-create --name=cinder --type=volume --description="OpenStack Block Storage" -keystone --os-token={{ ADMIN_TOKEN }} --os-endpoint=http://{{ internal_vip.ip }}:35357/v2.0 endpoint-create --service-id=$(keystone --os-token={{ ADMIN_TOKEN }} --os-endpoint=http://{{ internal_vip.ip }}:35357/v2.0 service-list | awk '/ volume / {print $2}') --publicurl=http://{{ internal_vip.ip }}:8776/v1/%\(tenant_id\)s --internalurl=http://{{ internal_vip.ip }}:8776/v1/%\(tenant_id\)s --adminurl=http://{{ internal_vip.ip }}:8776/v1/%\(tenant_id\)s +keystone --os-token={{ ADMIN_TOKEN }} --os-endpoint=http://{{ internal_vip.ip }}:35357/v2.0 endpoint-create --service-id=$(keystone --os-token={{ ADMIN_TOKEN }} --os-endpoint=http://{{ internal_vip.ip }}:35357/v2.0 service-list | awk '/ volume / {print $2}') --publicurl=http://{{ public_vip.ip }}:8776/v1/%\(tenant_id\)s --internalurl=http://{{ internal_vip.ip }}:8776/v1/%\(tenant_id\)s --adminurl=http://{{ internal_vip.ip }}:8776/v1/%\(tenant_id\)s diff --git a/deploy/adapters/ansible/roles/cinder-volume/tasks/main.yml b/deploy/adapters/ansible/roles/cinder-volume/tasks/main.yml index 3700bcdd..b64024da 100644 --- a/deploy/adapters/ansible/roles/cinder-volume/tasks/main.yml +++ b/deploy/adapters/ansible/roles/cinder-volume/tasks/main.yml @@ -43,6 +43,10 @@ shell: losetup {{ first_lo.stdout }} /mnt/cinder-volumes when: cindervolumes.stdout != 'cinder-volumes' +- name: destroy GPT lable + shell: dd if=/dev/urandom of=/dev/sdb bs=4M count=1 + ignore_errors: True + - name: create physical and group volumes lvg: vg=cinder-volumes pvs={{ physical_device }} vg_options=--force diff --git a/deploy/adapters/ansible/roles/common/tasks/main.yml b/deploy/adapters/ansible/roles/common/tasks/main.yml index b58bb44d..ead70aed 100644 --- a/deploy/adapters/ansible/roles/common/tasks/main.yml +++ b/deploy/adapters/ansible/roles/common/tasks/main.yml @@ -36,13 +36,20 @@ - name: update pip.conf template: src=pip.conf dest=~/.pip/pip.conf -- name: sync between sys clock and hard clock - command: su -s /bin/sh -c "service {{ ntp_service }} stop; ntpd -gq; hwclock --systohc" - ignore_errors: True - - name: update ntp conf template: src=ntp.conf dest=/etc/ntp.conf backup=yes +- name: stop ntp + service: name={{ ntp_service }} state=stopped enabled=yes + +- name: use ntpdate once for initial sync time + shell: ntpdate {{ ntp_server }} + ignore_errors: True + +- name: sync sys clock to hard clock + shell: hwclock --systohc + ignore_errors: True + - name: restart ntp service: name={{ ntp_service }} state=restarted enabled=yes diff --git a/deploy/adapters/ansible/roles/common/templates/ntp.conf b/deploy/adapters/ansible/roles/common/templates/ntp.conf index c6138092..2d560be2 100644 --- a/deploy/adapters/ansible/roles/common/templates/ntp.conf +++ b/deploy/adapters/ansible/roles/common/templates/ntp.conf @@ -16,14 +16,12 @@ filegen clockstats file clockstats type day enable # Use servers from the NTP Pool Project. Approved by Ubuntu Technical Board # on 2011-02-08 (LP: #104525). See http://www.pool.ntp.org/join.html for # more information. -server {{ NTP_SERVER_LOCAL }} -server 0.ubuntu.pool.ntp.org -server 1.ubuntu.pool.ntp.org -server 2.ubuntu.pool.ntp.org -server 3.ubuntu.pool.ntp.org +server {{ ntp_server }} +server {{ internal_vip.ip }} -# Use Ubuntu's ntp server as a fallback. -server ntp.ubuntu.com +# Use local server as a fallback. +server 127.127.1.0 # local clock +fudge 127.127.1.0 stratum 10 # Access control configuration; see /usr/share/doc/ntp-doc/html/accopt.html for # details. The web page <http://support.ntp.org/bin/view/Support/AccessRestrictions> @@ -34,8 +32,8 @@ server ntp.ubuntu.com # up blocking replies from your own upstream servers. # By default, exchange time with everybody, but don't allow configuration. -restrict -4 default kod notrap nomodify nopeer noquery -restrict -6 default kod notrap nomodify nopeer noquery +restrict -4 default kod notrap nomodify +restrict -6 default kod notrap nomodify # Local users may interrogate the ntp server more closely. restrict 127.0.0.1 diff --git a/deploy/adapters/ansible/roles/dashboard/tasks/main.yml b/deploy/adapters/ansible/roles/dashboard/tasks/main.yml index 2cad1174..9206fda4 100644 --- a/deploy/adapters/ansible/roles/dashboard/tasks/main.yml +++ b/deploy/adapters/ansible/roles/dashboard/tasks/main.yml @@ -5,6 +5,9 @@ action: "{{ ansible_pkg_mgr }} name={{ item }} state=present" with_items: packages | union(packages_noarch) +- name: set apache2 config + template: src=ports.j2 dest=/etc/apache2/ports.conf backup=yes + - name: remove ubuntu theme action: "{{ ansible_pkg_mgr }} name=openstack-dashboard-ubuntu-theme state=absent" diff --git a/deploy/adapters/ansible/roles/dashboard/templates/ports.j2 b/deploy/adapters/ansible/roles/dashboard/templates/ports.j2 new file mode 100644 index 00000000..0bfa0428 --- /dev/null +++ b/deploy/adapters/ansible/roles/dashboard/templates/ports.j2 @@ -0,0 +1,15 @@ +# if you just change the port or add more ports here, you will likely also +# have to change the VirtualHost statement in +# /etc/apache2/sites-enabled/000-default.conf + +Listen {{ internal_ip }}:80 + +<IfModule ssl_module> + Listen 443 +</IfModule> + +<IfModule mod_gnutls.c> + Listen 443 +</IfModule> + +# vim: syntax=apache ts=4 sw=4 sts=4 sr noet diff --git a/deploy/adapters/ansible/roles/ha/files/notify.sh b/deploy/adapters/ansible/roles/ha/files/notify.sh deleted file mode 100644 index 5edffe84..00000000 --- a/deploy/adapters/ansible/roles/ha/files/notify.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -python /usr/local/bin/failover.py $1 -mysql -uroot -e"flush hosts" -service mysql restart diff --git a/deploy/adapters/ansible/roles/ha/tasks/main.yml b/deploy/adapters/ansible/roles/ha/tasks/main.yml index edd5e6dd..668f6847 100644 --- a/deploy/adapters/ansible/roles/ha/tasks/main.yml +++ b/deploy/adapters/ansible/roles/ha/tasks/main.yml @@ -57,12 +57,6 @@ - name: copy galera_chk file copy: src=galera_chk dest=/usr/local/bin/galera_chk mode=0777 -- name: copy notify file - copy: src=notify.sh dest=/usr/local/bin/notify.sh mode=0777 - -- name: copy notify template file - template: src=failover.j2 dest=/usr/local/bin/failover.py mode=0777 - - name: add network service lineinfile: dest=/etc/services state=present line="mysqlchk 9200/tcp" diff --git a/deploy/adapters/ansible/roles/ha/templates/failover.j2 b/deploy/adapters/ansible/roles/ha/templates/failover.j2 deleted file mode 100644 index 3b08cf2d..00000000 --- a/deploy/adapters/ansible/roles/ha/templates/failover.j2 +++ /dev/null @@ -1,65 +0,0 @@ -import ConfigParser, os, socket -import logging as LOG -import pxssh -import sys -import re - -LOG_FILE="/var/log/mysql_failover" -try: - os.remove(LOG_FILE) -except: - pass - -LOG.basicConfig(format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p', filename=LOG_FILE,level=LOG.DEBUG) -ha_vip = {{ internal_vip.ip }} -LOG.info("ha_vip: %s" % ha_vip) - -#ha_vip = "10.1.0.50" -galera_path = '/etc/mysql/conf.d/wsrep.cnf' -pattern = re.compile(r"gcomm://(?P<prev_ip>.*)") - -def ssh_get_hostname(ip): - try: - s = pxssh.pxssh() - s.login("%s" % ip, "root", "root") - s.sendline('hostname') # run a command - s.prompt() # match the prompt - result = s.before.strip() # print everything before the prompt. - return result.split(os.linesep)[1] - except pxssh.ExceptionPxssh as e: - LOG.error("pxssh failed on login.") - raise - -def failover(mode): - config = ConfigParser.ConfigParser() - config.optionxform = str - config.readfp(open(galera_path)) - wsrep_cluster_address = config.get("mysqld", "wsrep_cluster_address") - wsrep_cluster_address = pattern.match(wsrep_cluster_address).groupdict()["prev_ip"] - - LOG.info("old wsrep_cluster_address = %s" % wsrep_cluster_address) - - if mode == "master": - # refresh wsrep_cluster_address to null - LOG.info("I'm being master, set wsrep_cluster_address to null") - wsrep_cluster_address = "" - - elif mode == "backup": - # refresh wsrep_cluster_address to master int ip - hostname = ssh_get_hostname(ha_vip) - wsrep_cluster_address = socket.gethostbyname(hostname) - LOG.info("I'm being slave, set wsrep_cluster_address to master internal ip") - - LOG.info("new wsrep_cluster_address = %s" % wsrep_cluster_address) - wsrep_cluster_address = "gcomm://%s" % wsrep_cluster_address - config.set("mysqld", "wsrep_cluster_address", wsrep_cluster_address) - with open(galera_path, 'wb') as fp: - #config.write(sys.stdout) - config.write(fp) - - os.system("service mysql restart") - LOG.info("failover success!!!") - -if __name__ == "__main__": - LOG.debug("call me: %s" % sys.argv) - failover(sys.argv[1]) diff --git a/deploy/adapters/ansible/roles/ha/templates/haproxy.cfg b/deploy/adapters/ansible/roles/ha/templates/haproxy.cfg index f1a2312c..8f026fa4 100644 --- a/deploy/adapters/ansible/roles/ha/templates/haproxy.cfg +++ b/deploy/adapters/ansible/roles/ha/templates/haproxy.cfg @@ -36,6 +36,7 @@ listen proxy-glance_registry_cluster listen proxy-glance_api_cluster bind {{ internal_vip.ip }}:9292 + bind {{ public_vip.ip }}:9292 option tcpka option httpchk option tcplog @@ -94,6 +95,7 @@ listen proxy-keystone_public_internal_cluster listen proxy-nova_compute_api_cluster bind {{ internal_vip.ip }}:8774 + bind {{ public_vip.ip }}:8774 mode tcp option httpchk option tcplog @@ -104,6 +106,7 @@ listen proxy-nova_compute_api_cluster listen proxy-nova_metadata_api_cluster bind {{ internal_vip.ip }}:8775 + bind {{ public_vip.ip }}:8775 option tcpka option tcplog balance source @@ -113,6 +116,7 @@ listen proxy-nova_metadata_api_cluster listen proxy-cinder_api_cluster bind {{ internal_vip.ip }}:8776 + bind {{ public_vip.ip }}:8776 mode tcp option httpchk option tcplog @@ -121,6 +125,16 @@ listen proxy-cinder_api_cluster server {{ host }} {{ ip }}:8776 weight 1 check inter 2000 rise 2 fall 5 {% endfor %} +listen proxy-dashboarad + bind {{ public_vip.ip }}:80 + option tcpka + option httpchk + option tcplog + balance source +{% for host,ip in haproxy_hosts.items() %} + server {{ host }} {{ ip }}:80 weight 1 check inter 2000 rise 2 fall 5 +{% endfor %} + listen stats mode http bind 0.0.0.0:8888 diff --git a/deploy/adapters/ansible/roles/ha/templates/keepalived.conf b/deploy/adapters/ansible/roles/ha/templates/keepalived.conf index f1e6db5d..a2e008a7 100644 --- a/deploy/adapters/ansible/roles/ha/templates/keepalived.conf +++ b/deploy/adapters/ansible/roles/ha/templates/keepalived.conf @@ -19,30 +19,24 @@ vrrp_instance internal_vip { virtual_ipaddress { {{ internal_vip.ip }}/{{ internal_vip.netmask }} dev {{ internal_vip.interface }} } +} - notify_master "/usr/local/bin/notify.sh master" - notify_backup "/usr/local/bin/notify.sh backup" +vrrp_instance public_vip { + interface {{ network_cfg.public_vip.interface }} + virtual_router_id {{ vrouter_id_public }} + state BACKUP + nopreempt + preempt_delay 30 + advert_int 1 + priority 100 -} + authentication { + auth_type PASS + auth_pass 4321 + } -#vrrp_instance public_vip { -# interface {{ network_cfg.public_vip.interface }} -# virtual_router_id {{ vrouter_id_public }} -# state BACKUP -# nopreempt -# preempt_delay 30 -# advert_int 1 -# priority 100 -# -# authentication { -# auth_type PASS -# auth_pass 4321 -# } -# -# virtual_ipaddress { -# {{ network_cfg.public_vip.ip }}/{{ network_cfg.public_vip.netmask }} dev {{ network_cfg.public_vip.interface }} -# } -# -#} -# -# notify_backup "/usr/local/bin/notify.sh backup" + virtual_ipaddress { + {{ network_cfg.public_vip.ip }}/{{ network_cfg.public_vip.netmask }} dev {{ network_cfg.public_vip.interface }} + } + +} diff --git a/deploy/adapters/ansible/roles/keystone/templates/keystone_init b/deploy/adapters/ansible/roles/keystone/templates/keystone_init index d9cc65a9..c7e22324 100644 --- a/deploy/adapters/ansible/roles/keystone/templates/keystone_init +++ b/deploy/adapters/ansible/roles/keystone/templates/keystone_init @@ -22,7 +22,7 @@ keystone --os-token={{ ADMIN_TOKEN }} --os-endpoint=http://{{ internal_vip.ip }} # regist keystone keystone --os-token={{ ADMIN_TOKEN }} --os-endpoint=http://{{ internal_vip.ip }}:35357/v2.0 service-create --name=keystone --type=identity --description="OpenStack Identity" -keystone --os-token={{ ADMIN_TOKEN }} --os-endpoint=http://{{ internal_vip.ip }}:35357/v2.0 endpoint-create --service_id=$(keystone --os-token={{ ADMIN_TOKEN }} --os-endpoint=http://{{ internal_vip.ip }}:35357/v2.0 service-list | awk '/ identity / {print $2}') --publicurl=http://{{ internal_vip.ip }}:5000/v2.0 --internalurl=http://{{ internal_vip.ip }}:5000/v2.0 --adminurl=http://{{ internal_vip.ip }}:35357/v2.0 +keystone --os-token={{ ADMIN_TOKEN }} --os-endpoint=http://{{ internal_vip.ip }}:35357/v2.0 endpoint-create --service_id=$(keystone --os-token={{ ADMIN_TOKEN }} --os-endpoint=http://{{ internal_vip.ip }}:35357/v2.0 service-list | awk '/ identity / {print $2}') --publicurl=http://{{ public_vip.ip }}:5000/v2.0 --internalurl=http://{{ internal_vip.ip }}:5000/v2.0 --adminurl=http://{{ internal_vip.ip }}:35357/v2.0 # Create a glance user that the Image Service can use to authenticate with the Identity service keystone --os-token={{ ADMIN_TOKEN }} --os-endpoint=http://{{ internal_vip.ip }}:35357/v2.0 user-create --name=glance --pass={{ GLANCE_PASS }} --email=glance@example.com @@ -30,7 +30,7 @@ keystone --os-token={{ ADMIN_TOKEN }} --os-endpoint=http://{{ internal_vip.ip }} #Register the Image Service with the Identity service so that other OpenStack services can locate it keystone --os-token={{ ADMIN_TOKEN }} --os-endpoint=http://{{ internal_vip.ip }}:35357/v2.0 service-create --name=glance --type=image --description="OpenStack Image Service" -keystone --os-token={{ ADMIN_TOKEN }} --os-endpoint=http://{{ internal_vip.ip }}:35357/v2.0 endpoint-create --service-id=$(keystone --os-token={{ ADMIN_TOKEN }} --os-endpoint=http://{{ internal_vip.ip }}:35357/v2.0 service-list | awk '/ image / {print $2}') --publicurl=http://{{ internal_vip.ip }}:9292 --internalurl=http://{{ internal_vip.ip }}:9292 --adminurl=http://{{ internal_vip.ip }}:9292 +keystone --os-token={{ ADMIN_TOKEN }} --os-endpoint=http://{{ internal_vip.ip }}:35357/v2.0 endpoint-create --service-id=$(keystone --os-token={{ ADMIN_TOKEN }} --os-endpoint=http://{{ internal_vip.ip }}:35357/v2.0 service-list | awk '/ image / {print $2}') --publicurl=http://{{ public_vip.ip }}:9292 --internalurl=http://{{ internal_vip.ip }}:9292 --adminurl=http://{{ internal_vip.ip }}:9292 #Create a nova user that Compute uses to authenticate with the Identity Service keystone --os-token={{ ADMIN_TOKEN }} --os-endpoint=http://{{ internal_vip.ip }}:35357/v2.0 user-create --name=nova --pass={{ NOVA_PASS }} --email=nova@example.com @@ -38,10 +38,10 @@ keystone --os-token={{ ADMIN_TOKEN }} --os-endpoint=http://{{ internal_vip.ip }} # register Compute with the Identity Service so that other OpenStack services can locate it keystone --os-token={{ ADMIN_TOKEN }} --os-endpoint=http://{{ internal_vip.ip }}:35357/v2.0 service-create --name=nova --type=compute --description="OpenStack Compute" -keystone --os-token={{ ADMIN_TOKEN }} --os-endpoint=http://{{ internal_vip.ip }}:35357/v2.0 endpoint-create --service-id=$(keystone --os-token={{ ADMIN_TOKEN }} --os-endpoint=http://{{ internal_vip.ip }}:35357/v2.0 service-list | awk '/ compute / {print $2}') --publicurl=http://{{ internal_vip.ip }}:8774/v2/%\(tenant_id\)s --internalurl=http://{{ internal_vip.ip }}:8774/v2/%\(tenant_id\)s --adminurl=http://{{ internal_vip.ip }}:8774/v2/%\(tenant_id\)s +keystone --os-token={{ ADMIN_TOKEN }} --os-endpoint=http://{{ internal_vip.ip }}:35357/v2.0 endpoint-create --service-id=$(keystone --os-token={{ ADMIN_TOKEN }} --os-endpoint=http://{{ internal_vip.ip }}:35357/v2.0 service-list | awk '/ compute / {print $2}') --publicurl=http://{{ public_vip.ip }}:8774/v2/%\(tenant_id\)s --internalurl=http://{{ internal_vip.ip }}:8774/v2/%\(tenant_id\)s --adminurl=http://{{ internal_vip.ip }}:8774/v2/%\(tenant_id\)s # register netron user, role and service keystone --os-token={{ ADMIN_TOKEN }} --os-endpoint=http://{{ internal_vip.ip }}:35357/v2.0 user-create --name neutron --pass {{ NEUTRON_PASS }} --email neutron@example.com keystone --os-token={{ ADMIN_TOKEN }} --os-endpoint=http://{{ internal_vip.ip }}:35357/v2.0 user-role-add --user neutron --tenant service --role admin keystone --os-token={{ ADMIN_TOKEN }} --os-endpoint=http://{{ internal_vip.ip }}:35357/v2.0 service-create --name neutron --type network --description "OpenStack Networking" -keystone --os-token={{ ADMIN_TOKEN }} --os-endpoint=http://{{ internal_vip.ip }}:35357/v2.0 endpoint-create --service-id $(keystone --os-token={{ ADMIN_TOKEN }} --os-endpoint=http://{{ internal_vip.ip }}:35357/v2.0 service-list | awk '/ network / {print $2}') --publicurl http://{{ internal_vip.ip }}:9696 --adminurl http://{{ internal_vip.ip }}:9696 --internalurl http://{{ internal_vip.ip }}:9696 +keystone --os-token={{ ADMIN_TOKEN }} --os-endpoint=http://{{ internal_vip.ip }}:35357/v2.0 endpoint-create --service-id $(keystone --os-token={{ ADMIN_TOKEN }} --os-endpoint=http://{{ internal_vip.ip }}:35357/v2.0 service-list | awk '/ network / {print $2}') --publicurl http://{{ public_vip.ip }}:9696 --adminurl http://{{ internal_vip.ip }}:9696 --internalurl http://{{ internal_vip.ip }}:9696 diff --git a/deploy/adapters/ansible/roles/neutron-controller/tasks/neutron_config.yml b/deploy/adapters/ansible/roles/neutron-controller/tasks/neutron_config.yml index 991e33cc..26758f58 100644 --- a/deploy/adapters/ansible/roles/neutron-controller/tasks/neutron_config.yml +++ b/deploy/adapters/ansible/roles/neutron-controller/tasks/neutron_config.yml @@ -9,10 +9,12 @@ notify: - restart neutron control services -- name: restart neutron-server - service: name=neutron-server state=restarted enabled=yes - delegate_to: "{{ item }}" - run_once: True - with_items: groups['controller'] +- name: restart first neutron-server + service: name=neutron-server state=restarted enabled=yes + when: inventory_hostname == groups['controller'][0] + +- name: restart other neutron-server + service: name=neutron-server state=restarted enabled=yes + when: inventory_hostname != groups['controller'][0] - meta: flush_handlers diff --git a/deploy/adapters/ansible/roles/setup-network/files/setup_networks/log.py b/deploy/adapters/ansible/roles/setup-network/files/setup_networks/log.py new file mode 100644 index 00000000..fffeb589 --- /dev/null +++ b/deploy/adapters/ansible/roles/setup-network/files/setup_networks/log.py @@ -0,0 +1,41 @@ +import logging +import os +loggers = {} +log_dir="/var/log/setup_network" +try: + os.makedirs(log_dir) +except: + pass + +def getLogger(name): + if name in loggers: + return loggers[name] + + logger = logging.getLogger(name) + logger.setLevel(logging.DEBUG) + + # create file handler which logs even debug messages + log_file = "%s/%s.log" % (log_dir, name) + try: + os.remove(log_file) + except: + pass + + fh = logging.FileHandler(log_file) + fh.setLevel(logging.DEBUG) + + # create console handler with a higher log level + ch = logging.StreamHandler() + ch.setLevel(logging.ERROR) + + # create formatter and add it to the handlers + formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s") + ch.setFormatter(formatter) + fh.setFormatter(formatter) + + # add the handlers to logger + logger.addHandler(ch) + logger.addHandler(fh) + + loggers[name] = logger + return logger diff --git a/deploy/adapters/ansible/roles/setup-network/files/setup_networks/net_init b/deploy/adapters/ansible/roles/setup-network/files/setup_networks/net_init new file mode 100755 index 00000000..c27a8bf8 --- /dev/null +++ b/deploy/adapters/ansible/roles/setup-network/files/setup_networks/net_init @@ -0,0 +1,20 @@ +#!/bin/bash +## BEGIN INIT INFO +# Provides: anamon.init +# Default-Start: 3 5 +# Default-Stop: 0 1 2 4 6 +# Required-Start: $network +# Short-Description: Starts the cobbler anamon boot notification program +# Description: anamon runs the first time a machine is booted after +# installation. +## END INIT INFO + +# +# anamon.init: Starts the cobbler post-install boot notification program +# +# chkconfig: 35 0 6 +# +# description: anamon runs the first time a machine is booted after +# installation. +# +python /opt/setup_networks/setup_networks.py diff --git a/deploy/adapters/ansible/roles/setup-network/files/setup_networks/setup_networks.py b/deploy/adapters/ansible/roles/setup-network/files/setup_networks/setup_networks.py new file mode 100644 index 00000000..b46abcee --- /dev/null +++ b/deploy/adapters/ansible/roles/setup-network/files/setup_networks/setup_networks.py @@ -0,0 +1,73 @@ +import yaml +import netaddr +import os +import log as logging + +LOG = logging.getLogger("net-init") +config_path = os.path.join(os.path.dirname(__file__), "network.cfg") +#from socket import AF_INET +#from pyroute2 import IPRoute +#from pyroute2 import IPRouteRequest + +#ip = IPRoute() +def setup_bondings(bond_mappings): + print bond_mappings + +def add_vlan_link(interface, ifname, vlan_id): + LOG.info("add_vlan_link enter") + #idx = ip.link_lookup(ifname=interface)[0] + #ip.link_create(ifname=ifname, + # kind="vlan", + # vlan_id=vlan_id, + # link=idx) + cmd = "ip link add link %s name %s type vlan id %s; " % (ifname, interface, vlan_id) + cmd += "ip link set %s up; ip link set %s up" % (interface, ifname) + LOG.info("add_vlan_link: cmd=%s" % cmd) + os.system(cmd) + +def add_ovs_port(ovs_br, ifname, vlan_id=None): + LOG.info("add_ovs_port enter") + cmd = "ovs-vsctl --may-exist add-port %s %s" % (ovs_br, ifname) + if vlan_id: + cmd += " tag=%s" % vlan_id + cmd += " -- set Interface %s type=internal" % ifname + LOG.info("add_ovs_port: cmd=%s" % cmd) + os.system(cmd) + +def setup_intfs(sys_intf_mappings): + LOG.info("setup_intfs enter") + for intf_name, intf_info in sys_intf_mappings.items(): + if intf_info["type"] == "vlan": + add_vlan_link(intf_name, intf_info["interface"], intf_info["vlan_tag"]) + elif intf_info["type"] == "ovs": + add_ovs_port(intf_info["interface"], intf_name, vlan_id=intf_info.get("vlan_tag")) + else: + pass + +def setup_ips(ip_settings): + LOG.info("setup_ips enter") + for intf_info in ip_settings.values(): + network = netaddr.IPNetwork(intf_info["cidr"]) + intf_name = intf_info["alias"] + cmd = "ip addr add %s/%s brd %s dev %s;" \ + % (intf_info["ip"], intf_info["netmask"], str(network.broadcast),intf_name) + if "gw" in intf_info: + cmd += "ip route add default via %s dev %s" % (intf_info["gw"], intf_name) + LOG.info("setup_ips: cmd=%s" % cmd) + os.system(cmd) + #idx = ip.link_lookup(ifname=intf_name)[0] + #ip.addr('add', + # index=idx, + # address=intf_info["ip"], + # broadcast=str(network.broadcast), + # prefixlen=intf_info["netmask"]) + +def main(config): + setup_bondings(config["bond_mappings"]) + setup_intfs(config["sys_intf_mappings"]) + setup_ips(config["ip_settings"]) + +if __name__ == "__main__": + os.system("service openvswitch-switch status|| service openvswitch-switch start") + config = yaml.load(open(config_path)) + main(config) diff --git a/deploy/adapters/ansible/roles/setup-network/tasks/main.yml b/deploy/adapters/ansible/roles/setup-network/tasks/main.yml index 8df1ac3a..8667a9b1 100644 --- a/deploy/adapters/ansible/roles/setup-network/tasks/main.yml +++ b/deploy/adapters/ansible/roles/setup-network/tasks/main.yml @@ -14,30 +14,31 @@ with_items: "{{ network_cfg['provider_net_mappings'] }}" when: 'item["type"] == "ovs"' -- name: setup sys intf - shell: ip link del {{ item.key }}; \ - ip link add link {{ item.value["interface"] }} name {{ item.key }} type vlan id {{ item.value["vlan_tag"] }}; \ - ip link set {{ item.value["interface"] }} up - when: '"vlan_tag" in item.value and item.value["type"] == "vlan"' - with_dict: "{{ sys_intf_mappings }}" - - -- name: set sys intf ip - shell: ip addr del {{ item.value["ip"] }}/{{ item.value["netmask"] }} dev {{ item.value["alias"] }}; \ - ip addr add {{ item.value["ip"] }}/{{ item.value["netmask"] }} dev {{ item.value["alias"] }}; \ - ip link set {{ item.value["alias"] }} up - with_dict: "{{ host_ip_settings }}" - -- name: set gateway - shell: ip route del default; \ - ip route add default via {{ item.value["gw"] }} dev {{ item.key }} - when: '"gw" in item.value' - with_dict: "{{ host_ip_settings }}" - -- name: copy net config - template: src=my_configs.debian dest=/etc/network/interfaces.d/my_configs.cfg - when: ansible_os_family == "Debian" - -- name: source net config - lineinfile: dest=/etc/network/interfaces line='source /etc/network/interfaces.d/my_configs.cfg' - when: ansible_os_family == "Debian" +- name: ensure script dir exist + shell: mkdir -p /opt/setup_networks + +- name: copy scripts + copy: src={{ item }} dest=/opt/setup_networks + with_items: + - setup_networks/log.py + - setup_networks/setup_networks.py + +- name: copy boot scripts + copy: src={{ item }} dest=/etc/init.d mode=0755 + with_items: + - setup_networks/net_init + +- name: copy config files + template: src=network.cfg dest=/opt/setup_networks + +- name: make sure python lib exist + action: "{{ ansible_pkg_mgr }} name={{ item }} state=present" + with_items: + - python-yaml + - python-netaddr + +- name: run scripts + shell: python /opt/setup_networks/setup_networks.py + +- name: add to boot scripts + service: name=net_init enabled=yes diff --git a/deploy/adapters/ansible/roles/setup-network/templates/network.cfg b/deploy/adapters/ansible/roles/setup-network/templates/network.cfg new file mode 100644 index 00000000..230d10a9 --- /dev/null +++ b/deploy/adapters/ansible/roles/setup-network/templates/network.cfg @@ -0,0 +1,4 @@ +bond_mappings: {{ network_cfg["bond_mappings"] }} +ip_settings: {{ ip_settings[inventory_hostname] }} +sys_intf_mappings: {{ sys_intf_mappings }} + |