def show_space_usage(zfs_cmd='/usr/sbin/zfs', tr_cmd='/usr/bin/tr', nmc_cmd='/usr/bin/nmc -c', tr='tr \'[[:blank:]]\' \' \'', dataset=''): with settings( hide('running', 'stdout', 'stderr'), warn_only=True, always_use_pty='false', shell=default_shell, user='******', ): ''' Testing to see if dataset is name of pool only, or name of pool including child dataset ''' if not dataset == dataset.split('/'): ## is '/' in the name validate = get_volume(vol=dataset.split('/')[0]) else: validate = get_volume(vol=dataset) ''' Next, we need to confirm that pool name is valid and exists on the target SAN ''' if validate == False: fab_abort( 'Invalid Volume Name {0}, Please check name.'.format(dataset)) print 'FAILED!!!' else: result = fab_run('%s %s|%s' % (zfs_spa_cmd, dataset, tr)) if result.succeeded: final_space_usage = organize_dataset_list(result) #print final_zvols print '%s' % ('') write_line(char='x') print '>> Task Succeeded: [%s] >> Total Dataset Count: [%d]' % \ ('show_zvol',len(final_space_usage)) write_line(char='x') for line in final_space_usage: ofields = (line[0], line[1], line[2], line[3], line[4], line[5], line[6]) print show_space_usage_fmt.format(ofields) return True else: return False
def show_space_usage (zfs_cmd='/usr/sbin/zfs', tr_cmd='/usr/bin/tr', nmc_cmd='/usr/bin/nmc -c', tr = 'tr \'[[:blank:]]\' \' \'', dataset=''): with settings( hide('running', 'stdout', 'stderr'), warn_only=True, always_use_pty='false', shell=default_shell, user='******',): ''' Testing to see if dataset is name of pool only, or name of pool including child dataset ''' if not dataset == dataset.split('/'): ## is '/' in the name validate = get_volume(vol=dataset.split('/')[0]) else: validate = get_volume(vol=dataset) ''' Next, we need to confirm that pool name is valid and exists on the target SAN ''' if validate == False: fab_abort('Invalid Volume Name {0}, Please check name.'.format(dataset)) print 'FAILED!!!' else: result = fab_run('%s %s|%s' % (zfs_spa_cmd, dataset, tr)) if result.succeeded: final_space_usage = organize_dataset_list(result) #print final_zvols print '%s' % ('') write_line(char='x') print '>> Task Succeeded: [%s] >> Total Dataset Count: [%d]' % \ ('show_zvol',len(final_space_usage)) write_line(char='x') for line in final_space_usage: ofields = (line[0],line[1],line[2],line[3], line[4],line[5],line[6]) print show_space_usage_fmt.format(ofields) return True else: return False
def install_deps(ag='apt-get'): reqs = ['apache2', 'libapache2-mod-wsgi', 'libapache2-mod-python', 'memcached', 'python-dev', 'python-cairo-dev', 'python-django', 'python-ldap', 'python-memcache', 'python-pysqlite2', 'sqlite3', 'erlang-os-mon', 'erlang-snmp', 'rabbitmq-server'] with settings( show('running', 'stdout', 'stderr'), warn_only=True, always_use_pty='false'): a = fab_local("{0} install --no-install-recommends --assume-yes {1}".format(ag," ".join(reqs))) b = fab_local('pip install django-tagging') if a.succeeded and b.succeeded: fab_puts("Installed Prerequisites for Graphite.", show_prefix=False) else: if a.failed: print a.stderr if b.failed: print b.stderr fab_abort("Failed to Install Pre-requisites, cannot continue.", show_prefix=False)
def configure(): graph_conf_path='/opt/graphite/conf' graph_stor_path = '/opt/graphite/storage' apache_avail = '/etc/apache2/sites-available' apache_enab = '/etc/apache2/sites-enabled' apache_src_conf = '/root/default-graphite' apache_dst_conf = "{0}/{1}".format(apache_avail,'default-graphite') apache_enab_conf = "{0}/{1}".format(apache_enab,'default-graphite') stor_sch_conf = "{0}/{1}".format(graph_conf_path,'storage-schemas.conf') with settings( show('running', 'stdout', 'stderr'), warn_only=True, always_use_pty='false'): for file in ['carbon.conf','storage-schemas.conf','graphite.wsgi']: src = "{0}/{1}.example".format(graph_conf_path,file) dst = "{0}/{1}".format(graph_conf_path,file) ## Copy from example, template to real file copyfile(src,dst) ## Generate default-graphite apache config file, based on ## template at top of this file. make_apache_conf = Template(apache_base_templ) ## Write template into the new config file ## /etc/apache2/sites-available/default-graphite try: open(apache_dst_conf,'wt').write( make_apache_conf.substitute(port=80,wsgi_sockd='/etc/httpd/wsgi/') ) fab_puts("Wrote apache config for Graphite WebApp.",show_prefix=False) except IOError as e: fab_abort("Error {0} Failed to open file {1}".format(e.errno,e.filename)) try: open(stor_sch_conf,'at').write(stor_base_templ) fab_puts("Updated storage schema config with brickstor elements.",show_prefix=False) except IOError as e: fab_abort("Error {0} Failed to open file {1}".format(e.errno,e.filename)) try: os_remove('/etc/apache2/sites-enabled/000-default') except OSError as e: print "Warning: {0} {1}".format(e.filename,e.args) ## Create necessary directories for Apache for dir in ['/etc/httpd','/etc/httpd/wsgi']: try: os_mkdir(dir,0755) fab_puts("Created directory: {0}".format(dir),show_prefix=False) except OSError as e: print "Warning: {0} {1}".format(e.filename,e.args) try: os_symlink(apache_dst_conf, apache_enab_conf) fab_puts("Created symbolic link for {0}".format(apache_dst_conf),show_prefix=False) except OSError as e: print "Warning: {0} {1}".format(e.filename,e.args) with fab_lcd('/opt/graphite/webapp/graphite/'): fab_local('python manage.py syncdb') ## This should really use python os module, will fix later. fab_local("chown -R {0} {1}".format('www-data:www-data',graph_stor_path)) ## Copy local_settings.py.example config into real config file src = '/opt/graphite/webapp/graphite/local_settings.py.example' dst = '/opt/graphite/webapp/graphite/local_settings.py' copyfile(src,dst) ## Reload Apache config after all the changes fab_local("/etc/init.d/apache2 reload")