Added and using new get_bool_option and get_int_option functions
This commit is contained in:
@@ -24,8 +24,6 @@ import re
|
||||
# This one keeps comments but has some weirdness with it
|
||||
import iniparse
|
||||
|
||||
import yaml
|
||||
|
||||
from anvil import env
|
||||
from anvil import exceptions as excp
|
||||
from anvil import log as logging
|
||||
@@ -220,7 +218,7 @@ class YamlInterpolator(object):
|
||||
if not sh.isfile(pth):
|
||||
self.included[root] = {}
|
||||
return
|
||||
self.included[root] = yaml.load(sh.load_file(pth))
|
||||
self.included[root] = utils.load_yaml(pth)
|
||||
self.included[root] = self._do_include(self.included[root])
|
||||
|
||||
def extract(self, root):
|
||||
|
||||
@@ -71,6 +71,12 @@ class Component(object):
|
||||
else:
|
||||
return option_value
|
||||
|
||||
def get_bool_option(self, option, default_value=False):
|
||||
return utils.make_bool(self.get_option(option, default_value))
|
||||
|
||||
def get_int_option(self, option, default_value=0):
|
||||
return int(self.get_option(option, default_value))
|
||||
|
||||
@property
|
||||
def env_exports(self):
|
||||
return {}
|
||||
@@ -106,5 +112,5 @@ class Component(object):
|
||||
def warm_configs(self):
|
||||
# Before any actions occur you get the chance to
|
||||
# warmup the configs u might use (ie for prompting for passwords
|
||||
# earlier rather than later
|
||||
# earlier rather than later)
|
||||
pass
|
||||
|
||||
@@ -31,12 +31,6 @@ LOG = logging.getLogger(__name__)
|
||||
# always reset it when u uninstall the db
|
||||
RESET_BASE_PW = ''
|
||||
|
||||
# Links about how to reset if we fail to set the PW
|
||||
SQL_RESET_PW_LINKS = [
|
||||
'https://help.ubuntu.com/community/MysqlPasswordReset',
|
||||
'http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html',
|
||||
]
|
||||
|
||||
# Copies from helper
|
||||
BASE_ERROR = dbhelper.BASE_ERROR
|
||||
|
||||
@@ -71,8 +65,6 @@ class DBUninstaller(comp.PkgUninstallComponent):
|
||||
except IOError:
|
||||
LOG.warn(("Could not reset the database password. You might have to manually "
|
||||
"reset the password to %s before the next install"), colorizer.quote(RESET_BASE_PW))
|
||||
utils.log_iterable(SQL_RESET_PW_LINKS, logger=LOG,
|
||||
header="To aid in this check out:")
|
||||
|
||||
|
||||
class DBInstaller(comp.PkgInstallComponent):
|
||||
@@ -143,7 +135,7 @@ class DBInstaller(comp.PkgInstallComponent):
|
||||
class DBRuntime(comp.ProgramRuntime):
|
||||
def __init__(self, *args, **kargs):
|
||||
comp.ProgramRuntime.__init__(self, *args, **kargs)
|
||||
self.wait_time = max(int(self.get_option('service_wait_seconds')), 1)
|
||||
self.wait_time = self.get_int_option('service_wait_seconds')
|
||||
|
||||
def _get_run_actions(self, act, exception_cls):
|
||||
db_type = self.get_option("type")
|
||||
|
||||
@@ -208,7 +208,7 @@ class GlanceRuntime(GlanceMixin, comp.PythonRuntime):
|
||||
def __init__(self, *args, **kargs):
|
||||
comp.PythonRuntime.__init__(self, *args, **kargs)
|
||||
self.bin_dir = sh.joinpths(self.get_option('app_dir'), 'bin')
|
||||
self.wait_time = max(int(self.get_option('service_wait_seconds')), 1)
|
||||
self.wait_time = self.get_int_option('service_wait_seconds')
|
||||
|
||||
@property
|
||||
def apps_to_start(self):
|
||||
|
||||
@@ -40,30 +40,30 @@ API_CONF = 'nova.conf'
|
||||
# This db will be dropped then created
|
||||
DB_NAME = 'nova'
|
||||
|
||||
# Network class/driver/manager templs
|
||||
|
||||
# Default virt types
|
||||
DEF_VIRT_DRIVER = 'libvirt'
|
||||
|
||||
# Virt drivers map -> to there connection name
|
||||
VIRT_DRIVER_CON_MAP = {
|
||||
'libvirt': 'libvirt',
|
||||
'xen', 'xen',
|
||||
'xenserver', 'xen',
|
||||
}
|
||||
|
||||
# Message queue types to there internal 'canoncalized' name
|
||||
MQ_TYPES = {
|
||||
'qpid': 'qpid',
|
||||
'qpidd': 'qpid',
|
||||
'rabbit': 'rabbit',
|
||||
'rabbit-mq': 'rabbit',
|
||||
}
|
||||
|
||||
|
||||
def canon_mq_type(mq_type):
|
||||
if not mq_type:
|
||||
return ''
|
||||
return str(mq_type).lower().strip()
|
||||
mq_type = str(mq_type).lower().strip()
|
||||
return MQ_TYPES.get(mq_type, 'rabbit')
|
||||
|
||||
|
||||
def canon_virt_driver(virt_driver):
|
||||
if not virt_driver:
|
||||
return DEF_VIRT_DRIVER
|
||||
virt_driver = virt_driver.strip().lower()
|
||||
if not (virt_driver in VIRT_DRIVER_CON_MAP):
|
||||
return DEF_VIRT_DRIVER
|
||||
return virt_driver
|
||||
virt_driver = str(virt_driver).strip().lower()
|
||||
return VIRT_DRIVER_CON_MAP.get(virt_driver, 'libvirt')
|
||||
|
||||
|
||||
def get_shared_params(ip, protocol,
|
||||
@@ -121,16 +121,10 @@ class ConfConfigurator(object):
|
||||
def __init__(self, installer):
|
||||
self.installer = weakref.proxy(installer)
|
||||
|
||||
def _getbool(self, name):
|
||||
return bool(self.installer.get_option(name))
|
||||
|
||||
def _getstr(self, name, default=''):
|
||||
return str(self.installer.get_option(name, default))
|
||||
|
||||
def verify(self):
|
||||
# Do a little check to make sure actually have that interface/s
|
||||
public_interface = self._getstr('public_interface')
|
||||
vlan_interface = self._getstr('vlan_interface', public_interface)
|
||||
public_interface = self.installer.get_option('public_interface')
|
||||
vlan_interface = self.installer.get_option('vlan_interface', public_interface)
|
||||
known_interfaces = utils.get_interfaces()
|
||||
if not public_interface in known_interfaces:
|
||||
msg = "Public interface %r is not a known interface (is it one of %s??)" % (public_interface, ", ".join(known_interfaces))
|
||||
@@ -139,16 +133,12 @@ class ConfConfigurator(object):
|
||||
msg = "VLAN interface %r is not a known interface (is it one of %s??)" % (vlan_interface, ", ".join(known_interfaces))
|
||||
raise exceptions.ConfigException(msg)
|
||||
# Driver specific interface checks
|
||||
drive_canon = canon_virt_driver(self._getstr('virt_driver'))
|
||||
drive_canon = canon_virt_driver(self.installer.get_option('virt_driver'))
|
||||
if drive_canon == 'libvirt':
|
||||
flat_interface = self._getstr('flat_interface')
|
||||
flat_interface = self.installer.get_option('flat_interface')
|
||||
if flat_interface and not flat_interface in known_interfaces:
|
||||
msg = "Libvirt flat interface %s is not a known interface (is it one of %s??)" % (flat_interface, ", ".join(known_interfaces))
|
||||
raise exceptions.ConfigException(msg)
|
||||
mq_type = canon_mq_type(self.installer.get_option('mq'))
|
||||
if mq_type not in ['rabbit']:
|
||||
msg = "Unknown message queue type %s (is it one of %s??)" % (mq_type, ", ".join(['rabbit']))
|
||||
raise exceptions.ConfigException(msg)
|
||||
|
||||
def generate(self, fn):
|
||||
|
||||
@@ -156,19 +146,19 @@ class ConfConfigurator(object):
|
||||
nova_conf = Conf(fn)
|
||||
|
||||
# Used more than once so we calculate it ahead of time
|
||||
hostip = self._getstr('ip')
|
||||
hostip = self.installer.get_option('ip')
|
||||
|
||||
if self._getbool('verbose'):
|
||||
nova_conf.add('verbose', True)
|
||||
nova_conf.add('verbose', self.installer.get_bool_option('verbose'))
|
||||
|
||||
# Allow destination machine to match source for resize.
|
||||
nova_conf.add('allow_resize_to_same_host', True)
|
||||
|
||||
# Which scheduler do u want?
|
||||
nova_conf.add('compute_scheduler_driver', self._getstr('scheduler', 'nova.scheduler.filter_scheduler.FilterScheduler'))
|
||||
nova_conf.add('compute_scheduler_driver',
|
||||
self.installer.get_option('scheduler', 'nova.scheduler.filter_scheduler.FilterScheduler'))
|
||||
|
||||
# Rate limit the api??
|
||||
nova_conf.add('api_rate_limit', self._getbool('api_rate_limit'))
|
||||
nova_conf.add('api_rate_limit', self.installer.get_bool_option('api_rate_limit'))
|
||||
|
||||
# Setup nova network/settings
|
||||
self._configure_network_settings(nova_conf)
|
||||
@@ -182,7 +172,7 @@ class ConfConfigurator(object):
|
||||
|
||||
dbdsn = dbhelper.fetch_dbdsn(dbname=DB_NAME,
|
||||
utf8=True,
|
||||
dbtype=self._getstr('db.type'),
|
||||
dbtype=self.installer.get_option('db.type'),
|
||||
**utils.merge_dicts(self.installer.get_option('db'),
|
||||
dbhelper.get_shared_passwords(self.installer)))
|
||||
|
||||
@@ -190,12 +180,13 @@ class ConfConfigurator(object):
|
||||
nova_conf.add('sql_connection', dbdsn)
|
||||
|
||||
# Configure anything libvirt related?
|
||||
virt_driver = canon_virt_driver(self._getstr('virt_driver'))
|
||||
virt_driver = canon_virt_driver(self.installer.get_option('virt_driver'))
|
||||
if virt_driver == 'libvirt':
|
||||
self._configure_libvirt(lv.canon_libvirt_type(self._getstr('libvirt_type')), nova_conf)
|
||||
self._configure_libvirt(lv.canon_libvirt_type(self.installer.get_option('libvirt_type')), nova_conf)
|
||||
|
||||
# How instances will be presented
|
||||
instance_template = self._getstr('instance_name_prefix') + self._getstr('instance_name_postfix')
|
||||
instance_template = "%s%s" % (self.installer.get_option('instance_name_prefix'),
|
||||
self.installer.get_option('instance_name_postfix'))
|
||||
if not instance_template:
|
||||
instance_template = 'instance-%08x'
|
||||
nova_conf.add('instance_name_template', instance_template)
|
||||
@@ -208,10 +199,10 @@ class ConfConfigurator(object):
|
||||
nova_conf.add('auth_strategy', 'keystone')
|
||||
|
||||
# Don't always force images to raw
|
||||
nova_conf.add('force_raw_images', self._getbool('force_raw_images'))
|
||||
nova_conf.add('force_raw_images', self.installer.get_bool_option('force_raw_images'))
|
||||
|
||||
# Add a checksum for images fetched to a hypervisor
|
||||
nova_conf.add('checksum_base_images', self._getbool('checksum_base_images'))
|
||||
nova_conf.add('checksum_base_images', self.installer.get_bool_option('checksum_base_images'))
|
||||
|
||||
# Vnc settings setup
|
||||
self._configure_vnc(nova_conf)
|
||||
@@ -224,19 +215,19 @@ class ConfConfigurator(object):
|
||||
self._configure_image_service(nova_conf, hostip)
|
||||
|
||||
# Configs for ec2 / s3 stuff
|
||||
nova_conf.add('ec2_dmz_host', self._getstr('ec2_dmz_host', hostip))
|
||||
nova_conf.add('ec2_dmz_host', self.installer.get_option('ec2_dmz_host', hostip))
|
||||
nova_conf.add('s3_host', hostip)
|
||||
|
||||
# How is your message queue setup?
|
||||
mq_type = canon_mq_type(self._getstr('mq'))
|
||||
mq_type = canon_mq_type(self.installer.get_option('mq'))
|
||||
if mq_type == 'rabbit':
|
||||
nova_conf.add('rabbit_host', self._getstr('rabbit.host', hostip))
|
||||
nova_conf.add('rabbit_host', self.installer.get_option('rabbit.host', hostip))
|
||||
nova_conf.add('rabbit_password', rbhelper.get_shared_passwords(self.installer)['pw'])
|
||||
nova_conf.add('rabbit_userid', self._getstr('rabbit.user_id'))
|
||||
nova_conf.add('rabbit_userid', self.installer.get_option('rabbit.user_id'))
|
||||
nova_conf.add('rpc_backend', 'nova.rpc.impl_kombu')
|
||||
|
||||
# Where instances will be stored
|
||||
instances_path = self._getstr('instances_path')
|
||||
instances_path = self.installer.get_option('instances_path')
|
||||
if not instances_path:
|
||||
instances_path = sh.joinpths(self.installer.get_option('component_dir'), 'instances')
|
||||
self._configure_instances_path(instances_path, nova_conf)
|
||||
@@ -251,7 +242,7 @@ class ConfConfigurator(object):
|
||||
return self._get_content(nova_conf)
|
||||
|
||||
def _get_extra(self, key):
|
||||
extras = self._getstr(key)
|
||||
extras = self.installer.get_option(key)
|
||||
cleaned_lines = list()
|
||||
extra_lines = extras.splitlines()
|
||||
for line in extra_lines:
|
||||
@@ -295,26 +286,26 @@ class ConfConfigurator(object):
|
||||
|
||||
def _configure_image_service(self, nova_conf, hostip):
|
||||
# What image service we will u be using sir?
|
||||
img_service = self._getstr('img_service', 'nova.image.glance.GlanceImageService')
|
||||
img_service = self.installer.get_option('img_service', 'nova.image.glance.GlanceImageService')
|
||||
nova_conf.add('image_service', img_service)
|
||||
|
||||
# If glance then where is it?
|
||||
if img_service.lower().find("glance") != -1:
|
||||
glance_api_server = self._getstr('glance_server', ("%s:9292" % (hostip)))
|
||||
glance_api_server = self.installer.get_option('glance_server', ("%s:9292" % (hostip)))
|
||||
nova_conf.add('glance_api_servers', glance_api_server)
|
||||
|
||||
def _configure_vnc(self, nova_conf):
|
||||
# All nova-compute workers need to know the vnc configuration options
|
||||
# These settings don't hurt anything if n-xvnc and n-novnc are disabled
|
||||
nova_conf.add('novncproxy_base_url', self._getstr('vncproxy_url'))
|
||||
nova_conf.add('xvpvncproxy_base_url', self._getstr('xvpvncproxy_url'))
|
||||
nova_conf.add('vncserver_listen', self._getstr('vncserver_listen', '127.0.0.1'))
|
||||
nova_conf.add('vncserver_proxyclient_address', self._getstr('vncserver_proxyclient_address', '127.0.0.1'))
|
||||
nova_conf.add('novncproxy_base_url', self.installer.get_option('vncproxy_url'))
|
||||
nova_conf.add('xvpvncproxy_base_url', self.installer.get_option('xvpvncproxy_url'))
|
||||
nova_conf.add('vncserver_listen', self.installer.get_option('vncserver_listen', '127.0.0.1'))
|
||||
nova_conf.add('vncserver_proxyclient_address', self.installer.get_option('vncserver_proxyclient_address', '127.0.0.1'))
|
||||
|
||||
# Fixes up your nova volumes
|
||||
def _configure_vols(self, nova_conf):
|
||||
nova_conf.add('volume_group', self._getstr('volume_group'))
|
||||
vol_name_tpl = self._getstr('volume_name_prefix') + self._getstr('volume_name_postfix')
|
||||
nova_conf.add('volume_group', self.installer.get_option('volume_group'))
|
||||
vol_name_tpl = self.installer.get_option('volume_name_prefix') + self.installer.get_option('volume_name_postfix')
|
||||
if not vol_name_tpl:
|
||||
vol_name_tpl = 'volume-%08x'
|
||||
nova_conf.add('volume_name_template', vol_name_tpl)
|
||||
@@ -328,19 +319,19 @@ class ConfConfigurator(object):
|
||||
if self.installer.get_option('quantum-enabled'):
|
||||
self._configure_quantum(nova_conf)
|
||||
else:
|
||||
nova_conf.add('network_manager', self._getstr('network_manager'))
|
||||
nova_conf.add('network_manager', self.installer.get_option('network_manager'))
|
||||
|
||||
# Configs dhcp bridge stuff???
|
||||
# TODO(harlowja) why is this the same as the nova.conf?
|
||||
nova_conf.add('dhcpbridge_flagfile', sh.joinpths(self.installer.get_option('cfg_dir'), API_CONF))
|
||||
|
||||
# Network prefix for the IP network that all the projects for future VM guests reside on. Example: 192.168.0.0/12
|
||||
nova_conf.add('fixed_range', self._getstr('fixed_range'))
|
||||
nova_conf.add('fixed_range', self.installer.get_option('fixed_range'))
|
||||
|
||||
# The value for vlan_interface may default to the the current value
|
||||
# of public_interface. We'll grab the value and keep it handy.
|
||||
public_interface = self._getstr('public_interface')
|
||||
vlan_interface = self._getstr('vlan_interface', public_interface)
|
||||
public_interface = self.installer.get_option('public_interface')
|
||||
vlan_interface = self.installer.get_option('vlan_interface', public_interface)
|
||||
nova_conf.add('public_interface', public_interface)
|
||||
nova_conf.add('vlan_interface', vlan_interface)
|
||||
|
||||
@@ -348,15 +339,15 @@ class ConfConfigurator(object):
|
||||
nova_conf.add('force_dhcp_release', True)
|
||||
|
||||
# Special virt driver network settings
|
||||
nova_conf.add('flat_network_bridge', self._getstr('flat_network_bridge', 'br100'))
|
||||
nova_conf.add('flat_injected', self._getbool('flat_injected'))
|
||||
flat_interface = self._getstr('flat_interface')
|
||||
nova_conf.add('flat_network_bridge', self.installer.get_option('flat_network_bridge', 'br100'))
|
||||
nova_conf.add('flat_injected', self.installer.get_bool_option('flat_injected'))
|
||||
flat_interface = self.installer.get_option('flat_interface')
|
||||
if flat_interface:
|
||||
nova_conf.add('flat_interface', flat_interface)
|
||||
|
||||
# Enables multihost (??)
|
||||
def _configure_multihost(self, nova_conf):
|
||||
if self._getbool('multi_host'):
|
||||
if self.installer.get_bool_option('multi_host'):
|
||||
nova_conf.add('multi_host', True)
|
||||
nova_conf.add('send_arp_for_ha', True)
|
||||
|
||||
@@ -378,12 +369,12 @@ class ConfConfigurator(object):
|
||||
|
||||
# Configures any virt driver settings
|
||||
def _configure_virt_driver(self, nova_conf):
|
||||
drive_canon = canon_virt_driver(self._getstr('virt_driver'))
|
||||
drive_canon = canon_virt_driver(self.installer.get_option('virt_driver'))
|
||||
nova_conf.add('connection_type', VIRT_DRIVER_CON_MAP.get(drive_canon, drive_canon))
|
||||
if drive_canon == 'libvirt':
|
||||
nova_conf.add('firewall_driver', self._getstr('libvirt_firewall_driver'))
|
||||
nova_conf.add('firewall_driver', self.installer.get_option('libvirt_firewall_driver'))
|
||||
else:
|
||||
nova_conf.add('firewall_driver', self._getstr('basic_firewall_driver'))
|
||||
nova_conf.add('firewall_driver', self.installer.get_option('basic_firewall_driver'))
|
||||
|
||||
|
||||
# This class represents the data/format of the nova config file
|
||||
|
||||
@@ -43,20 +43,15 @@ DEF_VIRT_TYPE = 'qemu'
|
||||
|
||||
|
||||
def canon_libvirt_type(virt_type):
|
||||
if not virt_type:
|
||||
return DEF_VIRT_TYPE
|
||||
virt_type = virt_type.lower().strip()
|
||||
if not (virt_type in LIBVIRT_PROTOCOL_MAP):
|
||||
return DEF_VIRT_TYPE
|
||||
else:
|
||||
return virt_type
|
||||
virt_type = str(virt_type).lower().strip()
|
||||
return LIBVIRT_PROTOCOL_MAP.get(virt_type, DEF_VIRT_TYPE)
|
||||
|
||||
|
||||
class Virsh(object):
|
||||
|
||||
def __init__(self, service_wait, distro):
|
||||
self.distro = distro
|
||||
self.wait_time = max(int(service_wait), 1)
|
||||
self.wait_time = service_wait
|
||||
|
||||
def _service_status(self):
|
||||
cmd = self.distro.get_command('libvirt', 'status')
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
import copy
|
||||
import io
|
||||
import yaml
|
||||
|
||||
from anvil import cfg
|
||||
from anvil import colorizer
|
||||
@@ -198,7 +197,7 @@ class KeystoneRuntime(comp.PythonRuntime):
|
||||
def __init__(self, *args, **kargs):
|
||||
comp.PythonRuntime.__init__(self, *args, **kargs)
|
||||
self.bin_dir = sh.joinpths(self.get_option('app_dir'), 'bin')
|
||||
self.wait_time = max(int(self.get_option('service_wait_seconds')), 1)
|
||||
self.wait_time = self.get_int_option('service_wait_seconds')
|
||||
self.init_fn = sh.joinpths(self.get_option('trace_dir'), INIT_WHAT_HAPPENED)
|
||||
|
||||
def post_start(self):
|
||||
@@ -206,7 +205,7 @@ class KeystoneRuntime(comp.PythonRuntime):
|
||||
LOG.info("Waiting %s seconds so that keystone can start up before running first time init." % (self.wait_time))
|
||||
sh.sleep(self.wait_time)
|
||||
LOG.info("Running commands to initialize keystone.")
|
||||
(fn, contents) = utils.load_template(self.name, INIT_WHAT_FN)
|
||||
(fn, _contents) = utils.load_template(self.name, INIT_WHAT_FN)
|
||||
LOG.debug("Initializing with contents of %s", fn)
|
||||
cfg = {}
|
||||
cfg['keystone'] = khelper.get_shared_params(**utils.merge_dicts(self.options, khelper.get_shared_passwords(self)))
|
||||
@@ -214,7 +213,7 @@ class KeystoneRuntime(comp.PythonRuntime):
|
||||
**self.get_option('glance'))
|
||||
cfg['nova'] = nhelper.get_shared_params(ip=self.get_option('ip'),
|
||||
**self.get_option('nova'))
|
||||
init_what = utils.param_replace_deep(copy.deepcopy(yaml.load(contents)), cfg)
|
||||
init_what = utils.param_replace_deep(utils.load_yaml(fn), cfg)
|
||||
khelper.Initializer(cfg['keystone']['service_token'],
|
||||
cfg['keystone']['endpoints']['admin']['uri']).initialize(**init_what)
|
||||
# Writing this makes sure that we don't init again
|
||||
|
||||
@@ -195,7 +195,7 @@ class NovaInstaller(NovaMixin, comp.PythonInstallComponent):
|
||||
|
||||
def warm_configs(self):
|
||||
warm_pws = list()
|
||||
mq_type = nhelper.canon_mq_type(self.get_option('mq'))
|
||||
mq_type = nhelper.canon_mq_type(self.get_option('mq-type'))
|
||||
if mq_type == 'rabbit':
|
||||
rhelper.get_shared_passwords(self)
|
||||
driver_canon = nhelper.canon_virt_driver(self.get_option('virt_driver'))
|
||||
@@ -314,8 +314,8 @@ class NovaInstaller(NovaMixin, comp.PythonInstallComponent):
|
||||
class NovaRuntime(NovaMixin, comp.PythonRuntime):
|
||||
def __init__(self, *args, **kargs):
|
||||
comp.PythonRuntime.__init__(self, *args, **kargs)
|
||||
self.wait_time = max(int(self.get_option('service_wait_seconds')), 1)
|
||||
self.virsh = lv.Virsh(int(self.get_option('service_wait_seconds')), self.distro)
|
||||
self.wait_time = self.get_int_option('service_wait_seconds')
|
||||
self.virsh = lv.Virsh(self.wait_time, self.distro)
|
||||
self.config_path = sh.joinpths(self.get_option('cfg_dir'), API_CONF)
|
||||
self.bin_dir = sh.joinpths(self.get_option('app_dir'), BIN_DIR)
|
||||
self.net_init_fn = sh.joinpths(self.get_option('trace_dir'), NET_INITED_FN)
|
||||
|
||||
@@ -71,7 +71,7 @@ class RabbitInstaller(comp.PkgInstallComponent):
|
||||
class RabbitRuntime(comp.ProgramRuntime):
|
||||
def __init__(self, *args, **kargs):
|
||||
comp.ProgramRuntime.__init__(self, *args, **kargs)
|
||||
self.wait_time = max(int(self.get_option('service_wait_seconds')), 1)
|
||||
self.wait_time = self.get_int_option('service_wait_seconds')
|
||||
|
||||
def start(self):
|
||||
if self.status()[0].status != comp.STATUS_STARTED:
|
||||
|
||||
@@ -25,11 +25,11 @@ import shlex
|
||||
import yaml
|
||||
|
||||
from anvil import colorizer
|
||||
from anvil import exceptions as excp
|
||||
from anvil import importer
|
||||
from anvil import log as logging
|
||||
from anvil import shell as sh
|
||||
from anvil import utils
|
||||
from anvil import exceptions as excp
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
@@ -133,7 +133,7 @@ def load(path):
|
||||
# read this (even if dry-run)
|
||||
with open(fn, 'r') as fh:
|
||||
contents = fh.read()
|
||||
cls_kvs = yaml.load(contents)
|
||||
cls_kvs = yaml.safe_load(contents)
|
||||
distro_possibles.append(Distro(**cls_kvs))
|
||||
except (IOError, yaml.YAMLError) as err:
|
||||
LOG.warning('Could not load distro definition from %r: %s', fn, err)
|
||||
|
||||
@@ -40,11 +40,9 @@ SHELL_QUOTE_REPLACERS = {
|
||||
"$": '\$',
|
||||
'`': '\`',
|
||||
}
|
||||
SHELL_WRAPPER = "\"%s\""
|
||||
ROOT_PATH = os.sep
|
||||
|
||||
|
||||
#root context guard
|
||||
class Rooted(object):
|
||||
def __init__(self, run_as_root):
|
||||
self.root_mode = run_as_root
|
||||
@@ -66,8 +64,9 @@ def is_dry_run():
|
||||
dry_v = env.get_key('ANVIL_DRYRUN')
|
||||
if not dry_v:
|
||||
return False
|
||||
# TODO(harlowja) these checks are duplicated in utils, rework that...
|
||||
dry_v = str(dry_v).lower().strip()
|
||||
if dry_v in ['0', 'false', 'no', 'off']:
|
||||
if dry_v in ['0', 'false', 'off', 'no', 'f', '', 'none']:
|
||||
return False
|
||||
return True
|
||||
|
||||
@@ -100,15 +99,6 @@ def execute(*cmd, **kwargs):
|
||||
if shell:
|
||||
execute_cmd = str_cmd.strip()
|
||||
|
||||
if not shell:
|
||||
LOG.debug('Running cmd: %r' % (execute_cmd))
|
||||
else:
|
||||
LOG.debug('Running shell cmd: %r' % (execute_cmd))
|
||||
if process_input is not None:
|
||||
LOG.debug('With stdin: %s' % (process_input))
|
||||
if cwd:
|
||||
LOG.debug("In working directory: %r" % (cwd))
|
||||
|
||||
stdin_fh = subprocess.PIPE
|
||||
stdout_fh = subprocess.PIPE
|
||||
stderr_fh = subprocess.PIPE
|
||||
@@ -124,6 +114,15 @@ def execute(*cmd, **kwargs):
|
||||
if 'stderr_fh' in kwargs.keys():
|
||||
stderr_fh = kwargs.get('stderr_fh')
|
||||
|
||||
if not shell:
|
||||
LOG.debug('Running cmd: %r' % (execute_cmd))
|
||||
else:
|
||||
LOG.debug('Running shell cmd: %r' % (execute_cmd))
|
||||
if process_input is not None:
|
||||
LOG.debug('With stdin: %s' % (process_input))
|
||||
if cwd:
|
||||
LOG.debug("In working directory: %r" % (cwd))
|
||||
|
||||
process_env = None
|
||||
if env_overrides and len(env_overrides):
|
||||
process_env = env.get()
|
||||
@@ -156,15 +155,9 @@ def execute(*cmd, **kwargs):
|
||||
result = ('', '')
|
||||
else:
|
||||
try:
|
||||
obj = subprocess.Popen(execute_cmd,
|
||||
stdin=stdin_fh,
|
||||
stdout=stdout_fh,
|
||||
stderr=stderr_fh,
|
||||
close_fds=close_file_descriptors,
|
||||
cwd=cwd,
|
||||
shell=shell,
|
||||
preexec_fn=demoter,
|
||||
env=process_env)
|
||||
obj = subprocess.Popen(execute_cmd, stdin=stdin_fh, stdout=stdout_fh, stderr=stderr_fh,
|
||||
close_fds=close_file_descriptors, cwd=cwd, shell=shell,
|
||||
preexec_fn=demoter, env=process_env)
|
||||
if process_input is not None:
|
||||
result = obj.communicate(str(process_input))
|
||||
else:
|
||||
@@ -172,8 +165,7 @@ def execute(*cmd, **kwargs):
|
||||
except OSError as e:
|
||||
raise excp.ProcessExecutionError(description="%s: [%s, %s]" % (e, e.errno, e.strerror),
|
||||
cmd=str_cmd)
|
||||
if (stdin_fh != subprocess.PIPE
|
||||
and obj.stdin and close_stdin):
|
||||
if (stdin_fh != subprocess.PIPE and obj.stdin and close_stdin):
|
||||
obj.stdin.close()
|
||||
rc = obj.returncode
|
||||
|
||||
@@ -237,7 +229,7 @@ def pipe_in_out(in_fh, out_fh, chunk_size=1024, chunk_cb=None):
|
||||
|
||||
|
||||
def shellquote(text):
|
||||
# TODO since there doesn't seem to be a standard lib that actually works use this way...
|
||||
# TODO(harlowja) find a better way - since there doesn't seem to be a standard lib that actually works
|
||||
do_adjust = False
|
||||
for srch in SHELL_QUOTE_REPLACERS.keys():
|
||||
if text.find(srch) != -1:
|
||||
@@ -250,7 +242,7 @@ def shellquote(text):
|
||||
text.startswith((" ", "\t")) or \
|
||||
text.endswith((" ", "\t")) or \
|
||||
text.find("'") != -1:
|
||||
text = SHELL_WRAPPER % (text)
|
||||
text = "\"%s\"" % (text)
|
||||
return text
|
||||
|
||||
|
||||
@@ -625,38 +617,6 @@ def getgroupname():
|
||||
return grp.getgrgid(gid).gr_name
|
||||
|
||||
|
||||
def create_loopback_file(fname, size, bsize=1024, fs_type='ext3', run_as_root=False):
|
||||
dd_cmd = ['dd', 'if=/dev/zero', 'of=%s' % fname, 'bs=%d' % bsize,
|
||||
'count=0', 'seek=%d' % size]
|
||||
mkfs_cmd = ['mkfs.%s' % fs_type, '-f', '-i', 'size=%d' % bsize, fname]
|
||||
|
||||
# Make sure folder exists
|
||||
files = mkdirslist(dirname(fname))
|
||||
|
||||
# Create file
|
||||
touch_file(fname)
|
||||
|
||||
# Fill with zeroes
|
||||
execute(*dd_cmd, run_as_root=run_as_root)
|
||||
|
||||
# Create fs on the file
|
||||
execute(*mkfs_cmd, run_as_root=run_as_root)
|
||||
|
||||
return files
|
||||
|
||||
|
||||
def mount_loopback_file(fname, device_name, fs_type='ext3'):
|
||||
mount_cmd = ['mount', '-t', fs_type, '-o',
|
||||
'loop,noatime,nodiratime,nobarrier,logbufs=8', fname,
|
||||
device_name]
|
||||
|
||||
files = mkdirslist(device_name)
|
||||
|
||||
execute(*mount_cmd, run_as_root=True)
|
||||
|
||||
return files
|
||||
|
||||
|
||||
def umount(dev_name, ignore_errors=True):
|
||||
try:
|
||||
execute('umount', dev_name, run_as_root=True)
|
||||
@@ -757,6 +717,8 @@ def getegid():
|
||||
|
||||
|
||||
def sleep(winks):
|
||||
if winks <= 0:
|
||||
return
|
||||
if is_dry_run():
|
||||
LOG.debug("Not really sleeping for: %s seconds" % (winks))
|
||||
else:
|
||||
|
||||
@@ -77,12 +77,14 @@ LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def make_bool(val):
|
||||
if type(val) is bool:
|
||||
if isinstance(val, bool):
|
||||
return val
|
||||
if isinstance(val, types.NoneType):
|
||||
return False
|
||||
sval = str(val).lower().strip()
|
||||
if sval in ['true', '1', 'on', 'yes', 't']:
|
||||
return True
|
||||
if sval in ['0', 'false', 'off', 'no', 'f', '']:
|
||||
if sval in ['0', 'false', 'off', 'no', 'f', '', 'none']:
|
||||
return False
|
||||
raise TypeError("Unable to convert %r to a boolean" % (val))
|
||||
|
||||
@@ -97,8 +99,7 @@ def obj_name(obj):
|
||||
|
||||
|
||||
def load_yaml(fn):
|
||||
contents = sh.load_file(fn)
|
||||
return yaml.safe_load(contents)
|
||||
return yaml.safe_load(sh.load_file(fn))
|
||||
|
||||
|
||||
def add_header(fn, contents):
|
||||
|
||||
Reference in New Issue
Block a user