本文整理汇总了Python中settings.Settings.get_item方法的典型用法代码示例。如果您正苦于以下问题:Python Settings.get_item方法的具体用法?Python Settings.get_item怎么用?Python Settings.get_item使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类settings.Settings
的用法示例。
在下文中一共展示了Settings.get_item方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Vrm
# 需要导入模块: from settings import Settings [as 别名]
# 或者: from settings.Settings import get_item [as 别名]
class Vrm(object):
def __init__(self):
self.driver = None
self.is_synced = False
self.logger = Logger()
self.settings = Settings()
self.valid_driver = self.__list_valid_driver()
def __list_valid_driver(self):
return self.settings.get_item("vrm_default","valid_driver").split(",")
def init_object(self,vm_name,driver,memory=None,hd_size=None,password=None):
if driver in self.__list_valid_driver() :
self.driver = __import__("vrm.%s_driver" % driver,
fromlist="*").Driver(vm_name,memory,hd_size,password)
self.logger.success("[Vrm] Driver Object successfuly initialized for VirtualMacnine %s" % vm_name)
if self.driver.is_synced :
self.is_synced = True
return True
else :
self.logger.critical("[Vrm] Invalid or not supported Driver, %s" % driver)
return False
def register_instance(self):
if self.is_synced :
self.logger.warning("[Vrm] Instance %s already created" % self.driver.vm_name)
return False
else :
self.driver.make_server()
self.logger.success("[Vrm] Instance %s successfuly created" % self.driver.vm_name)
return True
示例2: __init__
# 需要导入模块: from settings import Settings [as 别名]
# 或者: from settings.Settings import get_item [as 别名]
def __init__(self,host=None,port=None):
set = Settings()
self.logger = Logger()
if host or port == None :
host = set.get_item('core','server_host')
port = set.get_item('core','server_port')
self.host = host
self.port = port
Pyro4.config.HMAC_KEY = set.get_item('core','hmac_phrase')
if is_ip_set(self.host):
self.daemon = VinllaDaemon(
host = self.host,
port = self.port
)
else :
self.logger.critical(
"[Server] Server can't bind to address %s, Node Manager not detect this IP belonging this Server" % self.host
)
sys.exit()
示例3: prepare_kmod
# 需要导入模块: from settings import Settings [as 别名]
# 或者: from settings.Settings import get_item [as 别名]
def prepare_kmod():
kmod_list = []
sets = Settings()
l = Logger()
for section in sets.config_parse.sections() :
try :
kmod_list.extend(
sets.get_item(section,"kmod_required").split(",")
)
except :
pass
for kmod in kmod_list :
l.info("[OperatingSystem] Succesed load kernel module %s" % kmod)
if kmod :
execute_command("modprobe %s" % kmod)
else :
pass
示例4: Driver
# 需要导入模块: from settings import Settings [as 别名]
# 或者: from settings.Settings import get_item [as 别名]
class Driver(object):
def __init__(self,name,memory=None,hd_size=None,password=None):
self.settings = Settings()
suff_name = self.settings.get_item("driver_vserver","prefix_name")
self.vm_name = suff_name+name
self.conf_base = self.settings.get_item("driver_vserver","conf_dir") + "/" + self.vm_name
self.repo_base = self.settings.get_item("driver_vserver","repo_dir")
self.buildroot = self.settings.get_item("vrm_default","buildroot")
self.ip = self.__get_ip()
self.is_synced = self.__check_vm()
if not memory :
self.memory = self.settings.get_item("resource","default_memory")
else :
self.memory = memory
if not password :
self.passwd = self.vm_name
else :
self.passwd = password
if not hd_size :
self.size = self.settings.get_item("resource","default_storage_space")
else :
self.size = hd_size
def make_server(self):
if self.__check_vm():
pass
else :
self.__create_storage()
self.__create_vm()
def destroy_server(self):
pass
def alter_attribute(self,paramater,new_value):
pass
def start_server(self):
pass
def stop_server(self):
pass
def restart_server(self):
pass
def __create_vm(self):
conf_dir = os.path.join(self.conf_base,self.vm_name)
home = os.path.join(self.repo_base, self.vm_name)
interface = "dummy0:%s/%s" % (self.ip, self.settings.get_item(
"driver_vserver","network_netmask_cidr"))
init_command = """
vserver %s build -m skeleton \
--hostname %s \
--interface %s \
--flags lock,virt_mem,virt_uptime,virt_cpu,virt_load,hide_netif\
--initstyle sysv
""" % (self.vm_name,self.vm_name,interface)
execute_command(init_command)
execute_command("rsync -arv %s /tmp/pravega/volume/%s" %
(home, self.vm_name))
execute_command("umount /tmp/pravega/volume/%s" % self.vm_name)
execute_command("rm -rf %s/*" % home)
execute_command("mount /dev/%s/%s" % (
self.settings.get_item("driver_vserver","volume_group"),
self.vm_name,
))
execute_command("mount aufs-%s" % self.vm_name)
os.mkdir(os.path.join(self.conf_base,'cgroup'))
mem = open(os.path.join(self.conf_base,'cgroup/memory.limit_in_bytes'),'w')
mem.write(""+str(self.memory)+"M\n")
mem.close()
swap = open(os.path.join(self.conf_base,'cgroup/memory.memsw.limit_in_bytes'),'w')
swap.write(""+str(int(self.memory)+2*int(self.memory))+"M\n")
swap.close()
old_password = execute_command("openssl passwd "+self.passwd+"").strip()
execute_command("chroot "+home+" /usr/sbin/usermod -p \""+old_password+"\" root")
def __create_storage(self):
com1 = "lvcreate -L %s -n %s --addtag %s %s" % (
self.size,
self.vm_name, self.vm_name,
self.settings.get_item("driver_vserver","volume_group"))
com2 = "mkfs.%s /dev/%s/%s" % (
self.settings.get_item("resource","default_storage_filesystem"),
self.settings.get_item("driver_vserver","volume_group"),
self.vm_name
)
com3 = "mkdir -p /tmp/pravega/volume/%s" % self.vm_name
com4 = "mount /dev/%s/%s /tmp/pravega/volume/%s" % (
self.settings.get_item("driver_vserver","volume_group"),
#.........这里部分代码省略.........
示例5: __init__
# 需要导入模块: from settings import Settings [as 别名]
# 或者: from settings.Settings import get_item [as 别名]
def __init__(self):
sets = Settings()
logging.basicConfig(
filename=PROJECT_ROOT+"/"+sets.get_item('core','log_file'),
format="%(asctime)s %(message)s",
level=logging.DEBUG)