def setup(self): data = self.init() if self.is_tag('package'): self.python.setup() self.python.setup_package(**self.package) if self.is_tag('conf'): # setup conf files filer.template( '/etc/rally/rally.conf', src='{0}/rally.conf.j2'.format(data['version']), data=data, ) filer.template( '/etc/rally/rally-existing.json', src='{0}/rally-existing.json.j2'.format(data['version']), data=data, ) if self.is_tag('data') and env.host == env.hosts[0]: sudo('rally deployment list | grep {0} || ' 'rally deployment create --file=/etc/rally/rally-existing.json --name={0}'.format( env.cluster['keystone']['service_region']))
def setup(self): data = self.init() if self.is_tag('package'): self.python.setup() self.python.setup_package(**self.package) if self.is_tag('conf'): # setup conf files if filer.template( '/etc/trove/trove.conf', src='{0}/trove.conf.j2'.format(data['version']), data=data): self.handlers['restart_trove-*'] = True if filer.template( '/etc/trove/trove-taskmanager.conf', src='{0}/trove-taskmanager.conf.j2'.format(data['version']), data=data): self.handlers['restart_trove-*'] = True if filer.template( '/etc/trove/trove-guestagent.conf', src='{0}/trove-guestagent.conf.j2'.format(data['version']), data=data): self.handlers['restart_trove-*'] = True if self.is_tag('data') and env.host == env.hosts[0]: sudo('{0}/bin/trove-manage db_sync'.format(self.prefix)) self.register_image() if self.is_tag('conf', 'service'): self.enable_services().start_services(pty=False) self.exec_handlers()
def setup(self): data = self.init() if self.is_tag('package'): self.python.setup() self.python.setup_package(**self.package) if self.is_tag('conf'): is_updated = filer.template( '/etc/ceilometer/ceilometer.conf', src='{0}/ceilometer.conf.j2'.format(data['version']), data=data, ) is_updated = filer.template( '/etc/ceilometer/pipeline.yaml', src='{0}/pipeline.yaml'.format(data['version']), data=data, ) or is_updated if self.is_tag('data') and env.host == env.hosts[0]: sudo('{0}/bin/ceilometer-dbsync'.format(self.prefix)) if self.is_tag('conf', 'service'): self.enable_services().start_services(pty=False) if is_updated: self.restart_services(pty=False)
def setup(self): data = self.init() self.install_packages() self.start_services() is_updated = filer.template(src='docker.j2', dest='/etc/default/docker') if is_updated: self.restart_services() for docker in data['dockers']: data = { 'user': CONF.test.user, 'password': CONF.test.password, 'docker': docker, } filer.template(src=docker['template'], dest=os.path.join('/tmp', docker['template']), data=data) sudo('docker images | grep {0} ||' ' docker build -f /tmp/{1} -t {0} /tmp/'.format( docker['name'], docker['template'])) port_option = '' for port in docker['ports']: port_option += ' -p {0[1]}:{0[0]}'.format(port) if docker.get('use_systemd', False): sudo('docker ps | grep {0} || (' ' docker run --privileged -di --name {0} {1} {0} /sbin/init &&' ' docker exec -di {0} /usr/sbin/sshd -D )'.format(docker['name'], port_option)) else: sudo('docker ps | grep {0} || (' ' docker run --privileged -di --name {0} {1} {0} /usr/sbin/sshd -D )'.format( docker['name'], port_option))
def setup(): filer.mkdir('/tmp/fabkit') filer.file(src='file_sample.txt', dest='/tmp/fabkit/file_sample.txt', override=True) filer.template(src='template_sample.txt', dest='/tmp/fabkit/template_sample.txt', data={'msg': 'test'}) run('diff /tmp/fabkit/file_sample.txt /tmp/fabkit/template_sample.txt')
def create_domain_xml(self, vm, instance_dir): vm['uuid'] = str(uuid.uuid1()) domain_xml = '{0}/domain.xml'.format(instance_dir) src_domain_xml = os.path.join(self.template_dir, 'domain.xml') filer.template(domain_xml, src_file=src_domain_xml, data=vm) return domain_xml
def setup(self): data = self.init() if self.is_tag('package'): self.python.setup() self.python.setup_package(**self.package) filer.mkdir(data['glance_store']['filesystem_store_datadir']) if self.is_tag('conf'): # setup conf files if filer.template( '/etc/glance/glance-api.conf', src='{0}/glance-api.conf.j2'.format(data['version']), data=data): self.handlers['restart_glance-api'] = True if filer.template( '/etc/glance/glance-registry.conf', src='{0}/glance-registry.conf.j2'.format(data['version']), data=data): self.handlers['restart_glance-registry'] = True if self.is_tag('data') and env.host == env.hosts[0]: sudo('{0}/bin/glance-manage db_sync'.format(self.prefix)) if self.is_tag('conf', 'service'): self.enable_services().start_services(pty=False) self.exec_handlers()
def setup(self): data = self.init() if self.is_tag('package'): self.install_packages() self.python.setup() self.python.setup_package(**self.package) sudo('sh -c "cd {0}/lib/horizon/ && {1} manage.py collectstatic --noinput"'.format( self.prefix, self.python.get_cmd())) sudo('sh -c "cd {0}/lib/horizon/ && {1} manage.py compress --force"'.format( self.prefix, self.python.get_cmd())) sudo('chown -R apache:apache {0}/lib/horizon'.format(self.prefix)) if self.is_tag('conf'): is_updated = filer.template( self.prefix + '/lib/horizon/openstack_dashboard/local/local_settings.py', src='{0}/local_settings.py.j2'.format(data['version']), data=data, ) is_updated = filer.template( '/etc/httpd/conf.d/horizon_httpd.conf', src='{0}/horizon_httpd.conf.j2'.format(data['version']), data=data, ) or is_updated if self.is_tag('service'): self.enable_services().start_services(pty=False) if is_updated: self.restart_services(pty=False)
def setup_prepare(self): if self.is_tag('package'): if env.node['package_manager'] == 'yum': filer.template('/etc/yum.repos.d/mariadb.repo') self.init_package_manager() self.install_packages() sudo('setenforce 0')
def setup(self): data = self.init() if self.is_tag('package'): self.install_packages() if self.is_tag('conf'): if filer.template('/var/lib/rabbitmq/.erlang.cookie', src_str=data['cookie'], mode='400', owner='rabbitmq:rabbitmq'): sudo('rm -rf /var/lib/rabbitmq/mnesia') self.handlers['restart_rabbitmq-server'] = True etc_hosts = Editor('/etc/hosts') for i, host in enumerate(data['hosts']): ip = socket.gethostbyname(host) etc_hosts.a('{0} rabbit{1}'.format(ip, i)) node_index = data['hosts'].index(env.host) nodename = 'rabbit@rabbit{0}'.format(node_index) if filer.template('/etc/rabbitmq/rabbitmq-env.conf', src_str='NODENAME={0}'.format(nodename), mode='644', owner='rabbitmq:rabbitmq'): self.handlers['restart_rabbitmq-server'] = True if self.is_tag('service'): self.enable_services().start_services() self.exec_handlers() if self.is_tag('data'): sudo('rabbitmq-plugins enable rabbitmq_management') if nodename == 'rabbit@rabbit0': result = sudo('rabbitmqctl list_vhosts | grep -v Listing') vhosts = result.split('\r\n') for vhost in data['vhost_map'].values(): if vhost not in vhosts: sudo('rabbitmqctl add_vhost {0}'.format(vhost)) result = sudo( 'rabbitmqctl list_users | grep -v Listing | awk \'{print $1}\'' ) users = result.split('\r\n') if 'guest' in users: sudo('rabbitmqctl delete_user guest') for user in data['user_map'].values(): if user['user'] not in users: sudo('rabbitmqctl add_user {0[user]} {0[password]}'. format(user)) for permission in user['permissions']: sudo( 'rabbitmqctl set_permissions -p {1[vhost]} {0[user]} {1[permissions]}' .format(user, permission)) # noqa
def setup(): print '{0}: hello'.format(env.host) print env.cluster run('hostname') sudo('hostname') Package('memcached').install() Service('memcached').start() # run('touch /tmp/test') filer.file('/etc/memcached.conf') filer.template('/etc/memcached.conf')
def disable_admin_token(self): data = self.init() data.update({ 'tmp_admin_token': '# admin_token =' }) filer.template( '/etc/keystone/keystone.conf', src='{0}/keystone.conf.j2'.format(data['version']), data=data, ) self.restart_services(pty=False)
def setup(self): data = self.init() if self.is_tag('package'): self.install_packages() self.python.setup() self.python.setup_package(**self.package) if self.is_tag('conf'): # setup conf files if filer.template( '/etc/swift/swift.conf', src='{0}/swift/swift.conf.j2'.format(data['version']), data=data): self.handlers['restart_swift-proxy-server'] = True if filer.template( '/etc/swift/proxy-server.conf', src='{0}/swift/proxy-server.conf.j2'.format(data['version']), data=data): self.handlers['restart_swift-proxy-server'] = True if filer.template( '/etc/swift/account-server.conf', src='{0}/swift/account-server.conf.j2'.format(data['version']), data=data): self.handlers['restart_swift-account-server'] = True if filer.template( '/etc/swift/container-server.conf', src='{0}/swift/container-server.conf.j2'.format(data['version']), data=data): self.handlers['restart_swift-container-server'] = True if filer.template( '/etc/swift/object-server.conf', src='{0}/swift/object-server.conf.j2'.format(data['version']), data=data): self.handlers['restart_swift-object-server'] = True if self.is_tag('data'): filer.mkdir('/mnt/swift/main') for ring in ['account', 'object', 'container']: port = data['{0}_port'.format(ring)] sudo('cd /etc/swift &&' '[ -e {0}.builder ] || swift-ring-builder {0}.builder create 9 1 1 && ' '[ -e {0}.ring.gz ] || swift-ring-builder {0}.builder add z1-127.0.0.1:{1}/main 100 &&' # noqa '[ -e {0}.ring.gz ] || swift-ring-builder {0}.builder rebalance'.format(ring, port)) # noqa if self.is_tag('conf', 'service'): self.enable_services().start_services(pty=False) self.exec_handlers()
def setup(self): data = self.init() if self.is_tag('package'): self.install_packages() if self.is_tag('conf'): if filer.template('/var/lib/rabbitmq/.erlang.cookie', src_str=data['cookie'], mode='400', owner='rabbitmq:rabbitmq'): sudo('rm -rf /var/lib/rabbitmq/mnesia') self.handlers['restart_rabbitmq-server'] = True etc_hosts = Editor('/etc/hosts') for i, host in enumerate(data['hosts']): ip = socket.gethostbyname(host) etc_hosts.a('{0} rabbit{1}'.format(ip, i)) node_index = data['hosts'].index(env.host) nodename = 'rabbit@rabbit{0}'.format(node_index) if filer.template('/etc/rabbitmq/rabbitmq-env.conf', src_str='NODENAME={0}'.format(nodename), mode='644', owner='rabbitmq:rabbitmq'): self.handlers['restart_rabbitmq-server'] = True if self.is_tag('service'): self.enable_services().start_services() self.exec_handlers() if self.is_tag('data'): sudo('rabbitmq-plugins enable rabbitmq_management') if nodename == 'rabbit@rabbit0': result = sudo('rabbitmqctl list_vhosts | grep -v Listing') vhosts = result.split('\r\n') for vhost in data['vhost_map'].values(): if vhost not in vhosts: sudo('rabbitmqctl add_vhost {0}'.format(vhost)) result = sudo('rabbitmqctl list_users | grep -v Listing | awk \'{print $1}\'') users = result.split('\r\n') if 'guest' in users: sudo('rabbitmqctl delete_user guest') for user in data['user_map'].values(): if user['user'] not in users: sudo('rabbitmqctl add_user {0[user]} {0[password]}'.format(user)) for permission in user['permissions']: sudo('rabbitmqctl set_permissions -p {1[vhost]} {0[user]} {1[permissions]}'.format(user, permission)) # noqa
def setup(self): data = self.init() self.install_packages() var_dir = CONF.client.package_var_dir common_repo = '{0}/fabkit-repo-common'.format(var_dir) server_repo = '{0}/fabkit-repo-server'.format(var_dir) filer.template('{0}/fabfile.ini'.format(server_repo), data=data) sudo('rm -rf {0}/fabfile && ' 'cp -r {1}/fabfile {0}/fabfile && ' 'chown -R {2}:{3} {0}/fabfile'.format(server_repo, common_repo, data['user'], data['group'])) if re.match('CentOS .*', env.node['os']): log_prefix = '/var/log/httpd/{0}'.format(env.user) data.update({ 'repo': server_repo, 'python_path': self.python.get_site_packages(), 'error_log': 'fabkit-error.log'.format(log_prefix), 'custom_log': 'fabkit-access.log'.format(log_prefix), }) if filer.template( src='httpd.conf', dest='/etc/httpd/conf.d/fabkit_httpd.conf'.format( env.user), data=data): self.handlers['restart_httpd'] = True self.exec_handlers() if env.host == env.hosts[0]: sudo("cd {0}/fabfile/core/webapp && " "{1}/bin/python manage.py migrate --noinput".format( server_repo, CONF.client.package_prefix)) sudo( "cd {0}/fabfile/core/webapp && " "echo \"from django.contrib.auth.models import User;" "User.objects.create_superuser('admin', '*****@*****.**', 'admin')\"" " | {1}/bin/python manage.py shell".format( server_repo, CONF.client.package_prefix)) self.start_services().enable_services() self.restart_services() sudo('/opt/fabkit/bin/fabserver -l')
def setup_pacemaker(self): data = self.init() if env.host == data['hosts'][0]: # stonith を無効化しておかないとresouceが作成できない sudo("pcs cluster start --all") sudo('pcs property set stonith-enabled=false') sudo('pcs resource show vip || ' 'pcs resource create vip ocf:heartbeat:IPaddr2 ' 'ip="{0[vip]}" cidr_netmask="{0[cidr_netmask]}" ' 'op monitor interval="{0[monitor_interval]}s"'.format(data)) sudo('pcs resource show lb-haproxy || ' 'pcs resource create lb-haproxy systemd:haproxy --clone') sudo('pcs constraint order | grep "start vip then start lb-haproxy-clone" || ' 'pcs constraint order start vip then lb-haproxy-clone') sudo('pcs constraint colocation | grep "vip with lb-haproxy-clone" || ' 'pcs constraint colocation add vip with lb-haproxy-clone') is_change = filer.template('/etc/haproxy/haproxy.cfg', data=data) if env.host == data['hosts'][0] and is_change: Service('haproxy').reload() self.enable_services()
def setup_pcs(self): data = self.init() if env.host == data['hosts'][0]: if not filer.exists('/etc/corosync/authkey'): sudo('corosync-keygen -l') sudo('cp /etc/corosync/authkey /tmp/authkey') sudo('chmod 666 /tmp/authkey') api.get('/tmp/authkey', '/tmp/authkey') sudo('rm /tmp/authkey') else: if not filer.exists('/etc/corosync/authkey'): api.put('/tmp/authkey', '/tmp/authkey') sudo('mv /tmp/authkey /etc/corosync/authkey') sudo('chown root:root /etc/corosync/authkey') sudo('chmod 400 /etc/corosync/authkey') data['bindnetaddr'] = env['node']['ip']['default_dev']['subnet'].split( '/')[0] nodes = [] for i, host in enumerate(env.hosts): ip = socket.gethostbyname(host) nodes.append({'id': i, 'ip': ip}) data['nodes'] = nodes if filer.template('/etc/corosync/corosync.conf', data=data): sudo('systemctl restart pacemaker') sudo('systemctl restart corosync') with api.warn_only(): result = sudo("pcs cluster status") if result.return_code != 0: sudo("pcs cluster start")
def setup(self): data = self.init() if self.is_tag('package'): self.python.setup() self.python.setup_package(**self.package) if self.is_tag('conf'): # setup conf files is_updated = filer.template( '/etc/heat/heat.conf', src='{0}/heat.conf.j2'.format(data['version']), data=data, ) if self.is_tag('data') and env.host == env.hosts[0]: utils.oscmd('/opt/heat/bin/heat-keystone-setup-domain \ --stack-user-domain-name {0} \ --stack-domain-admin {1} \ --stack-domain-admin-password {2}'.format( self.data['stack_user_domain_name'], self.data['stack_domain_admin'], self.data['stack_domain_admin_password'])) sudo('{0}/bin/heat-manage db_sync'.format(self.prefix)) if self.is_tag('conf', 'service'): self.enable_services().start_services(pty=False) if is_updated: self.restart_services(pty=False)
def setup_pacemaker(self): data = self.init() if env.host == data['hosts'][0]: # stonith を無効化しておかないとresouceがスタートしない sudo('pcs property set stonith-enabled=false') sudo('pcs resource show vip || ' 'pcs resource create vip ocf:heartbeat:IPaddr2 ' 'ip="{0[vip]}" cidr_netmask="{0[cidr_netmask]}" ' 'op monitor interval="{0[monitor_interval]}s"'.format(data)) sudo( 'pcs resource show lb-haproxy || ' 'pcs resource create lb-haproxy systemd:haproxy --clone --force' ) sudo( 'pcs constraint order | grep "start vip then start lb-haproxy-clone" || ' 'pcs constraint order start vip then lb-haproxy-clone') sudo( 'pcs constraint colocation | grep "vip with lb-haproxy-clone" || ' 'pcs constraint colocation add vip with lb-haproxy-clone') is_change = filer.template('/etc/haproxy/haproxy.cfg', data=data) if env.host == data['hosts'][0] and is_change: Service('haproxy').reload() self.enable_services()
def setup(self): data = self.init() if self.is_tag('package'): self.install_packages() self.python.setup() self.python.setup_package(**self.package) # for cinder if not filer.exists('/usr/bin/scsi_id'): sudo('ln -s /lib/udev/scsi_id /usr/bin/') if self.is_tag('conf'): # sudoersファイルは最後に改行入れないと、シンタックスエラーとなりsudo実行できなくなる # sudo: >>> /etc/sudoers.d/nova: syntax error near line 2 <<< # この場合は以下のコマンドでvisudoを実行し、編集する # $ pkexec visudo -f /etc/sudoers.d/nova if filer.template( '/etc/sudoers.d/nova', data=data, src='sudoers.j2', ): self.handlers['restart_nova'] = True if filer.template( '/etc/nova/nova.conf', src='{0}/nova.conf.j2'.format(data['version']), data=data, ): self.handlers['restart_nova'] = True if self.is_tag('data') and env.host == env.hosts[0]: if data['is_master']: sudo('nova-manage db sync') if data['version'] in ['mitaka']: sudo('nova-manage api_db sync') if self.is_tag('service'): self.enable_services().start_services(pty=False) self.exec_handlers() if self.is_tag('data') and env.host == env.hosts[0]: if data['is_master']: self.sync_flavors() return 0
def setup(self): data = self.init() self.install_packages() var_dir = CONF.client.package_var_dir common_repo = '{0}/fabkit-repo-common'.format(var_dir) server_repo = '{0}/fabkit-repo-server'.format(var_dir) filer.template('{0}/fabfile.ini'.format(server_repo), data=data) sudo('rm -rf {0}/fabfile && ' 'cp -r {1}/fabfile {0}/fabfile && ' 'chown -R {2}:{3} {0}/fabfile'.format( server_repo, common_repo, data['user'], data['group'])) if re.match('CentOS .*', env.node['os']): log_prefix = '/var/log/httpd/{0}'.format(env.user) data.update({ 'repo': server_repo, 'python_path': self.python.get_site_packages(), 'error_log': 'fabkit-error.log'.format(log_prefix), 'custom_log': 'fabkit-access.log'.format(log_prefix), }) if filer.template(src='httpd.conf', dest='/etc/httpd/conf.d/fabkit_httpd.conf'.format(env.user), data=data): self.handlers['restart_httpd'] = True self.exec_handlers() if env.host == env.hosts[0]: sudo("cd {0}/fabfile/core/webapp && " "{1}/bin/python manage.py migrate --noinput".format( server_repo, CONF.client.package_prefix)) sudo("cd {0}/fabfile/core/webapp && " "echo \"from django.contrib.auth.models import User;" "User.objects.create_superuser('admin', '*****@*****.**', 'admin')\"" " | {1}/bin/python manage.py shell".format( server_repo, CONF.client.package_prefix)) self.start_services().enable_services() self.restart_services() sudo('/opt/fabkit/bin/fabserver -l')
def setup_package(self, name, git_repos=[], exec_user='******', branch=None, is_develop=False, mk_links=[], mk_dirs=[], cp_files=[], services=[], requirements=[], **kwargs): user.add(exec_user) for git_repo in git_repos: git_dir = os.path.join(self.prefix, 'src', git_repo['name']) git_dir_parent = os.path.dirname(git_dir) filer.mkdir(git_dir_parent, mode='777') git.sync(git_repo['url'], branch=git_repo['branch'], dest=git_dir) requirements_txt = '{0}/requirements.txt'.format(git_dir) if filer.exists(requirements_txt): self.install(requirements=requirements_txt) if is_develop: sudo('sh -c "cd {0} && {1}/bin/python setup.py develop"'.format( git_dir, self.prefix)) else: sudo('sh -c "cd {0} && {1}/bin/python setup.py install"'.format( git_dir, self.prefix)) for mkdir in mk_dirs: filer.mkdir(mkdir['path'], owner=mkdir.get('owner', exec_user)) for cpfile in cp_files: if filer.exists(cpfile['dest']): continue sudo('cp -r {0} {1}'.format( os.path.join(git_dir, cpfile['src']), cpfile['dest'])) for service in services: service['user'] = exec_user filer.template( '/etc/systemd/system/{0}.service'.format(service['name']), src='systemd.service.j2', mode='755', data=service) for requirement in requirements: self.install(requirement) for link in mk_links: if not filer.exists(link['dest']): sudo('ln -s {0} {1}'.format(link['src'], link['dest']))
def setup(self): data = self.init() if self.is_tag('package'): self.init_package_manager() self.install_packages() if self.is_tag('conf'): if env.node['package_manager'] == 'apt': if filer.template('/etc/memcached.conf', data=data): self.handlers['restart_memcached'] = True else: if filer.template('/etc/sysconfig/memcached', data=data): self.handlers['restart_memcached'] = True if self.is_tag('service'): self.enable_services().start_services() self.exec_handlers()
def setup(self): data = self.init() if self.is_tag('conf'): if env.node['package_manager'] == 'yum': if filer.template('/etc/my.cnf.d/server.cnf', data=data): self.handlers['restart_mariadb'] = True elif env.node['package_manager'] == 'apt': pass if self.is_tag('service'): if self.data['hosts'][0] == env.host: with api.warn_only(): result = sudo('systemctl status mariadb') if result.return_code != 0: sudo('galera_new_cluster') else: self.exec_handlers() self.enable_services().start_services() else: self.enable_services().start_services() self.exec_handlers() if self.is_tag('data'): # init root_password if not filer.exists('/root/.my.cnf'): root_password = data['root_password'] if data['hosts'][0] == env.host: if self.is_ubuntu(): sudo('mysqladmin password {0} -uroot -ptmppass'.format( root_password)) else: sudo('mysqladmin password {0} -uroot'.format( root_password)) filer.template('/root/.my.cnf', data={'root_password': root_password}) if data['hosts'][0] == env.host: self.create_users() self.delete_default_users() self.create_databases()
def setup(self): data = self.init() var_dir = CONF.client.package_var_dir common_repo = '{0}/fabkit-repo-common'.format(var_dir) client_repo = '{0}/fabkit-repo-client'.format(var_dir) filer.template('{0}/fabfile.ini'.format(client_repo), data=data) sudo('rm -rf {0}/fabfile && ' 'cp -r {1}/fabfile {0}/fabfile && ' 'chown -R {2}:{3} {0}/fabfile'.format( client_repo, common_repo, data['user'], data['group'])) if env.host == env.hosts[0]: sudo('/opt/fabkit/bin/fabclient sync_db') self.start_services().enable_services() self.restart_services() sudo('/opt/fabkit/bin/fabclient -l')
def install_graphite_web(self): data = self.data Package('pycairo').install() Package('cairo-devel').install() Package('bitmap-fonts-compat').install() Package('httpd').install() Package('mod_wsgi').install() Package('MySQL-python').install() python.setup() sudo('pip install django==1.6.8') python.install_from_git('graphite-web', 'https://github.com/graphite-project/graphite-web.git') log_dir = '/opt/graphite/storage/log/webapp/' owner = '{0[user]}:{0[group]}'.format(data) filer.mkdir(log_dir, owner=owner) log_files = ['access.log', 'error.log', 'exception.log', 'info.log'] for log_file in log_files: log_file = os.path.join(log_dir, log_file) filer.touch(log_file, owner=owner) manage_py = os.path.join(conf.REMOTE_TMP_DIR, 'git/graphite-web.git/webapp/manage.py') sudo('cp {0} /opt/graphite/webapp/'.format(manage_py)) is_updated = filer.template('/opt/graphite/webapp/graphite/local_settings.py', data=data) is_updated = filer.template('/opt/graphite/webapp/graphite/settings.py', data=data) or is_updated is_updated = filer.template('/opt/graphite/conf/graphite.wsgi') or is_updated is_updated = filer.template('/etc/httpd/conf.d/graphite-vhost.conf', data={ 'user': data['user'], 'group': data['group'], }) or is_updated return is_updated
def setup(self): data = self.init() self.install_packages() self.start_services() is_updated = filer.template(src='docker.j2', dest='/etc/default/docker') if is_updated: self.restart_services() for docker in data['dockers']: data = { 'user': CONF.test.user, 'password': CONF.test.password, 'docker': docker, } filer.template(src=docker['template'], dest=os.path.join('/tmp', docker['template']), data=data) sudo('docker images | grep {0} ||' ' docker build -f /tmp/{1} -t {0} /tmp/'.format( docker['name'], docker['template'])) port_option = '' for port in docker['ports']: port_option += ' -p {0[1]}:{0[0]}'.format(port) if docker.get('use_systemd', False): sudo( 'docker ps | grep {0} || (' ' docker run --privileged -di --name {0} {1} {0} /sbin/init &&' ' docker exec -di {0} /usr/sbin/sshd -D )'.format( docker['name'], port_option)) else: sudo( 'docker ps | grep {0} || (' ' docker run --privileged -di --name {0} {1} {0} /usr/sbin/sshd -D )' .format(docker['name'], port_option))
def setup(self): data = self.init() run('hostname') self.install_packages() filer.template('/tmp/pdns.sql') sudo('mysql -uroot pdns -e "show tables;" | grep domain || ' 'mysql -uroot pdns < /tmp/pdns.sql') if env.host in data['master']['hosts']: data['is_master'] = True if env.host in data['slave']['hosts']: data['is_slave'] = True filer.template('/etc/pdns/pdns.conf', data=data) self.start_services().enable_services() if not filer.exists('/var/www/html/poweradmin'): sudo('cd /tmp/ && ' 'wget http://downloads.sourceforge.net/project/poweradmin/poweradmin-2.1.7.tgz && ' 'tar xf poweradmin-2.1.7.tgz && ' 'mv poweradmin-2.1.7 /var/www/html/poweradmin && ' 'chown -R apache:apache /var/www/html/poweradmin')
def create_configiso(self, vm, instance_dir): data = self.data template_data = { 'user': CONF.job_user, 'password': CONF.job_password, 'vm': vm, 'gateway': data['libvirt']['gateway'], 'netmask': data['libvirt']['netmask'], } metadata_path = '{0}/meta-data'.format(instance_dir) userdata_path = '{0}/user-data'.format(instance_dir) configiso_path = '{0}/config.iso'.format(instance_dir) src_metadata_path = os.path.join(self.template_dir, 'meta-data') src_userdata_path = os.path.join(self.template_dir, vm['template']) filer.template(metadata_path, src_file=src_metadata_path, data=template_data) filer.template(userdata_path, src_file=src_userdata_path, data=template_data) if not filer.exists(configiso_path): sudo('genisoimage -o {0} -V cidata -r -J {1} {2}'.format( configiso_path, metadata_path, userdata_path)) return configiso_path
def setup(self): data = self.init() if self.is_tag('package'): self.python.setup() self.python.setup_package(**self.package) if self.is_tag('conf'): if filer.template( '/etc/aodh/aodh.conf', src='{0}/aodh.conf.j2'.format(data['version']), data=data, ): self.handlers['restart_aodh-*'] = True if self.is_tag('data') and env.host == env.hosts[0]: sudo('{0}/bin/aodh-dbsync'.format(self.prefix)) if self.is_tag('conf', 'service'): self.enable_services().start_services(pty=False) self.exec_handlers()
def setup(self): data = self.init() if self.is_tag('package'): self.python.setup() self.python.setup_package(**self.package) if self.is_tag('conf'): # setup conf files if filer.template( '/etc/designate/designate.conf', src='{0}/designate.conf.j2'.format(data['version']), data=data): self.handlers['restart_ironic-*'] = True if self.is_tag('data') and env.host == env.hosts[0]: sudo('{0}/bin/designate-manage database sync'.format(self.prefix)) if self.is_tag('conf', 'service'): self.enable_services().start_services(pty=False) self.exec_handlers()
def setup(self): data = self.init() if self.is_tag('package'): self.python.setup() self.python.setup_package(**self.package) if self.is_tag('conf'): # setup conf files if filer.template( '/etc/ironic/ironic.conf', src='{0}/ironic.conf.j2'.format(data['version']), data=data): self.handlers['restart_ironic-*'] = True if self.is_tag('data') and env.host == env.hosts[0]: sudo('{0}/bin/ironic-dbsync --config-file /etc/ironic/ironic.conf ' 'upgrade --revision head'.format(self.prefix)) if self.is_tag('conf', 'service'): self.enable_services().start_services(pty=False) self.exec_handlers()
def setup(self): self.install_packages() self.start_services().enable_services() repo = '/home/{0}/fabkit-repo'.format(env.user) filer.mkdir(repo, use_sudo=False) git.setup() git.sync('https://github.com/fabrickit/fabkit.git', dest='{0}/fabfile'.format(repo)) python = Python('/opt/fabkit') python.setup() python.install( requirements='{0}/fabfile/requirements.txt'.format(repo)) run('cd {0} && /opt/fabkit/bin/fab genconfig:fabfile.ini &&' ' sed -i "/^\[web\]/,/^\[/s/#hostname =.*/hostname = */g" fabfile.ini'.format(repo)) data = { 'port': 80, 'repo': repo, 'user': env.user, 'group': env.user, 'python_path': python.get_site_packages(), 'processes': 5, 'threads': 1, } run('cd {0}/fabfile/core/webapp/ &&' ' /opt/fabkit/bin/python manage.py migrate &&' ' echo "from django.contrib.auth.models import User;' ' User.objects.create_superuser(\'admin\', \'admin@localhost\', \'admin\')"' ' | /opt/fabkit/bin/python manage.py shell &&' ' /opt/fabkit/bin/python manage.py collectstatic --noinput'.format(repo)) sudo('chmod 755 /home/{0}'.format(env.user)) if re.match('CentOS .*', env.node['os']): log_prefix = '/var/log/httpd/{0}'.format(env.user) data['error_log'] = '{0}-error.log'.format(log_prefix) data['custom_log'] = '{0}-access.log'.format(log_prefix) if filer.template(src='httpd.conf', dest='/etc/httpd/conf.d/{0}_httpd.conf'.format(env.user), data=data): self.handlers['restart_httpd'] = True elif re.match('Ubuntu .*', env.node['os']): log_prefix = '/var/log/apache2/{0}'.format(env.user) data['error_log'] = '{0}-error.log'.format(log_prefix) data['custom_log'] = '{0}-access.log'.format(log_prefix) if filer.template(src='httpd.conf', dest='/etc/apache2/sites-enabled/{0}_httpd.conf'.format(env.user), data=data): self.handlers['restart_apache2'] = True self.exec_handlers() # install sudo('npm install -g coffee-script'.format(repo)) sudo('cd {0}/fabfile/core/webapp && npm install'.format(repo)) # install node packages for develop sudo('npm install -g grunt-cli'.format(repo)) sudo('cd {0}/fabfile/core/webapp/node_chat && npm install'.format(repo))
def setup(self): data = self.init() version = data['version'] if self.is_tag('package'): self.python.setup() self.python.setup_package(**self.package) self.install_packages() if self.is_tag('conf'): if filer.template( '/etc/keystone/keystone.conf', src='{0}/keystone.conf.j2'.format(version), data=data, ): self.handlers['restart_httpd'] = True data.update({ 'httpd_port': data['public_port'], 'prefix': self.prefix, 'wsgi_name': 'keystone-public', 'wsgi_script_alias': '{0}/bin/keystone-wsgi-public'.format(self.prefix), 'wsgi_script_dir': '{0}/bin/'.format(self.prefix), 'log_name': 'keystone' }) if filer.template( '/etc/httpd/conf.d/wsgi-keystone-public.conf', src='wsgi-httpd.conf', data=data, ): self.handlers['restart_httpd'] = True data.update({ 'httpd_port': data['admin_port'], 'wsgi_name': 'keystone-admin', 'wsgi_script_alias': '{0}/bin/keystone-wsgi-admin'.format(self.prefix), }) if filer.template( '/etc/httpd/conf.d/wsgi-keystone-admin.conf', src='wsgi-httpd.conf', data=data, ): self.handlers['restart_httpd'] = True if self.is_tag('data'): if env.host == env.hosts[0]: sudo('{0}/bin/keystone-manage db_sync'.format(self.prefix)) if self.is_tag('service'): self.enable_services().start_services(pty=False) self.exec_handlers() if self.is_tag('data') and env.host == env.hosts[0]: time.sleep(3) self.create_tenant('admin', 'Admin Project') self.create_role('admin') self.create_role('_member_') self.create_user(data['admin_user'], data['admin_password'], [['admin', 'admin'], ['admin', '_member_']]) self.create_tenant(data['service_tenant_name'], 'Service Project') self.create_user(data['service_user'], data['service_password'], [['service', 'admin']]) for name, service in data['services'].items(): self.create_service(name, service) if self.is_tag('conf'): self.disable_admin_token()
def setup(self): data = self.init() node_os = env.node['os'] if re.match('Ubuntu 14.*', node_os): with api.warn_only(): sudo('apt-get update -y') self.install_packages() self.start_services() sudo('modprobe kvm') sudo('modprobe kvm_intel') for i, vm in enumerate(data['libvirt_vms']): template_data = { 'user': CONF.test.user, 'password': CONF.test.password, 'vm': vm, 'gateway': data['libvirt']['gateway'], 'netmask': data['libvirt']['netmask'], } vm_dir = '/var/lib/libvirt/images/{0}'.format(vm['name']) image_path = '{0}/vm.img'.format(vm_dir) metadata_path = '{0}/meta-data'.format(vm_dir) userdata_path = '{0}/user-data'.format(vm_dir) configiso_path = '{0}/config.iso'.format(vm_dir) src_image = vm['src_image'].rsplit('/', 1)[1] src_image_path = '/var/lib/libvirt/images/{0}'.format(src_image) src_image_format = 'qcow2' if src_image_path[-3:] == '.xz': src_image_path = src_image_path[:-3] src_image_format = 'xz' if not filer.exists(src_image_path): sudo('cd /var/lib/libvirt/images/ && wget {0}'.format(vm['src_image'])) if src_image_format == 'xz': sudo('cd /var/lib/libvirt/images/ && xz -d {0}'.format(src_image)) with api.warn_only(): sudo("virsh list --all | grep {0} && virsh destroy {0}" " && virsh undefine {0}".format(vm['name'])) sudo('rm -rf {0}'.format(vm_dir)) filer.mkdir(vm_dir) if not filer.exists(image_path): sudo('cp {0} {1}'.format(src_image_path, image_path)) sudo('qemu-img resize {0} {1}G'.format(image_path, vm.get('disk_size', 10))) filer.template(metadata_path, src='meta-data', data=template_data) filer.template(userdata_path, src=vm['template'], data=template_data) if not filer.exists(configiso_path): sudo('genisoimage -o {0} -V cidata -r -J {1} {2}'.format( configiso_path, metadata_path, userdata_path)) sudo("sed -i 's/^Defaults.*requiretty/# Defaults requiretty/' /etc/sudoers") vm['uuid'] = str(uuid.uuid1()) vm['image_path'] = image_path vm['configiso_path'] = configiso_path vm['tap'] = 'tap{0}'.format(i) vm['mac'] = self.get_random_mac() domain_xml = '/tmp/domain-{0}.xml'.format(vm['name']) filer.template(domain_xml, src='domain.xml', data=vm) with api.warn_only(): sudo("virsh net-update default delete ip-dhcp-host \"`virsh net-dumpxml default | grep '{0}' | sed -e 's/^ *//'`\"".format(vm['ip'])) sudo("virsh net-update default add ip-dhcp-host " "\"<host mac='{0}' name='{1}' ip='{2}' />\"".format( vm['mac'], vm['name'], vm['ip'])) sudo('virsh define {0}'.format(domain_xml)) sudo('virsh start {0}'.format(vm['name'])) # sudo("virt-install" # " --connect=qemu:///system" # " --name={name} --vcpus={vcpus} --ram={ram}" # " --accelerate --hvm --virt-type=kvm" # " --cpu host" # " --network bridge=virbr0,model=virtio" # " --disk {image_path},format=qcow2 --import" # " --disk {configiso_path},device=cdrom" # " --nographics &".format( # name=vm['name'], # vcpus=vm['vcpus'], # ram=vm['ram'], # image_path=image_path, # configiso_path=configiso_path, # ip=vm['ip'], # ), pty=False) # ), pty=False) for vm in data['libvirt_vms']: while True: with api.warn_only(): if run('nmap -p 22 {0} | grep open'.format(vm['ip'])): break time.sleep(5) sudo("iptables -R FORWARD 1 -o virbr0 -s 0.0.0.0/0" " -d 192.168.122.0/255.255.255.0 -j ACCEPT") for vm in data['libvirt_vms']: for port in vm.get('ports', []): sudo("iptables -t nat -A PREROUTING -p tcp" " --dport {0[1]} -j DNAT --to {1}:{0[0]}".format( port, vm['ip'])) for ip in data['iptables']: for port in ip.get('ports', []): sudo("iptables -t nat -A PREROUTING -p tcp" " --dport {0[1]} -j DNAT --to {1}:{0[0]}".format( port, ip['ip']))
def local(): filer.file('/etc/memcached.conf') filer.template('/etc/memcached.conf')
def setup(): filer.template('/tmp/test_template', data={'msg': 'world'}) filer.file('/tmp/test_file')
def setup(self): data = self.init() var_dir = CONF.client.package_var_dir tmp_dir = os.path.join(var_dir, 'tmp') log_dir = '/var/log/fabkit' common_repo = '{0}/fabkit-repo-common'.format(var_dir) client_repo = '{0}/fabkit-repo-client'.format(var_dir) server_repo = '{0}/fabkit-repo-server'.format(var_dir) if data['use_package']: Package(data['package_name']).install() return self.install_packages() self.python.setup() filer.mkdir(var_dir, owner=data['owner']) filer.mkdir(log_dir, owner=data['owner']) filer.mkdir(tmp_dir, owner=data['owner'], mode='777') filer.mkdir(common_repo, owner=data['owner']) filer.mkdir(client_repo, owner=data['owner']) filer.mkdir(server_repo, owner=data['owner']) sudo('rm -rf {0}/fabfile*'.format(tmp_dir)) fabfile_tar_gz = os.path.join(tmp_dir, 'fabfile.tar.gz') scp('/tmp/fabfile.tar.gz', fabfile_tar_gz) sudo('rm -rf {0}/fabfile'.format(common_repo)) sudo('cd {0} && tar xzf {1} && ' 'cp -r fabfile {2}/fabfile'.format(tmp_dir, fabfile_tar_gz, common_repo)) sudo('{0}/bin/pip install -r {1}/fabfile/requirements.txt'.format( CONF.client.package_prefix, common_repo)) data['repo'] = client_repo filer.template('{0}/bin/fabclient'.format(CONF.client.package_prefix), src='fabric.sh', data=data, mode='755') data['repo'] = server_repo filer.template('{0}/bin/fabserver'.format(CONF.client.package_prefix), src='fabric.sh', data=data, mode='755') filer.template('{0}/bin/fabnode'.format(CONF.client.package_prefix), src='fabnode.sh', data=data, mode='755') filer.template('/etc/systemd/system/fabagent.service', src='systemd.service', data={ 'description': 'fabagent', 'exec': '/opt/fabkit/bin/fabclient agent', 'user': '******', }) filer.template('/etc/systemd/system/fabagent-central.service', src='systemd.service', data={ 'description': 'fabagent', 'exec': '/opt/fabkit/bin/fabclient agent_central', 'user': '******', }) filer.template( '/etc/systemd/system/fabnode.service', src='systemd.service', data={ 'description': 'fabnode', 'exec': '/opt/fabkit/bin/fabnode', # noqa 'user': '******', }) sudo('systemctl daemon-reload') sudo('npm install -g coffee-script') sudo('cd {0}/fabfile/core/webapp/fabnode && ' 'npm install'.format(common_repo))
def setup(self): self.install_packages() self.start_services().enable_services() repo = '/home/{0}/fabkit-repo'.format(env.user) filer.mkdir(repo, use_sudo=False) git.setup() git.sync('https://github.com/fabrickit/fabkit.git', dest='{0}/fabfile'.format(repo)) python = Python('/opt/fabkit') python.setup() python.install( requirements='{0}/fabfile/requirements.txt'.format(repo)) run('cd {0} && /opt/fabkit/bin/fab genconfig:fabfile.ini &&' ' sed -i "/^\[web\]/,/^\[/s/#hostname =.*/hostname = */g" fabfile.ini' .format(repo)) data = { 'port': 80, 'repo': repo, 'user': env.user, 'group': env.user, 'python_path': python.get_site_packages(), 'processes': 5, 'threads': 1, } run('cd {0}/fabfile/core/webapp/ &&' ' /opt/fabkit/bin/python manage.py migrate &&' ' echo "from django.contrib.auth.models import User;' ' User.objects.create_superuser(\'admin\', \'admin@localhost\', \'admin\')"' ' | /opt/fabkit/bin/python manage.py shell &&' ' /opt/fabkit/bin/python manage.py collectstatic --noinput'.format( repo)) sudo('chmod 755 /home/{0}'.format(env.user)) if re.match('CentOS .*', env.node['os']): log_prefix = '/var/log/httpd/{0}'.format(env.user) data['error_log'] = '{0}-error.log'.format(log_prefix) data['custom_log'] = '{0}-access.log'.format(log_prefix) if filer.template(src='httpd.conf', dest='/etc/httpd/conf.d/{0}_httpd.conf'.format( env.user), data=data): self.handlers['restart_httpd'] = True elif re.match('Ubuntu .*', env.node['os']): log_prefix = '/var/log/apache2/{0}'.format(env.user) data['error_log'] = '{0}-error.log'.format(log_prefix) data['custom_log'] = '{0}-access.log'.format(log_prefix) if filer.template( src='httpd.conf', dest='/etc/apache2/sites-enabled/{0}_httpd.conf'.format( env.user), data=data): self.handlers['restart_apache2'] = True self.exec_handlers() # install sudo('npm install -g coffee-script'.format(repo)) sudo('cd {0}/fabfile/core/webapp && npm install'.format(repo)) # install node packages for develop sudo('npm install -g grunt-cli'.format(repo)) sudo( 'cd {0}/fabfile/core/webapp/node_chat && npm install'.format(repo))
def setup(self): data = self.init() if self.is_tag('package'): self.python.setup() self.install_packages() self.python.setup_package(**self.package) sudo('modprobe tun') # for vhost_net self.setup_network_bridge() if self.is_tag('conf'): filer.template( '/etc/sudoers.d/neutron', data=data, src='sudoers.j2', ) if filer.template( '/etc/neutron/neutron.conf', src='{0}/neutron.conf.j2'.format(data['version']), data=data, ): self.handlers['restart_neutron-*'] = True if filer.template( '/etc/neutron/plugins/ml2/ml2_conf.ini', src='{0}/ml2_conf.ini.j2'.format(data['version']), data=data, ): self.handlers['restart_neutron-*'] = True if self.data['version'] == 'kilo': linuxbridge_conf = '/etc/neutron/plugins/linuxbridge/linuxbridge_conf.ini' elif self.data['version'] in ['liberty', 'mitaka', 'master']: linuxbridge_conf = '/etc/neutron/plugins/ml2/linuxbridge_agent.ini' if filer.template( linuxbridge_conf, src='{0}/linuxbridge_conf.ini.j2'.format(data['version']), data=data, ): self.handlers['restart_neutron-*'] = True if self.data['version'] == 'kilo': ovs_conf = '/etc/neutron/plugins/openvswitch/ovs_neutron_plugin.ini' elif self.data['version'] in ['liberty', 'mitaka', 'master']: ovs_conf = '/etc/neutron/plugins/ml2/openvswitch_agent.ini' if 'openvswitch' in self.data['ml2']['mechanism_drivers']: if filer.template( ovs_conf, src='{0}/ovs_neutron_plugin.ini.j2'.format(data['version']), data=data, ): self.handlers['restart_neutron-*'] = True if filer.template( '/etc/neutron/l3_agent.ini', src='{0}/l3_agent.ini.j2'.format(data['version']), data=data, ): self.handlers['restart_neutron-*'] = True else: sudo('echo '' > {0}'.format(ovs_conf)) if filer.template( '/etc/neutron/dhcp_agent.ini', src='{0}/dhcp_agent.ini.j2'.format(data['version']), data=data, ): self.handlers['restart_neutron-*'] = True if filer.template( '/etc/neutron/metadata_agent.ini', src='{0}/metadata_agent.ini.j2'.format(data['version']), data=data, ): self.handlers['restart_neutron-*'] = True # lbaas if filer.template( '/etc/neutron/services_lbaas.conf', src='{0}/services_lbaas.conf.j2'.format(data['version']), data=data, ): self.handlers['restart_neutron-*'] = True if filer.template( '/etc/neutron/neutron_lbaas.conf', src='{0}/neutron_lbaas.conf.j2'.format(data['version']), data=data, ): self.handlers['restart_neutron-*'] = True if filer.template( '/etc/neutron/lbaas_agent.ini', src='{0}/lbaas_agent.ini.j2'.format(data['version']), data=data, ): self.handlers['restart_neutron-*'] = True if self.is_tag('data') and env.host == env.hosts[0]: if data['is_master']: option = '--config-file /etc/neutron/neutron.conf' run('{0}/bin/neutron-db-manage {1} upgrade head'.format(self.prefix, option)) run('{0}/bin/neutron-db-manage {1} --service lbaas upgrade head'.format( self.prefix, option)) if self.is_tag('service'): self.enable_services().start_services(pty=False) self.exec_handlers() if self.is_tag('data') and env.host == env.hosts[0]: if data['is_master']: time.sleep(5) self.create_nets() self.create_routers() return 0