本文整理汇总了Python中sss.core.logging.Log.info方法的典型用法代码示例。如果您正苦于以下问题:Python Log.info方法的具体用法?Python Log.info怎么用?Python Log.info使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sss.core.logging.Log
的用法示例。
在下文中一共展示了Log.info方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: remove
# 需要导入模块: from sss.core.logging import Log [as 别名]
# 或者: from sss.core.logging.Log import info [as 别名]
def remove(self, packages, auto=False, purge=False):
all_packages = " ".join(packages)
try:
with open("/var/log/sss/sss.log", "a") as f:
if purge:
proc = subprocess.Popen(
"apt-get purge -y {0}".format(all_packages),
shell=True,
stdin=None,
stdout=f,
stderr=f,
executable="/bin/bash",
)
else:
proc = subprocess.Popen(
"apt-get remove -y {0}".format(all_packages),
shell=True,
stdin=None,
stdout=f,
stderr=f,
executable="/bin/bash",
)
proc.wait()
if proc.returncode == 0:
return True
else:
Log.info(self, Log.FAIL + "Oops Something went " "wrong!!")
Log.error(self, "Check logs for reason " "`tail /var/log/sss/sss.log` & Try Again!!!")
except Exception as e:
Log.error(self, "Error while installing packages, " "apt-get exited with error")
示例2: dist_upgrade
# 需要导入模块: from sss.core.logging import Log [as 别名]
# 或者: from sss.core.logging.Log import info [as 别名]
def dist_upgrade(self):
"""
Similar to `apt-get upgrade`
"""
try:
with open("/var/log/sss/sss.log", "a") as f:
proc = subprocess.Popen(
"DEBIAN_FRONTEND=noninteractive "
"apt-get dist-upgrade -o "
'Dpkg::Options::="--force-confdef"'
" -o "
'Dpkg::Options::="--force-confold"'
" -y ",
shell=True,
stdin=None,
stdout=f,
stderr=f,
executable="/bin/bash",
)
proc.wait()
if proc.returncode == 0:
return True
else:
Log.info(self, Log.FAIL + "Oops Something went " "wrong!!")
Log.error(self, "Check logs for reason " "`tail /var/log/ss/ss.log` & Try Again!!!")
except Exception as e:
Log.error(self, "Error while installing packages, " "apt-get exited with error")
示例3: download
# 需要导入模块: from sss.core.logging import Log [as 别名]
# 或者: from sss.core.logging.Log import info [as 别名]
def download(self, packages):
"""Download packages, packges must be list in format of
[url, path, package name]"""
for package in packages:
url = package[0]
filename = package[1]
pkg_name = package[2]
try:
directory = os.path.dirname(filename)
if not os.path.exists(directory):
os.makedirs(directory)
Log.info(self, "Downloading {0:20}".format(pkg_name), end=' ')
urllib.request.urlretrieve(url, filename)
Log.info(self, "{0}".format("[" + Log.ENDC + "Done"
+ Log.OKGREEN + "]"))
except urllib.error.URLError as e:
Log.debug(self, "[{err}]".format(err=str(e.reason)))
Log.error(self, "Unable to download file, {0}"
.format(filename))
return False
except urllib.error.HTTPError as e:
Log.error(self, "Package download failed. {0}"
.format(pkg_name))
Log.debug(self, "[{err}]".format(err=str(e.reason)))
return False
except urllib.error.ContentTooShortError as e:
Log.debug(self, "{0}{1}".format(e.errno, e.strerror))
Log.error(self, "Package download failed. The amount of the"
" downloaded data is less than "
"the expected amount \{0} ".format(pkg_name))
return False
示例4: install
# 需要导入模块: from sss.core.logging import Log [as 别名]
# 或者: from sss.core.logging.Log import info [as 别名]
def install(self, packages):
all_packages = " ".join(packages)
try:
with open("/var/log/sss/sss.log", "a") as f:
proc = subprocess.Popen(
"DEBIAN_FRONTEND=noninteractive "
"apt-get install -o "
'Dpkg::Options::="--force-confdef"'
" -o "
'Dpkg::Options::="--force-confold"'
" -y {0}".format(all_packages),
shell=True,
stdin=None,
stdout=f,
stderr=f,
executable="/bin/bash",
)
proc.wait()
if proc.returncode == 0:
return True
else:
Log.info(self, Log.FAIL + "Oops Something went " "wrong!!")
Log.error(self, "Check logs for reason " "`tail /var/log/sss/sss.log` & Try Again!!!")
except Exception as e:
Log.info(self, Log.FAIL + "Oops Something went " "wrong!!")
Log.error(self, "Check logs for reason " "`tail /var/log/sss/sss.log` & Try Again!!!")
示例5: add
# 需要导入模块: from sss.core.logging import Log [as 别名]
# 或者: from sss.core.logging.Log import info [as 别名]
def add(self):
"""Swap addition with SimpleSetupServer"""
if SSSVariables.sss_ram < 512:
if SSSVariables.sss_swap < 1000:
Log.info(self, "Adding SWAP file, please wait...")
# Install dphys-swapfile
SSSAptGet.update(self)
SSSAptGet.install(self, ["dphys-swapfile"])
# Stop service
SSSShellExec.cmd_exec(self, "service dphys-swapfile stop")
# Remove Default swap created
SSSShellExec.cmd_exec(self, "/sbin/dphys-swapfile uninstall")
# Modify Swap configuration
if os.path.isfile("/etc/dphys-swapfile"):
SSSFileUtils.searchreplace(self, "/etc/dphys-swapfile",
"#CONF_SWAPFILE=/var/swap",
"CONF_SWAPFILE=/sss-swapfile")
SSSFileUtils.searchreplace(self, "/etc/dphys-swapfile",
"#CONF_MAXSWAP=2048",
"CONF_MAXSWAP=1024")
SSSFileUtils.searchreplace(self, "/etc/dphys-swapfile",
"#CONF_SWAPSIZE=",
"CONF_SWAPSIZE=1024")
else:
with open("/etc/dphys-swapfile", 'w') as conffile:
conffile.write("CONF_SWAPFILE=/sss-swapfile\n"
"CONF_SWAPSIZE=1024\n"
"CONF_MAXSWAP=1024\n")
# Create swap file
SSSShellExec.cmd_exec(self, "service dphys-swapfile start")
示例6: remove
# 需要导入模块: from sss.core.logging import Log [as 别名]
# 或者: from sss.core.logging.Log import info [as 别名]
def remove(self):
"""Start removal of packages"""
apt_packages = []
packages = []
# Default action for stack remove
if ((not self.app.pargs.web) and (not self.app.pargs.apache2) and
(not self.app.pargs.php) and (not self.app.pargs.mysql)):
self.app.pargs.web = True
self.app.pargs.apache2 = True
self.app.pargs.php = True
self.app.pargs.mysql = True
if self.app.pargs.all:
self.app.pargs.web = True
self.app.pargs.apache2 = True
self.app.pargs.php = True
self.app.pargs.mysql = True
if self.app.pargs.web:
self.app.pargs.apache2 = True
self.app.pargs.php = True
self.app.pargs.mysql = True
#self.app.pargs.wpcli = True
#self.app.pargs.postfix = True
if self.app.pargs.apache2:
Log.debug(self,"Removing apt_packages variable of Apache")
apt_packages = apt_packages + SSSVariables.sss_apache
if self.app.pargs.php:
Log.debug(self,"Removing apt_packages variable of PHP")
apt_packages = apt_packages + SSSVariables.sss_php
if self.app.pargs.mysql:
Log.debug(self,"Removing apt_packages variable of PHP")
apt_packages = apt_packages + SSSVariables.sss_mysql
packages = packages + ['/usr/bin/tuning-primer']
if len(packages) or len(apt_packages):
sss_prompt = input('Are you sure you to want to'
' remove from server.'
'\nPackage configuration will remain'
' on server after this operation.\n'
'Any answer other than '
'"yes" will be stop this'
' operation : ')
if sss_prompt == 'YES' or sss_prompt == 'yes':
if len(packages):
SSSFileUtils.remove(self, packages)
SSSAptGet.auto_remove(self)
if len(apt_packages):
Log.debug(self, "Removing apt_packages")
Log.info(self, "Removing packages, please wait...")
SSSAptGet.remove(self, apt_packages)
SSSAptGet.auto_remove(self)
Log.info(self, "Successfully removed packages")
示例7: callback
# 需要导入模块: from sss.core.logging import Log [as 别名]
# 或者: from sss.core.logging.Log import info [as 别名]
def callback(filename, lines):
for line in lines:
if line.find(":::") == -1:
print(line)
else:
data = line.split(":::")
try:
print(data[0], data[1], zlib.decompress(base64.decodestring(data[2])))
except Exception as e:
Log.info(time.time(), "caught exception rendering a new log line in %s" % filename)
示例8: pre_run_checks
# 需要导入模块: from sss.core.logging import Log [as 别名]
# 或者: from sss.core.logging.Log import info [as 别名]
def pre_run_checks(self):
# Check Apache configuration
Log.info(self, "Running pre-update checks, please wait...")
try:
Log.debug(self, "checking Apache configuration ...")
FNULL = open("/dev/null", "w")
ret = subprocess.check_call(["apachectl", "configtest"], stdout=FNULL, stderr=subprocess.STDOUT)
except CalledProcessError as e:
Log.debug(self, "{0}".format(str(e)))
raise SiteError("Apache configuration check failed.")
示例9: default
# 需要导入模块: from sss.core.logging import Log [as 别名]
# 或者: from sss.core.logging.Log import info [as 别名]
def default(self):
if not self.app.pargs.mariadb:
self.app.args.print_help()
if self.app.pargs.mariadb:
if SSSVariables.sss_mysql_host is not "localhost":
Log.error(self, "Remote MySQL found, EasyEngine will not " "install MariaDB")
if SSSShellExec.cmd_exec(self, "mysqladmin ping") and (not SSSAptGet.is_installed(self, "mariadb-server")):
Log.info(self, "If your database size is big, " "migration may take some time.")
Log.info(self, "During migration non Apache parts of " "your site may remain down")
start_migrate = input('Type "mariadb" to continue:')
if start_migrate != "mariadb":
Log.error(self, "Not starting migration")
self.migrate_mariadb()
else:
Log.error(self, "Your current MySQL is not alive or " "you allready installed MariaDB")
示例10: check_upgrade
# 需要导入模块: from sss.core.logging import Log [as 别名]
# 或者: from sss.core.logging.Log import info [as 别名]
def check_upgrade(self):
"""
Similar to `apt-get upgrade`
"""
try:
check_update = subprocess.Popen(
["apt-get upgrade -s | grep " '"^Inst" | wc -l'], stdout=subprocess.PIPE, shell=True
).communicate()[0]
if check_update == b"0\n":
Log.error(self, "No package updates available")
Log.info(self, "Following package updates are available:")
subprocess.Popen(
'apt-get -s dist-upgrade | grep "^Inst"', shell=True, executable="/bin/bash", stdout=sys.stdout
).communicate()
except Exception as e:
Log.error(self, "Unable to check for packages upgrades")
示例11: status
# 需要导入模块: from sss.core.logging import Log [as 别名]
# 或者: from sss.core.logging.Log import info [as 别名]
def status(self):
"""Status of services"""
services = []
if not (self.app.pargs.apache2 or self.app.pargs.php
or self.app.pargs.mysql or self.app.pargs.memcache):
self.app.pargs.apache2 = True
self.app.pargs.php = True
self.app.pargs.mysql = True
if self.app.pargs.apache2:
if SSSAptGet.is_installed(self,'apache2'):
services = services + ['apache2']
else:
Log.info(self,"Apache is not installed")
if self.app.pargs.php:
if SSSAptGet.is_installed(self, 'php7.0-fpm'):
services = services + ['php7.0-fpm']
else:
Log.info(self, "PHP7-FPM is not installed")
if self.app.pargs.mysql:
if ((SSSVariables.sss_mysql_host is "localhost") or
(SSSVariables.sss_mysql_host is "127.0.0.1")):
if (SSSAptGet.is_installed(self, 'mysql-server') or
SSSAptGet.is_installed(self, 'percona-server-server-5.6') or
SSSAptGet.is_installed(self, 'mariadb-server')):
services = services + ['mysql']
else:
Log.info(self, "MySQL is not installed")
else:
Log.warn(self, "Remote MySQL found, "
"Unable to check MySQL service status")
if self.app.pargs.memcache:
if SSSAptGet.is_installed(self, 'memcached'):
services = services + ['memcached']
else:
Log.info(self, "Memcache is not installed")
for service in services:
if SSSService.get_service_status(self, service):
Log.info(self, "{0:10}: {1}".format(service, "Running"))
示例12: reload_service
# 需要导入模块: from sss.core.logging import Log [as 别名]
# 或者: from sss.core.logging.Log import info [as 别名]
def reload_service(self, service_name):
"""
Stop service
Similar to `service xyz stop`
"""
try:
if service_name in ['php5-fpm']:
service_cmd = ('{0} -t && service {0} reload'
.format(service_name))
else:
service_cmd = ('service {0} reload'.format(service_name))
Log.info(self, "Reload : {0:10}".format(service_name), end='')
retcode = subprocess.getstatusoutput(service_cmd)
if retcode[0] == 0:
Log.info(self, "[" + Log.ENDC + "OK" + Log.OKGREEN + "]")
return True
else:
Log.debug(self, "{0}".format(retcode[1]))
Log.info(self, "[" + Log.FAIL + "Failed" + Log.OKGREEN+"]")
return False
except OSError as e:
Log.debug(self, "{0}".format(e))
Log.error(self, "\nFailed to reload service {0}"
.format(service_name))
示例13: deleteDB
# 需要导入模块: from sss.core.logging import Log [as 别名]
# 或者: from sss.core.logging.Log import info [as 别名]
def deleteDB(self, dbname, dbuser, dbhost, exit=True):
try:
# Check if Database exists
try:
if SSSMysql.check_db_exists(self, dbname):
# Drop database if exists
Log.debug(self, "dropping database `{0}`".format(dbname))
SSSMysql.execute(self,
"drop database `{0}`".format(dbname),
errormsg='Unable to drop database {0}'
.format(dbname))
except StatementExcecutionError as e:
Log.debug(self, "drop database failed")
Log.info(self, "Database {0} not dropped".format(dbname))
except MySQLConnectionError as e:
Log.debug(self, "Mysql Connection problem occured")
if dbuser != 'root':
Log.debug(self, "dropping user `{0}`".format(dbuser))
try:
SSSMysql.execute(self,
"drop user `{0}`@`{1}`"
.format(dbuser, dbhost))
except StatementExcecutionError as e:
Log.debug(self, "drop database user failed")
Log.info(self, "Database {0} not dropped".format(dbuser))
try:
SSSMysql.execute(self, "flush privileges")
except StatementExcecutionError as e:
Log.debug(self, "drop database failed")
Log.info(self, "Database {0} not dropped".format(dbname))
except Exception as e:
Log.error(self, "Error occured while deleting database", exit)
示例14: backupAll
# 需要导入模块: from sss.core.logging import Log [as 别名]
# 或者: from sss.core.logging.Log import info [as 别名]
def backupAll(self):
import subprocess
try:
Log.info(self, "Backing up database at location: "
"/var/sss-mysqlbackup")
# Setup MySql backup directory
if not os.path.exists('/var/sss-mysqlbackup'):
Log.debug(self, 'Creating directory'
'/var/sss-mysqlbackup')
os.makedirs('/var/sss-mysqlbackup')
db = subprocess.check_output(["mysql -Bse \'show databases\'"],
universal_newlines=True,
shell=True).split('\n')
for dbs in db:
if dbs == "":
continue
Log.info(self, "Backing up {0} database".format(dbs))
p1 = subprocess.Popen("mysqldump {0}"
" --max_allowed_packet=1024M"
" --single-transaction".format(dbs),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE, shell=True)
p2 = subprocess.Popen("gzip -c > /var/sss-mysqlbackup/{0}{1}.s"
"ql.gz".format(dbs, SSSVariables.sss_date),
stdin=p1.stdout,
shell=True)
# Allow p1 to receive a SIGPIPE if p2 exits
p1.stdout.close()
output = p1.stderr.read()
p1.wait()
if p1.returncode == 0:
Log.debug(self, "done")
else:
Log.error(self, output.decode("utf-8"))
except Exception as e:
Log.error(self, "Error: process exited with status %s"
% e)
示例15: update
# 需要导入模块: from sss.core.logging import Log [as 别名]
# 或者: from sss.core.logging.Log import info [as 别名]
def update(self):
"""
Similar to `apt-get update`
"""
try:
with open("/var/log/sss/sss.log", "a") as f:
proc = subprocess.Popen(
"apt-get update", shell=True, stdin=None, stdout=f, stderr=subprocess.PIPE, executable="/bin/bash"
)
proc.wait()
output, error_output = proc.communicate()
# Check what is error in error_output
if "NO_PUBKEY" in str(error_output):
# Split the output
Log.info(self, "Fixing missing GPG keys, please wait...")
error_list = str(error_output).split("\\n")
# Use a loop to add misising keys
for single_error in error_list:
if "NO_PUBKEY" in single_error:
key = single_error.rsplit(None, 1)[-1]
SSSRepo.add_key(self, key, keyserver="hkp://pgp.mit.edu")
proc = subprocess.Popen(
"apt-get update", shell=True, stdin=None, stdout=f, stderr=f, executable="/bin/bash"
)
proc.wait()
if proc.returncode == 0:
return True
else:
Log.info(self, Log.FAIL + "Oops Something went wrong!!")
Log.error(self, "Check logs for reason " "`tail /var/log/sss/sss.log` & Try Again!!!")
except Exception as e:
Log.error(self, "apt-get update exited with error")