Python fabric.contrib.files.exists() Examples
The following are 30
code examples of fabric.contrib.files.exists().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
fabric.contrib.files
, or try the search function
.
Example #1
Source File: notebook_lib.py From incubator-dlab with Apache License 2.0 | 7 votes |
def ensure_r(os_user, r_libs, region, r_mirror): if not exists('/home/{}/.ensure_dir/r_ensured'.format(os_user)): try: if region == 'cn-north-1': r_repository = r_mirror else: r_repository = 'https://cloud.r-project.org' manage_pkg('-y install', 'remote', 'cmake') manage_pkg('-y install', 'remote', 'libcur*') sudo('echo -e "[base]\nname=CentOS-7-Base\nbaseurl=http://buildlogs.centos.org/centos/7/os/x86_64-20140704-1/\ngpgcheck=1\ngpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7\npriority=1\nexclude=php mysql" >> /etc/yum.repos.d/CentOS-base.repo') manage_pkg('-y install', 'remote', 'R R-core R-core-devel R-devel --nogpgcheck') sudo('R CMD javareconf') sudo('cd /root; git clone https://github.com/zeromq/zeromq4-x.git; cd zeromq4-x/; mkdir build; cd build; cmake ..; make install; ldconfig') for i in r_libs: sudo('R -e "install.packages(\'{}\',repos=\'{}\')"'.format(i, r_repository)) sudo('R -e "library(\'devtools\');install.packages(repos=\'{}\',c(\'rzmq\',\'repr\',\'digest\',\'stringr\',\'RJSONIO\',\'functional\',\'plyr\'))"'.format(r_repository)) sudo('R -e "library(\'devtools\');install_github(\'IRkernel/repr\');install_github(\'IRkernel/IRdisplay\');install_github(\'IRkernel/IRkernel\');"') sudo('R -e "library(\'devtools\');install_version(\'keras\', version = \'{}\', repos = \'{}\');"'.format(os.environ['notebook_keras_version'],r_repository)) sudo('R -e "install.packages(\'RJDBC\',repos=\'{}\',dep=TRUE)"'.format(r_repository)) sudo('touch /home/{}/.ensure_dir/r_ensured'.format(os_user)) except: sys.exit(1)
Example #2
Source File: notebook_lib.py From incubator-dlab with Apache License 2.0 | 6 votes |
def ensure_python2_libraries(os_user): if not exists('/home/' + os_user + '/.ensure_dir/python2_libraries_ensured'): try: sudo('pip2 install pyparsing==2.0.3') manage_pkg('-y install', 'remote', 'python-setuptools python-wheel') manage_pkg('-y install', 'remote', 'python-virtualenv openssl-devel python-devel openssl-libs libxslt-devel --nogpgcheck') try: sudo('python2 -m pip install backports.shutil_get_terminal_size tornado=={0} ipython ipykernel=={1} --no-cache-dir' \ .format(os.environ['notebook_tornado_version'], os.environ['notebook_ipykernel_version'])) except: sudo('python2 -m pip install backports.shutil_get_terminal_size tornado=={0} ipython==5.0.0 ipykernel=={1} --no-cache-dir' \ .format(os.environ['notebook_tornado_version'], os.environ['notebook_ipykernel_version'])) sudo('echo y | python2 -m pip uninstall backports.shutil_get_terminal_size') sudo('python2 -m pip install backports.shutil_get_terminal_size --no-cache-dir') sudo('pip2 install -UI pip=={} setuptools --no-cache-dir'.format(os.environ['conf_pip_version'])) sudo('pip2 install boto3 backoff --no-cache-dir') sudo('pip2 install fabvenv fabric-virtualenv future --no-cache-dir') downgrade_python_version() sudo('touch /home/' + os_user + '/.ensure_dir/python2_libraries_ensured') except: sys.exit(1)
Example #3
Source File: notebook_lib.py From incubator-dlab with Apache License 2.0 | 6 votes |
def install_caffe2(os_user, caffe2_version, cmake_version): if not exists('/home/{}/.ensure_dir/caffe2_ensured'.format(os_user)): env.shell = "/bin/bash -l -c -i" manage_pkg('update-minimal --security -y', 'remote', '') manage_pkg('-y install --nogpgcheck', 'remote', 'automake cmake3 gcc gcc-c++ kernel-devel leveldb-devel lmdb-devel libtool protobuf-devel graphviz') sudo('pip2 install flask graphviz hypothesis jupyter matplotlib==2.0.2 numpy=={} protobuf pydot python-nvd3 pyyaml ' 'requests scikit-image scipy setuptools tornado future --no-cache-dir'.format(os.environ['notebook_numpy_version'])) sudo('pip3.5 install flask graphviz hypothesis jupyter matplotlib==2.0.2 numpy=={} protobuf pydot python-nvd3 pyyaml ' 'requests scikit-image scipy setuptools tornado future --no-cache-dir'.format(os.environ['notebook_numpy_version'])) sudo('cp /opt/cudnn/include/* /opt/cuda-8.0/include/') sudo('cp /opt/cudnn/lib64/* /opt/cuda-8.0/lib64/') sudo('wget https://cmake.org/files/v{2}/cmake-{1}.tar.gz -O /home/{0}/cmake-{1}.tar.gz'.format( os_user, cmake_version, cmake_version.split('.')[0] + "." + cmake_version.split('.')[1])) sudo('tar -zxvf cmake-{}.tar.gz'.format(cmake_version)) with cd('/home/{}/cmake-{}/'.format(os_user, cmake_version)): sudo('./bootstrap --prefix=/usr/local && make && make install') sudo('ln -s /usr/local/bin/cmake /bin/cmake{}'.format(cmake_version)) sudo('git clone https://github.com/pytorch/pytorch.git') with cd('/home/{}/pytorch/'.format(os_user)): sudo('git submodule update --init') with settings(warn_only=True): sudo('git checkout v{}'.format(caffe2_version)) sudo('git submodule update --recursive') sudo('mkdir build && cd build && cmake{} .. && make "-j$(nproc)" install'.format(cmake_version)) sudo('touch /home/' + os_user + '/.ensure_dir/caffe2_ensured')
Example #4
Source File: notebook_lib.py From incubator-dlab with Apache License 2.0 | 6 votes |
def ensure_python3_libraries(os_user): if not exists('/home/' + os_user + '/.ensure_dir/python3_libraries_ensured'): try: manage_pkg('-y install', 'remote', 'https://centos7.iuscommunity.org/ius-release.rpm') manage_pkg('-y install', 'remote', 'python35u python35u-pip python35u-devel') sudo('python3.5 -m pip install -U pip=={} setuptools --no-cache-dir'.format(os.environ['conf_pip_version'])) sudo('python3.5 -m pip install boto3 --no-cache-dir') sudo('python3.5 -m pip install fabvenv fabric-virtualenv future --no-cache-dir') try: sudo('python3.5 -m pip install tornado=={0} ipython==7.9.0 ipykernel=={1} --no-cache-dir' \ .format(os.environ['notebook_tornado_version'], os.environ['notebook_ipykernel_version'])) except: sudo('python3.5 -m pip install tornado=={0} ipython==5.0.0 ipykernel=={1} --no-cache-dir' \ .format(os.environ['notebook_tornado_version'], os.environ['notebook_ipykernel_version'])) sudo('touch /home/' + os_user + '/.ensure_dir/python3_libraries_ensured') except: sys.exit(1)
Example #5
Source File: notebook_lib.py From incubator-dlab with Apache License 2.0 | 6 votes |
def ensure_r_local_kernel(spark_version, os_user, templates_dir, kernels_dir): if not exists('/home/' + os_user + '/.ensure_dir/r_local_kernel_ensured'): try: sudo('R -e "IRkernel::installspec()"') r_version = sudo("R --version | awk '/version / {print $3}'") put(templates_dir + 'r_template.json', '/tmp/r_template.json') sudo('sed -i "s|R_VER|' + r_version + '|g" /tmp/r_template.json') sudo('sed -i "s|SP_VER|' + spark_version + '|g" /tmp/r_template.json') sudo('\cp -f /tmp/r_template.json {}/ir/kernel.json'.format(kernels_dir)) sudo('ln -s /opt/spark/ /usr/local/spark') try: sudo('cd /usr/local/spark/R/lib/SparkR; R -e "install.packages(\'roxygen2\',repos=\'https://cloud.r-project.org\')" R -e "devtools::check(\'.\')"') except: pass sudo('cd /usr/local/spark/R/lib/SparkR; R -e "devtools::install(\'.\')"') sudo('chown -R ' + os_user + ':' + os_user + ' /home/' + os_user + '/.local') sudo('touch /home/' + os_user + '/.ensure_dir/r_local_kernel_ensured') except: sys.exit(1)
Example #6
Source File: notebook_lib.py From incubator-dlab with Apache License 2.0 | 6 votes |
def ensure_python3_libraries(os_user): if not exists('/home/' + os_user + '/.ensure_dir/python3_libraries_ensured'): try: manage_pkg('-y install', 'remote', 'python3-setuptools') manage_pkg('-y install', 'remote', 'python3-pip') try: sudo('pip3 install tornado=={0} ipython==7.9.0 ipykernel=={1} --no-cache-dir' \ .format(os.environ['notebook_tornado_version'], os.environ['notebook_ipykernel_version'])) except: sudo('pip3 install tornado=={0} ipython==5.0.0 ipykernel=={1} --no-cache-dir' \ .format(os.environ['notebook_tornado_version'], os.environ['notebook_ipykernel_version'])) sudo('pip3 install -U pip=={} --no-cache-dir'.format(os.environ['conf_pip_version'])) sudo('pip3 install boto3 --no-cache-dir') sudo('pip3 install fabvenv fabric-virtualenv future --no-cache-dir') sudo('touch /home/' + os_user + '/.ensure_dir/python3_libraries_ensured') except: sys.exit(1)
Example #7
Source File: fab.py From incubator-dlab with Apache License 2.0 | 6 votes |
def install_inactivity_checker(os_user, ip_address, rstudio=False): if not exists('/home/{}/.ensure_dir/inactivity_ensured'.format(os_user)): try: if not exists('/opt/inactivity'): sudo('mkdir /opt/inactivity') put('/root/templates/inactive.service', '/etc/systemd/system/inactive.service', use_sudo=True) put('/root/templates/inactive.timer', '/etc/systemd/system/inactive.timer', use_sudo=True) if rstudio: put('/root/templates/inactive_rs.sh', '/opt/inactivity/inactive.sh', use_sudo=True) else: put('/root/templates/inactive.sh', '/opt/inactivity/inactive.sh', use_sudo=True) sudo("sed -i 's|IP_ADRESS|{}|g' /opt/inactivity/inactive.sh".format(ip_address)) sudo("chmod 755 /opt/inactivity/inactive.sh") sudo("chown root:root /etc/systemd/system/inactive.service") sudo("chown root:root /etc/systemd/system/inactive.timer") sudo("date +%s > /opt/inactivity/local_inactivity") sudo('systemctl daemon-reload') sudo('systemctl enable inactive.timer') sudo('systemctl start inactive.timer') sudo('touch /home/{}/.ensure_dir/inactive_ensured'.format(os_user)) except Exception as err: print('Failed to setup inactivity check service!', str(err)) sys.exit(1)
Example #8
Source File: fab.py From incubator-dlab with Apache License 2.0 | 6 votes |
def update_spark_jars(jars_dir='/opt/jars'): try: configs = sudo('find /opt/ /etc/ /usr/lib/ -name spark-defaults.conf -type f').split('\r\n') if exists(jars_dir): for conf in filter(None, configs): des_path = '' all_jars = sudo('find {0} -name "*.jar"'.format(jars_dir)).split('\r\n') if ('-des-' in conf): des_path = '/'.join(conf.split('/')[:3]) all_jars = find_des_jars(all_jars, des_path) sudo('''sed -i '/^# Generated\|^spark.jars/d' {0}'''.format(conf)) sudo('echo "# Generated spark.jars by DLab from {0}\nspark.jars {1}" >> {2}' .format(','.join(filter(None, [jars_dir, des_path])), ','.join(all_jars), conf)) # sudo("sed -i 's/^[[:space:]]*//' {0}".format(conf)) else: print("Can't find directory {0} with jar files".format(jars_dir)) except Exception as err: append_result("Failed to update spark.jars parameter", str(err)) print("Failed to update spark.jars parameter") sys.exit(1)
Example #9
Source File: notebook_lib.py From incubator-dlab with Apache License 2.0 | 6 votes |
def ensure_r_local_kernel(spark_version, os_user, templates_dir, kernels_dir): if not exists('/home/{}/.ensure_dir/r_kernel_ensured'.format(os_user)): try: sudo('chown -R ' + os_user + ':' + os_user + ' /home/' + os_user + '/.local') run('R -e "IRkernel::installspec()"') sudo('ln -s /opt/spark/ /usr/local/spark') try: sudo('cd /usr/local/spark/R/lib/SparkR; R -e "install.packages(\'roxygen2\',repos=\'https://cloud.r-project.org\')" R -e "devtools::check(\'.\')"') except: pass sudo('cd /usr/local/spark/R/lib/SparkR; R -e "devtools::install(\'.\')"') r_version = sudo("R --version | awk '/version / {print $3}'") put(templates_dir + 'r_template.json', '/tmp/r_template.json') sudo('sed -i "s|R_VER|' + r_version + '|g" /tmp/r_template.json') sudo('sed -i "s|SP_VER|' + spark_version + '|g" /tmp/r_template.json') sudo('\cp -f /tmp/r_template.json {}/ir/kernel.json'.format(kernels_dir)) sudo('ln -s /usr/lib64/R/ /usr/lib/R') sudo('chown -R ' + os_user + ':' + os_user + ' /home/' + os_user + '/.local') sudo('touch /home/{}/.ensure_dir/r_kernel_ensured'.format(os_user)) except: sys.exit(1)
Example #10
Source File: fabfile.py From Expert-Python-Programming_Second-Edition with BSD 3-Clause "New" or "Revised" License | 6 votes |
def deploy(): """ Deploy application with packaging in mind """ version = get_version() pip_path = os.path.join( REMOTE_PROJECT_LOCATION, version, 'bin', 'pip' ) prepare_release() if not exists(REMOTE_PROJECT_LOCATION): # it may not exist for initial deployment on fresh host run("mkdir -p {}".format(REMOTE_PROJECT_LOCATION)) with cd(REMOTE_PROJECT_LOCATION): # create new virtual environment using venv run('python3 -m venv {}'.format(version)) run("{} install webxample=={} --index-url {}".format( pip_path, version, PYPI_URL )) switch_versions(version) # let's assume that Circus is our process supervision tool # of choice. run('circusctl restart webxample')
Example #11
Source File: common_lib.py From incubator-dlab with Apache License 2.0 | 5 votes |
def ensure_java(user): try: if not exists('/home/{}/.ensure_dir/java_ensured'.format(user)): manage_pkg('-y install', 'remote', 'java-1.8.0-openjdk-devel') sudo('touch /home/{}/.ensure_dir/java_ensured'.format(user)) except: sys.exit(1)
Example #12
Source File: common_lib.py From incubator-dlab with Apache License 2.0 | 5 votes |
def ensure_step(user): try: if not exists('/home/{}/.ensure_dir/step_ensured'.format(user)): manage_pkg('-y install', 'remote', 'wget') sudo('wget https://github.com/smallstep/cli/releases/download/v0.13.3/step_0.13.3_linux_amd64.tar.gz ' '-O /tmp/step_0.13.3_linux_amd64.tar.gz') sudo('tar zxvf /tmp/step_0.13.3_linux_amd64.tar.gz -C /tmp/') sudo('mv /tmp/step_0.13.3/bin/step /usr/bin/') sudo('touch /home/{}/.ensure_dir/step_ensured'.format(user)) except: sys.exit(1)
Example #13
Source File: actions_lib.py From incubator-dlab with Apache License 2.0 | 5 votes |
def prepare_disk(os_user): if not exists('/home/' + os_user + '/.ensure_dir/disk_ensured'): try: disk_name = sudo("lsblk | grep disk | awk '{print $1}' | sort | tail -n 1") sudo('''bash -c 'echo -e "o\nn\np\n1\n\n\nw" | fdisk /dev/{}' '''.format(disk_name)) sudo('mkfs.ext4 -F /dev/{}1'.format(disk_name)) sudo('mount /dev/{}1 /opt/'.format(disk_name)) sudo(''' bash -c "echo '/dev/{}1 /opt/ ext4 errors=remount-ro 0 1' >> /etc/fstab" '''.format(disk_name)) sudo('touch /home/' + os_user + '/.ensure_dir/disk_ensured') except: sys.exit(1)
Example #14
Source File: notebook_lib.py From incubator-dlab with Apache License 2.0 | 5 votes |
def install_maven(os_user): if not exists('/home/' + os_user + '/.ensure_dir/maven_ensured'): sudo('wget http://apache.volia.net/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz -O /tmp/maven.tar.gz') sudo('tar -zxvf /tmp/maven.tar.gz -C /opt/') sudo('ln -fs /opt/apache-maven-3.3.9/bin/mvn /usr/bin/mvn') sudo('touch /home/' + os_user + '/.ensure_dir/maven_ensured')
Example #15
Source File: actions_lib.py From incubator-dlab with Apache License 2.0 | 5 votes |
def get_files(s3client, s3resource, dist, bucket, local): s3list = s3client.get_paginator('list_objects') for result in s3list.paginate(Bucket=bucket, Delimiter='/', Prefix=dist): if result.get('CommonPrefixes') is not None: for subdir in result.get('CommonPrefixes'): get_files(s3client, s3resource, subdir.get('Prefix'), bucket, local) if result.get('Contents') is not None: for file in result.get('Contents'): if not os.path.exists(os.path.dirname(local + os.sep + file.get('Key'))): os.makedirs(os.path.dirname(local + os.sep + file.get('Key'))) s3resource.meta.client.download_file(bucket, file.get('Key'), local + os.sep + file.get('Key'))
Example #16
Source File: actions_lib.py From incubator-dlab with Apache License 2.0 | 5 votes |
def ensure_local_jars(os_user, jars_dir): if not exists('/home/{}/.ensure_dir/local_jars_ensured'.format(os_user)): try: sudo('mkdir -p {0}'.format(jars_dir)) sudo('wget https://repo1.maven.org/maven2/org/apache/hadoop/hadoop-aws/{0}/hadoop-aws-{0}.jar -O \ {1}hadoop-aws-{0}.jar'.format('2.7.4', jars_dir)) sudo('wget https://repo1.maven.org/maven2/com/amazonaws/aws-java-sdk/{0}/aws-java-sdk-{0}.jar -O \ {1}aws-java-sdk-{0}.jar'.format('1.7.4', jars_dir)) # sudo('wget https://maven.twttr.com/com/hadoop/gplcompression/hadoop-lzo/{0}/hadoop-lzo-{0}.jar -O \ # {1}hadoop-lzo-{0}.jar'.format('0.4.20', jars_dir)) sudo('touch /home/{}/.ensure_dir/local_jars_ensured'.format(os_user)) except: sys.exit(1)
Example #17
Source File: actions_lib.py From incubator-dlab with Apache License 2.0 | 5 votes |
def ensure_local_jars(os_user, jars_dir): if not exists('/home/{}/.ensure_dir/local_jars_ensured'.format(os_user)): try: hadoop_version = sudo("ls /opt/spark/jars/hadoop-common* | sed -n 's/.*\([0-9]\.[0-9]\.[0-9]\).*/\\1/p'") print("Downloading local jars for Azure") sudo('mkdir -p {}'.format(jars_dir)) if os.environ['azure_datalake_enable'] == 'false': sudo('wget https://repo1.maven.org/maven2/org/apache/hadoop/hadoop-azure/{0}/hadoop-azure-{0}.jar -O \ {1}hadoop-azure-{0}.jar'.format(hadoop_version, jars_dir)) sudo('wget https://repo1.maven.org/maven2/com/microsoft/azure/azure-storage/{0}/azure-storage-{0}.jar \ -O {1}azure-storage-{0}.jar'.format('2.2.0', jars_dir)) else: sudo('wget https://repo1.maven.org/maven2/org/apache/hadoop/hadoop-azure/{0}/hadoop-azure-{0}.jar -O \ {1}hadoop-azure-{0}.jar'.format('3.0.0', jars_dir)) sudo('wget https://repo1.maven.org/maven2/com/microsoft/azure/azure-storage/{0}/azure-storage-{0}.jar \ -O {1}azure-storage-{0}.jar'.format('6.1.0', jars_dir)) sudo('wget https://repo1.maven.org/maven2/com/microsoft/azure/azure-data-lake-store-sdk/{0}/azure-data-lake-store-sdk-{0}.jar \ -O {1}azure-data-lake-store-sdk-{0}.jar'.format('2.2.3', jars_dir)) sudo('wget https://repo1.maven.org/maven2/org/apache/hadoop/hadoop-azure-datalake/{0}/hadoop-azure-datalake-{0}.jar \ -O {1}hadoop-azure-datalake-{0}.jar'.format('3.0.0', jars_dir)) if os.environ['application'] == 'tensor' or os.environ['application'] == 'deeplearning': sudo('wget https://dl.bintray.com/spark-packages/maven/tapanalyticstoolkit/spark-tensorflow-connector/{0}/spark-tensorflow-connector-{0}.jar \ -O {1}spark-tensorflow-connector-{0}.jar'.format('1.0.0-s_2.11', jars_dir)) sudo('touch /home/{}/.ensure_dir/local_jars_ensured'.format(os_user)) except Exception as err: logging.info( "Unable to download local jars: " + str(err) + "\n Traceback: " + traceback.print_exc(file=sys.stdout)) append_result(str({"error": "Unable to download local jars", "error_message": str(err) + "\n Traceback: " + traceback.print_exc( file=sys.stdout)})) traceback.print_exc(file=sys.stdout)
Example #18
Source File: notebook_lib.py From incubator-dlab with Apache License 2.0 | 5 votes |
def install_livy_dependencies_emr(os_user): if not os.path.exists('/home/' + os_user + '/.ensure_dir/livy_dependencies_ensured'): local('sudo -i pip2 install cloudpickle requests requests-kerberos flake8 flaky pytest --no-cache-dir') local('sudo -i pip3.5 install cloudpickle requests requests-kerberos flake8 flaky pytest --no-cache-dir') local('touch /home/' + os_user + '/.ensure_dir/livy_dependencies_ensured')
Example #19
Source File: actions_lib.py From incubator-dlab with Apache License 2.0 | 5 votes |
def prepare_disk(os_user): if not exists('/home/' + os_user + '/.ensure_dir/disk_ensured'): try: remount_azure_disk() disk_name = sudo("lsblk | grep disk | awk '{print $1}' | sort | tail -n 1") with settings(warn_only=True): sudo('umount -l /dev/{}1'.format(disk_name)) sudo('''bash -c 'echo -e "o\nn\np\n1\n\n\nw" | fdisk /dev/{}' '''.format(disk_name)) sudo('mkfs.ext4 -F /dev/{}1'.format(disk_name)) sudo('mount /dev/{}1 /opt/'.format(disk_name)) sudo(''' bash -c "echo '/dev/{}1 /opt/ ext4 errors=remount-ro 0 1' >> /etc/fstab" '''.format(disk_name)) sudo('touch /home/' + os_user + '/.ensure_dir/disk_ensured') except: sys.exit(1)
Example #20
Source File: notebook_lib.py From incubator-dlab with Apache License 2.0 | 5 votes |
def ensure_additional_python_libs(os_user): if not exists('/home/' + os_user + '/.ensure_dir/additional_python_libs_ensured'): try: manage_pkg('clean', 'remote', 'all') manage_pkg('-y install', 'remote', 'zlib-devel libjpeg-turbo-devel --nogpgcheck') if os.environ['application'] in ('jupyter', 'zeppelin'): sudo('pip2 install NumPy=={} SciPy pandas Sympy Pillow sklearn --no-cache-dir'.format(os.environ['notebook_numpy_version'])) sudo('python3.5 -m pip install NumPy=={} SciPy pandas Sympy Pillow sklearn --no-cache-dir'.format(os.environ['notebook_numpy_version'])) if os.environ['application'] in ('tensor', 'deeplearning'): sudo('python2.7 -m pip install opencv-python h5py --no-cache-dir') sudo('python3.5 -m pip install opencv-python h5py --no-cache-dir') sudo('touch /home/' + os_user + '/.ensure_dir/additional_python_libs_ensured') except: sys.exit(1)
Example #21
Source File: notebook_lib.py From incubator-dlab with Apache License 2.0 | 5 votes |
def ensure_scala(scala_link, scala_version, os_user): if not exists('/home/' + os_user + '/.ensure_dir/scala_ensured'): try: sudo('wget {}scala-{}.rpm -O /tmp/scala.rpm'.format(scala_link, scala_version)) sudo('rpm -i /tmp/scala.rpm') sudo('touch /home/' + os_user + '/.ensure_dir/scala_ensured') except: sys.exit(1)
Example #22
Source File: notebook_lib.py From incubator-dlab with Apache License 2.0 | 5 votes |
def ensure_jre_jdk(os_user): if not exists('/home/' + os_user + '/.ensure_dir/jre_jdk_ensured'): try: manage_pkg('-y install', 'remote', 'java-1.8.0-openjdk') manage_pkg('-y install', 'remote', 'java-1.8.0-openjdk-devel') sudo('touch /home/' + os_user + '/.ensure_dir/jre_jdk_ensured') except: sys.exit(1)
Example #23
Source File: notebook_lib.py From incubator-dlab with Apache License 2.0 | 5 votes |
def ensure_sbt(os_user): if not exists('/home/{}/.ensure_dir/sbt_ensured'.format(os_user)): try: sudo('curl https://bintray.com/sbt/rpm/rpm | sudo tee /etc/yum.repos.d/bintray-sbt-rpm.repo') manage_pkg('-y install', 'remote', 'sbt') sudo('touch /home/{}/.ensure_dir/sbt_ensured'.format(os_user)) except: sys.exit(1)
Example #24
Source File: notebook_lib.py From incubator-dlab with Apache License 2.0 | 5 votes |
def ensure_matplot(os_user): if not exists('/home/{}/.ensure_dir/matplot_ensured'.format(os_user)): try: sudo('pip2 install matplotlib==2.0.2 --no-cache-dir') sudo('python3.5 -m pip install matplotlib==2.0.2 --no-cache-dir') if os.environ['application'] in ('tensor', 'deeplearning'): sudo('python2.7 -m pip install -U numpy=={} --no-cache-dir'.format(os.environ['notebook_numpy_version'])) sudo('python3.5 -m pip install -U numpy=={} --no-cache-dir'.format(os.environ['notebook_numpy_version'])) sudo('touch /home/{}/.ensure_dir/matplot_ensured'.format(os_user)) except: sys.exit(1)
Example #25
Source File: notebook_lib.py From incubator-dlab with Apache License 2.0 | 5 votes |
def enable_proxy(proxy_host, proxy_port): try: proxy_string = "http://%s:%s" % (proxy_host, proxy_port) sudo('sed -i "/^export http_proxy/d" /etc/profile') sudo('sed -i "/^export https_proxy/d" /etc/profile') sudo('echo export http_proxy=' + proxy_string + ' >> /etc/profile') sudo('echo export https_proxy=' + proxy_string + ' >> /etc/profile') if exists('/etc/yum.conf'): sudo('sed -i "/^proxy=/d" /etc/yum.conf') sudo("echo 'proxy={}' >> /etc/yum.conf".format(proxy_string)) manage_pkg('clean all', 'remote', '') except: sys.exit(1)
Example #26
Source File: edge_lib.py From incubator-dlab with Apache License 2.0 | 5 votes |
def configure_http_proxy_server(config): try: if not exists('/tmp/http_proxy_ensured'): manage_pkg('-y install', 'remote', 'squid') template_file = config['template_file'] proxy_subnet = config['exploratory_subnet'] put(template_file, '/tmp/squid.conf') sudo('\cp /tmp/squid.conf /etc/squid/squid.conf') sudo('sed -i "s|PROXY_SUBNET|{}|g" /etc/squid/squid.conf'.format(proxy_subnet)) sudo('sed -i "s|EDGE_USER_NAME|{}|g" /etc/squid/squid.conf'.format(config['project_name'])) sudo('sed -i "s|LDAP_HOST|{}|g" /etc/squid/squid.conf'.format(config['ldap_host'])) sudo('sed -i "s|LDAP_DN|{}|g" /etc/squid/squid.conf'.format(config['ldap_dn'])) sudo('sed -i "s|LDAP_SERVICE_USERNAME|{}|g" /etc/squid/squid.conf'.format(config['ldap_user'])) sudo('sed -i "s|LDAP_SERVICE_PASSWORD|{}|g" /etc/squid/squid.conf'.format(config['ldap_password'])) sudo('sed -i "s|LDAP_AUTH_PATH|{}|g" /etc/squid/squid.conf'.format('/usr/lib64/squid/basic_ldap_auth')) replace_string = '' for cidr in config['vpc_cidrs']: replace_string += 'acl AWS_VPC_CIDR dst {}\\n'.format(cidr) sudo('sed -i "s|VPC_CIDRS|{}|g" /etc/squid/squid.conf'.format(replace_string)) replace_string = '' for cidr in config['allowed_ip_cidr']: replace_string += 'acl AllowedCIDRS src {}\\n'.format(cidr) sudo('sed -i "s|ALLOWED_CIDRS|{}|g" /etc/squid/squid.conf'.format(replace_string)) sudo('systemctl restart squid') sudo('chkconfig squid on') sudo('touch /tmp/http_proxy_ensured') except Exception as err: print("Failed to install and configure squid: " + str(err)) sys.exit(1)
Example #27
Source File: common_lib.py From incubator-dlab with Apache License 2.0 | 5 votes |
def ensure_step(user): try: if not exists('/home/{}/.ensure_dir/step_ensured'.format(user)): manage_pkg('-y install', 'remote', 'wget') sudo('wget https://github.com/smallstep/cli/releases/download/v0.13.3/step-cli_0.13.3_amd64.deb ' '-O /tmp/step-cli_0.13.3_amd64.deb') sudo('dpkg -i /tmp/step-cli_0.13.3_amd64.deb') sudo('touch /home/{}/.ensure_dir/step_ensured'.format(user)) except: sys.exit(1)
Example #28
Source File: common_lib.py From incubator-dlab with Apache License 2.0 | 5 votes |
def ensure_ntpd(user, edge_private_ip=''): try: if not exists('/home/{}/.ensure_dir/ntpd_ensured'.format(user)): sudo('timedatectl set-ntp no') manage_pkg('-y install', 'remote', 'ntp ntpdate') sudo('echo "tinker panic 0" >> /etc/ntp.conf') if os.environ['conf_resource'] != 'ssn' and os.environ['conf_resource'] != 'edge': sudo('echo "server {} prefer iburst" >> /etc/ntp.conf'.format(edge_private_ip)) sudo('systemctl restart ntp') sudo('systemctl enable ntp') sudo('touch /home/{}/.ensure_dir/ntpd_ensured'.format(user)) except: sys.exit(1)
Example #29
Source File: common_lib.py From incubator-dlab with Apache License 2.0 | 5 votes |
def change_pkg_repos(): if not exists('/tmp/pkg_china_ensured'): put('/root/files/sources.list', '/tmp/sources.list') sudo('mv /tmp/sources.list /etc/apt/sources.list') manage_pkg('update', 'remote', '') sudo('touch /tmp/pkg_china_ensured')
Example #30
Source File: common_lib.py From incubator-dlab with Apache License 2.0 | 5 votes |
def ensure_pkg(user, requisites='linux-headers-generic python-pip python-dev ' 'groff gcc vim less git wget sysv-rc-conf ' 'libssl-dev unattended-upgrades nmap ' 'libffi-dev unzip libxml2-dev haveged'): try: if not exists('/home/{}/.ensure_dir/pkg_upgraded'.format(user)): count = 0 check = False while not check: if count > 60: print("Repositories are not available. Please, try again later.") sys.exit(1) else: try: print("Updating repositories " "and installing requested tools: {}".format(requisites)) print("Attempt number " + str(count) + " to install requested tools. Max 60 tries.") manage_pkg('update', 'remote', '') manage_pkg('-y install', 'remote', requisites) sudo('unattended-upgrades -v') sudo( 'sed -i \'s|APT::Periodic::Unattended-Upgrade "1"|APT::Periodic::Unattended-Upgrade "0"|\' /etc/apt/apt.conf.d/20auto-upgrades') sudo('export LC_ALL=C') sudo('touch /home/{}/.ensure_dir/pkg_upgraded'.format(user)) sudo('systemctl enable haveged') sudo('systemctl start haveged') if os.environ['conf_cloud_provider'] == 'aws': manage_pkg('-y install --install-recommends', 'remote', 'linux-aws-hwe') check = True except: count += 1 time.sleep(50) except: sys.exit(1)