本文整理汇总了Python中server_mgr_logger.ServerMgrlogger类的典型用法代码示例。如果您正苦于以下问题:Python ServerMgrlogger类的具体用法?Python ServerMgrlogger怎么用?Python ServerMgrlogger使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ServerMgrlogger类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, vm_params):
global _smgr_log
_smgr_log = ServerMgrlogger()
_smgr_log.log(_smgr_log.DEBUG, "ContrailVM Init")
self.vm = vm_params['vm']
self.vmdk = vm_params['vmdk']
self.datastore = vm_params['datastore']
self.eth0_mac = vm_params['eth0_mac']
self.eth0_ip = vm_params['eth0_ip']
self.eth0_pg = vm_params['eth0_pg']
self.eth0_vswitch = vm_params['eth0_vswitch']
self.eth0_vlan = vm_params['eth0_vlan']
self.eth1_vswitch = vm_params['eth1_vswitch']
self.eth1_pg = vm_params['eth1_pg']
self.eth1_vlan = vm_params['eth1_vlan']
self.uplink_nic = vm_params['uplink_nic']
self.uplink_vswitch = vm_params['uplink_vswitch']
self.server = vm_params['server']
self.username = vm_params['username']
self.password = vm_params['password']
self.thindisk = vm_params['thindisk']
self.vm_domain = vm_params['domain']
self.vm_id = 0
self.smgr_ip = vm_params['smgr_ip']
self.vm_server = vm_params['vm_server']
self.vm_password = vm_params['vm_password']
self.vm_deb = vm_params['vm_deb']
self._create_networking()
print self._create_vm()
print self._install_contrailvm_pkg(self.eth0_ip, "root", self.vm_password, self.vm_domain, self.vm_server,
self.vm_deb, self.smgr_ip)
开发者ID:Akilesh1597,项目名称:contrail-server-manager,代码行数:32,代码来源:esxi_contrailvm.py
示例2: __init__
class PlayLogger:
"""
Store log output in a single object
One object per Ansible run
"""
def __init__(self):
self.log = ''
self.runtime = 0
try:
self._sm_logger = ServerMgrlogger()
except:
f = open("/var/log/contrail-server-manager/debug.log", "a")
f.write("Ansible Callback Init - ServerMgrlogger init failed\n")
f.close()
def append(self, log_line):
self.log += log_line+"\n"
self._sm_logger.log(self._sm_logger.INFO, log_line)
def banner(self, msg):
width = 78 - len(msg)
if width < 3:
width = 3
filler = "*" * width
return "\n%s %s " % (msg, filler)
开发者ID:nitishkrishna,项目名称:contrail-server-manager,代码行数:26,代码来源:sm_ansible_callback.py
示例3: Joiner
class Joiner(threading.Thread):
def __init__(self, q):
super(Joiner, self).__init__()
self._smgr_log = ServerMgrlogger()
self.queue = q
def run(self):
while True:
child = self.queue.get()
self._smgr_log.log(self._smgr_log.INFO, "Joining a process")
print "joining a process"
if child == None:
return
child.join()
self._smgr_log.log(self._smgr_log.INFO, "Process Done")
print "process done"
开发者ID:Juniper,项目名称:contrail-server-manager,代码行数:16,代码来源:sm_ansible_server.py
示例4: run
def run(self):
#create the logger
try:
self._smgr_log = ServerMgrlogger()
except:
print "Error Creating logger object"
# Connect to the cluster-servers database
try:
self._status_serverDb = db(
self._smgr_main._args.server_manager_base_dir+self._smgr_main._args.database_name)
except:
self._smgr_log.log(self._smgr_log.DEBUG,
"Error Connecting to Server Database %s"
% (self._smgr_main._args.server_manager_base_dir+self._smgr_main._args.database_name))
exit()
#set the status related handlers
status_bottle_app = Bottle()
status_bottle_app.route('/server_status', 'POST', self.put_server_status)
status_bottle_app.route('/server_status', 'PUT', self.put_server_status)
self._base_obj = self._status_thread_config['base_obj']
try:
bottle.run(status_bottle_app,
host=self._status_thread_config['listen_ip'],
port=self._status_thread_config['listen_port'])
except Exception as e:
# cleanup gracefully
exit()
开发者ID:biddyweb,项目名称:contrail-server-manager,代码行数:30,代码来源:server_mgr_status.py
示例5: __init__
def __init__(self, base_dir=_DEF_BASE_DIR,
ip_address=_DEF_COBBLER_IP,
port=_DEF_COBBLER_PORT,
username=_DEF_USERNAME,
password=_DEF_PASSWORD):
self._smgr_log = ServerMgrlogger()
self._smgr_log.log(self._smgr_log.DEBUG, "ServerMgrCobbler Init")
# Store the passed in values
self._cobbler_ip = ip_address
self._cobbler_port = port
self._cobbler_username = username
self._cobbler_password = password
try:
if self._cobbler_port:
self._server = xmlrpclib.Server(
"http://" +
self._cobbler_ip + ":" +
self._cobbler_port + "/cobbler_api")
else:
self._server = xmlrpclib.Server(
"http://" +
self._cobbler_ip + "/cobbler_api")
self._token = self._server.login(self._cobbler_username,
self._cobbler_password)
except subprocess.CalledProcessError as e:
msg = ("Cobbler Init: error %d when executing"
"\"%s\"" %(e.returncode, e.cmd))
self.log_and_raise_exception(msg, ERR_OPR_ERROR)
except Exception as e:
raise e
开发者ID:Akilesh1597,项目名称:contrail-server-manager,代码行数:33,代码来源:server_mgr_cobbler.py
示例6: __init__
def __init__(self, json_entity, args):
super(ContrailAnsiblePlaybooks, self).__init__()
try:
self.logger = ServerMgrlogger()
except:
f = open("/var/log/contrail-server-manager/debug.log", "a")
f.write("Ansible Callback Init - ServerMgrlogger init failed\n")
f.close()
#Initialize common stuff
self.json_entity = json_entity
self.args = args
self.hosts_in_inv = json_entity[0]["hosts_in_inv"]
if "kolla_inv" in json_entity[0]["parameters"]:
self.hosts_in_kolla_inv = \
SMAnsibleUtils(self.logger).hosts_in_kolla_inventory(\
json_entity[0]['parameters']['kolla_inv'])
self.tasks = re.split(r'[,\ ]+', json_entity[0]["tasks"])
#Initialize vars required for Ansible Playbook APIs
self.options = None
self.extra_vars = None
self.pbook_path = None
self.var_mgr = None
self.inventory = None
self.pb_executor = None
开发者ID:Juniper,项目名称:contrail-server-manager,代码行数:27,代码来源:sm_ansible_playbook.py
示例7: __init__
def __init__(self, serverdb=None, log_file=None):
if serverdb:
self._serverDb = serverdb
else:
self._serverDb = db(DEF_SERVER_DB_LOCATION)
self._smgr_log = ServerMgrlogger()
开发者ID:nitishkrishna,项目名称:contrail-server-manager,代码行数:7,代码来源:server_mgr_ssh_client.py
示例8: __init__
def __init__(self, base_dir=_DEF_BASE_DIR,
ip_address=_DEF_COBBLER_IP,
port=_DEF_COBBLER_PORT,
username=_DEF_USERNAME,
password=_DEF_PASSWORD):
self._smgr_log = ServerMgrlogger()
self._smgr_log.log(self._smgr_log.DEBUG, "ServerMgrCobbler Init")
# Store the passed in values
self._cobbler_ip = ip_address
self._cobbler_port = port
self._cobbler_username = username
self._cobbler_password = password
try:
if self._cobbler_port:
self._server = xmlrpclib.Server(
"http://" +
self._cobbler_ip + ":" +
self._cobbler_port + "/cobbler_api")
else:
self._server = xmlrpclib.Server(
"http://" +
self._cobbler_ip + "/cobbler_api")
self._token = self._server.login(self._cobbler_username,
self._cobbler_password)
# Copy contrail centos repo to cobber repos, so that target
# systems can install and run puppet agent from kickstart.
repo = self._server.find_repo({"name": _CONTRAIL_CENTOS_REPO})
if repo:
rid = self._server.get_repo_handle(
_CONTRAIL_CENTOS_REPO, self._token)
else:
rid = self._server.new_repo(self._token)
self._server.modify_repo(rid, "arch", "x86_64", self._token)
repo_dir = base_dir + "contrail-centos-repo"
self._server.modify_repo(
rid, "name", _CONTRAIL_CENTOS_REPO, self._token)
self._server.modify_repo(rid, "mirror", repo_dir, self._token)
self._server.modify_repo(rid, "keep_updated", True, self._token)
self._server.modify_repo(rid, "priority", "99", self._token)
self._server.modify_repo(rid, "rpm_list", [], self._token)
self._server.modify_repo(rid, "yumopts", {}, self._token)
self._server.modify_repo(rid, "mirror_locally", True, self._token)
self._server.modify_repo(rid, "environment", {}, self._token)
self._server.modify_repo(rid, "comment", "...", self._token)
self._server.save_repo(rid, self._token)
# Issue cobbler reposync for this repo
cmd = "cobbler reposync --only=" + _CONTRAIL_CENTOS_REPO
subprocess.check_call(cmd, shell=True)
except subprocess.CalledProcessError as e:
msg = ("Cobbler Init: error %d when executing"
"\"%s\"" %(e.returncode, e.cmd))
raise ServerMgrException(msg)
except Exception as e:
raise e
开发者ID:jufeng,项目名称:contrail-server-manager,代码行数:58,代码来源:server_mgr_cobbler.py
示例9: __init__
def __init__(self, db_file_name=def_server_db_file):
try:
self._smgr_log = ServerMgrlogger()
self._con = lite.connect(db_file_name)
with self._con:
cursor = self._con.cursor()
# Create cluster table.
cursor.execute("CREATE TABLE IF NOT EXISTS " + cluster_table +
""" (id TEXT PRIMARY KEY,
parameters TEXT,
email TEXT)""")
# Create image table
cursor.execute("CREATE TABLE IF NOT EXISTS " +
image_table + """ (id TEXT PRIMARY KEY,
version TEXT, type TEXT, path TEXT,
parameters TEXT)""")
# Create status table
cursor.execute("CREATE TABLE IF NOT EXISTS " +
server_status_table + """ (id TEXT PRIMARY KEY,
server_status TEXT)""")
# Create server table
cursor.execute(
"CREATE TABLE IF NOT EXISTS " + server_table +
""" (mac_address TEXT PRIMARY KEY NOT NULL,
id TEXT, host_name TEXT, static_ip varchar default 'N',
ip_address TEXT, subnet_mask TEXT, gateway TEXT, domain TEXT,
cluster_id TEXT, base_image_id TEXT,
package_image_id TEXT, password TEXT,
last_update TEXT, discovered varchar default 'false',
parameters TEXT, roles TEXT, ipmi_username TEXT,
ipmi_password TEXT, ipmi_address TEXT,
ipmi_type TEXT, intf_control TEXT,
intf_data TEXT, intf_bond TEXT,
email TEXT, status TEXT,
tag1 TEXT, tag2 TEXT, tag3 TEXT,
tag4 TEXT, tag5 TEXT, tag6 TAXT, tag7 TEXT,
UNIQUE (id))""")
# Create server tags table
cursor.execute(
"CREATE TABLE IF NOT EXISTS " + server_tags_table +
""" (tag_id TEXT PRIMARY KEY NOT NULL,
value TEXT,
UNIQUE (tag_id),
UNIQUE (value))""")
self._get_table_columns()
self._smgr_log.log(self._smgr_log.DEBUG, "Created tables")
# During init, we check if any of the Cluster in DB are missing any Storage Parameters (Generated UUIDs)
cluster_list = self._get_items(cluster_table, None,
None, True, None)
for cluster in cluster_list:
# Check if storage parameters are present in Cluster, else generate them
if 'storage_fsid' not in set(eval(cluster['parameters'])) or 'storage_virsh_uuid' not in set(eval(
cluster['parameters'])):
self.update_cluster_uuids(cluster)
except e:
raise e
开发者ID:jufeng,项目名称:contrail-server-manager,代码行数:57,代码来源:server_mgr_db.py
示例10: __init__
def __init__(self, smgr_base_dir, puppet_dir):
self._smgr_log = ServerMgrlogger()
self._smgr_log.log(self._smgr_log.DEBUG, "ServerMgrPuppet Init")
self.smgr_base_dir = smgr_base_dir
self.puppet_directory = puppet_dir
if not os.path.exists(os.path.dirname(puppet_dir)):
os.makedirs(os.path.dirname(puppet_dir))
开发者ID:Juniper,项目名称:contrail-server-manager,代码行数:9,代码来源:server_mgr_puppet.py
示例11: dict
class PlayLogger:
default_config = dict()
"""
Store log output in a single object
One object per Ansible run
"""
def __init__(self, cluster_id):
self.log = ''
self.runtime = 0
self.defaults_file = "/etc/contrail/sm-client-config.ini"
config = ConfigParser.SafeConfigParser()
config.read([self.defaults_file])
self.default_config["smgr"] = dict(config.items("SERVER-MANAGER"))
self.smgr_ip = self.default_config["smgr"]["listen_ip_addr"]
self._sm_prov_logger = None
f = open("/var/log/contrail-server-manager/debug.log", "a")
f.write("Ansible callback init - smgr_ip: %s" % self.smgr_ip)
try:
self._sm_logger = ServerMgrlogger()
if cluster_id:
self._sm_prov_logger = ServerMgrProvlogger(cluster_id)
else:
self._sm_logger.log(self._sm_logger.ERROR,
"cluster_id not found in inventory - provision specific "\
"logging will not be done")
except:
f = open("/var/log/contrail-server-manager/debug.log", "a")
f.write("Ansible Callback Init - ServerMgrlogger init failed\n")
f.close()
def append(self, log_line):
self.log += log_line+"\n"
if self._sm_prov_logger:
self._sm_prov_logger.log("info", log_line)
self._sm_logger.log(self._sm_logger.INFO, log_line)
def banner(self, msg):
width = 78 - len(msg)
if width < 3:
width = 3
filler = "*" * width
return "\n%s %s " % (msg, filler)
开发者ID:Juniper,项目名称:contrail-server-manager,代码行数:43,代码来源:sm_ansible_callback.py
示例12: __init__
def __init__(self):
''' Constructor '''
self.MonitoringCfg = {
'monitoring_frequency': _DEF_MON_FREQ,
'monitoring_plugin': _DEF_MONITORING_PLUGIN
}
self.InventoryCfg = {
'inventory_plugin': _DEF_INVENTORY_PLUGIN
}
self._smgr_log = ServerMgrlogger()
self.monitoring_args = None
self.monitoring_config_set = False
self.inventory_args = None
self.inventory_config_set = False
self.server_monitoring_obj = None
self.server_inventory_obj = None
self.monitoring_gevent_thread_obj = None
开发者ID:Juniper,项目名称:contrail-server-manager,代码行数:17,代码来源:server_mgr_mon_base_plugin.py
示例13: __init__
def __init__(self, args_str=None):
try:
self._smgr_log = ServerMgrlogger()
except:
print "Error Creating logger object"
self._smgr_log.log(self._smgr_log.INFO, "Starting SM Ansible Server")
if not args_str:
args_str = sys.argv[1:]
self._parse_args(args_str)
self.joinq = Queue.Queue()
self.joiner = Joiner(self.joinq)
self.joiner.start()
self._smgr_log.log(self._smgr_log.INFO, 'Initializing Bottle App')
self.app = bottle.app()
bottle.route('/run_ansible_playbooks', 'POST',
self.start_ansible_playbooks)
开发者ID:Juniper,项目名称:contrail-server-manager,代码行数:17,代码来源:sm_ansible_server.py
示例14: __init__
def __init__(self, package, v1 = 0, v2 = 0, v3 = 0, v4 = 0):
self.logger = ServerMgrlogger()
if package == None:
self.os_sku = 14
self.major_version = v1
self.moderate_version = v2
self.minor_version_1 = v3
self.minor_version_2 = v4
elif eval(str(package["parameters"])).get("playbooks_version", False) == False:
# Could not detect playbooks in image. Set version such
# that puppet gets triggered
self.os_sku = 14
self.major_version = 4
self.moderate_version = 0
self.minor_version_1 = 0
self.minor_version_2 = 0
else:
try:
version_list = re.split(r'[\.\-]',
eval(str(package["parameters"]))["playbooks_version"])
if "sku" in package["parameters"]:
# sku is of the following format:
# 2:14.0.2-0ubuntu1~cloud0.1contrail
# here, 14 represents the openstack sku - newton
sku_list = re.split(r'[:.]',
eval(str(package["parameters"]))["sku"])
self.os_sku = sku_list[1]
else:
self.os_sku = 14
self.major_version = version_list[0]
self.moderate_version = version_list[1]
self.minor_version_1 = version_list[2]
self.minor_version_2 = version_list[3]
except Exception as e:
self.logger.log(self.logger.ERROR,
"ContrailVersion failed: %s. Falling back to 14.4.0.0.0" % e)
# Could not detect SKU. Fall back to puppet scheme of things
self.os_sku = 14
self.major_version = 4
self.moderate_version = 0
self.minor_version_1 = 0
self.minor_version_2 = 0
开发者ID:Juniper,项目名称:contrail-server-manager,代码行数:43,代码来源:server_mgr_utils.py
示例15: __init__
def __init__(self, args_str=None):
try:
self._smgr_log = ServerMgrlogger()
except:
print "Error Creating logger object"
self._smgr_log.log(self._smgr_log.INFO, "Starting SM Ansible Server")
self.host_run_results = defaultdict(dict)
if not args_str:
args_str = sys.argv[1:]
self._parse_args(args_str)
self.joinq = Queue.Queue()
self.joiner = Joiner(self.joinq)
self.joiner.start()
self._smgr_log.log(self._smgr_log.INFO, 'Initializing Bottle App')
self.app = bottle.app()
bottle.route('/start_provision', 'POST', self.start_provision)
bottle.route('/run_playbook', 'POST', self.start_playbook)
bottle.route('/playbook_status', 'PUT', self.playbook_status)
开发者ID:nitishkrishna,项目名称:contrail-server-manager,代码行数:19,代码来源:sm_ansible_server.py
示例16: __init__
def __init__(self, base_dir=_DEF_BASE_DIR,
ip_address=_DEF_COBBLER_IP,
port=_DEF_COBBLER_PORT,
username=_DEF_USERNAME,
password=_DEF_PASSWORD):
self._smgr_log = ServerMgrlogger()
self._smgr_log.log(self._smgr_log.DEBUG, "ServerMgrCobbler Init")
# Store the passed in values
self._cobbler_ip = ip_address
self._cobbler_port = port
self._cobbler_username = username
self._cobbler_password = password
try:
if self._cobbler_port:
self._server = xmlrpclib.Server(
"http://" +
self._cobbler_ip + ":" +
self._cobbler_port + "/cobbler_api")
else:
self._server = xmlrpclib.Server(
"http://" +
self._cobbler_ip + "/cobbler_api")
self._token = self._server.login(self._cobbler_username,
self._cobbler_password)
# Copy contrail centos/redhat repo to cobber repos, so that target
# systems can install and run puppet agent from kickstart.
self._init_create_repo(_CONTRAIL_CENTOS_REPO, self._server,
self._token, base_dir)
self._init_create_repo(_CONTRAIL_REDHAT_REPO, self._server,
self._token, base_dir)
except subprocess.CalledProcessError as e:
msg = ("Cobbler Init: error %d when executing"
"\"%s\"" %(e.returncode, e.cmd))
raise ServerMgrException(msg)
except Exception as e:
raise e
开发者ID:ajoshi9,项目名称:contrail-server-manager,代码行数:39,代码来源:server_mgr_cobbler.py
示例17: __init__
def __init__(self, cluster_id):
self.log = ''
self.runtime = 0
self.defaults_file = "/etc/contrail/sm-client-config.ini"
config = ConfigParser.SafeConfigParser()
config.read([self.defaults_file])
self.default_config["smgr"] = dict(config.items("SERVER-MANAGER"))
self.smgr_ip = self.default_config["smgr"]["listen_ip_addr"]
self._sm_prov_logger = None
f = open("/var/log/contrail-server-manager/debug.log", "a")
f.write("Ansible callback init - smgr_ip: %s" % self.smgr_ip)
try:
self._sm_logger = ServerMgrlogger()
if cluster_id:
self._sm_prov_logger = ServerMgrProvlogger(cluster_id)
else:
self._sm_logger.log(self._sm_logger.ERROR,
"cluster_id not found in inventory - provision specific "\
"logging will not be done")
except:
f = open("/var/log/contrail-server-manager/debug.log", "a")
f.write("Ansible Callback Init - ServerMgrlogger init failed\n")
f.close()
开发者ID:Juniper,项目名称:contrail-server-manager,代码行数:23,代码来源:sm_ansible_callback.py
示例18: ServerMgrStatusThread
class ServerMgrStatusThread(threading.Thread):
_smgr_log = None
_status_serverDb = None
_base_obj = None
_smgr_puppet = None
_smgr_main = None
''' Class to run function that keeps validating the cobbler token
periodically (every 30 minutes) on a new thread. '''
_pipe_start_app = None
def __init__(self, timer, server, status_thread_config):
threading.Thread.__init__(self)
self._status_thread_config = status_thread_config
self._smgr_puppet = status_thread_config['smgr_puppet']
self._smgr_main = status_thread_config['smgr_main']
def run(self):
#create the logger
try:
self._smgr_log = ServerMgrlogger()
except:
print "Error Creating logger object"
# Connect to the cluster-servers database
try:
self._status_serverDb = db(
self._smgr_main._args.server_manager_base_dir+self._smgr_main._args.database_name)
except:
self._smgr_log.log(self._smgr_log.DEBUG,
"Error Connecting to Server Database %s"
% (self._smgr_main._args.server_manager_base_dir+self._smgr_main._args.database_name))
exit()
#set the status related handlers
status_bottle_app = Bottle()
status_bottle_app.route('/server_status', 'POST', self.put_server_status)
status_bottle_app.route('/server_status', 'PUT', self.put_server_status)
self._base_obj = self._status_thread_config['base_obj']
try:
bottle.run(status_bottle_app,
host=self._status_thread_config['listen_ip'],
port=self._status_thread_config['listen_port'])
except Exception as e:
# cleanup gracefully
exit()
def put_server_status(self):
print "put-status"
#query_args = parse_qs(urlparse(bottle.request.url).query,
#keep_blank_values=True)
#match_key, match_value = query_args.popitem()
server_id = request.query['server_id']
server_state = request.query['state']
body = request.body.read()
server_data = {}
server_data['id'] = server_id
if server_state == "post_provision_completed":
server_data['status'] = "provision_completed"
else:
server_data['status'] = server_state
try:
time_str = strftime("%Y_%m_%d__%H_%M_%S", localtime())
message = server_id + ' ' + server_state + time_str
self._smgr_log.log(self._smgr_log.DEBUG, "Server status Data %s" % server_data)
servers = self._status_serverDb.modify_server(
server_data)
if server_state == "reimage_completed":
payload = dict()
payload["id"] = server_id
self._smgr_log.log(self._smgr_log.DEBUG, "Spawning Gevent for Id: %s" % payload["id"])
if self._base_obj:
gevent.spawn(self._base_obj.reimage_run_inventory, self._status_thread_config["listen_ip"],
self._status_thread_config["listen_port"], payload)
if server_state == "provision_started":
self._smgr_main.update_provision_started_flag(server_id, server_state)
self._smgr_main.update_provision_role_sequence(server_id,
server_state)
if server_state == "post_provision_completed":
server_state = "provision_completed"
if server_state == "provision_completed":
domain = self._status_serverDb.get_server_domain(server_id)
environment_name = 'TurningOffPuppetAgent__' + time_str
if domain:
server_fqdn = server_id + "." + domain
self._smgr_puppet.update_node_map_file(
server_fqdn, environment_name)
if server_state in email_events:
self.send_status_mail(server_id, message, message)
except Exception as e:
# self.log_trace()
self._smgr_log.log(self._smgr_log.ERROR, "Error adding to db %s" % repr(e))
abort(404, repr(e))
def get_email_list(self, email):
email_to = []
if not email:
#.........这里部分代码省略.........
开发者ID:biddyweb,项目名称:contrail-server-manager,代码行数:101,代码来源:server_mgr_status.py
示例19: SMAnsibleServer
class SMAnsibleServer():
'''
Use bottle to provide REST interface for the server manager.
'''
def __init__(self, args_str=None):
try:
self._smgr_log = ServerMgrlogger()
except:
print "Error Creating logger object"
self._smgr_log.log(self._smgr_log.INFO, "Starting SM Ansible Server")
if not args_str:
args_str = sys.argv[1:]
self._parse_args(args_str)
self.joinq = Queue.Queue()
self.joiner = Joiner(self.joinq)
self.joiner.start()
self._smgr_log.log(self._smgr_log.INFO, 'Initializing Bottle App')
self.app = bottle.app()
bottle.route('/run_ansible_playbooks', 'POST',
self.start_ansible_playbooks)
def _parse_args(self, args_str):
'''
Eg. python sm_ansible_server.py --config_file serverMgr.cfg
--listen_port 8082
'''
# Source any specified config/ini file
# Turn off help, so we print all options in response to -h
conf_parser = argparse.ArgumentParser(add_help=False)
conf_parser.add_argument(
"-c", "--config_file",
help="Specify config file with the parameter values.",
metavar="FILE")
args, remaining_argv = conf_parser.parse_known_args(args_str)
serverCfg = {
'ansible_srvr_ip': _WEB_HOST,
'ansible_srvr_port': _ANSIBLE_SRVR_PORT,
'docker_insecure_registries': _ANSIBLE_REGISTRY,
'docker_registry': _ANSIBLE_REGISTRY,
'ansible_playbook': ""
}
if args.config_file:
config_file = args.config_file
else:
config_file = _DEF_ANSIBLE_SRVR_CFG_FILE
config = ConfigParser.SafeConfigParser()
config.read([args.config_file])
self._smgr_config = config
try:
for key in dict(config.items("ANSIBLE-SERVER")).keys():
#if key in serverCfg.keys():
serverCfg[key] = dict(config.items("ANSIBLE-SERVER"))[key]
self._smgr_log.log(self._smgr_log.DEBUG,
"Arguments read form config file %s" % serverCfg)
except ConfigParser.NoSectionError:
msg = "Server Manager doesn't have a configuration set."
self._smgr_log.log(self._smgr_log.ERROR, msg)
self._smgr_log.log(self._smgr_log.DEBUG, "Arguments read form config file %s" % serverCfg)
# Override with CLI options
# Don't surpress add_help here so it will handle -h
parser = argparse.ArgumentParser(
# Inherit options from config_parser
# parents=[conf_parser],
# print script description with -h/--help
description=__doc__,
# Don't mess with format of description
formatter_class=argparse.RawDescriptionHelpFormatter,
)
parser.set_defaults(**serverCfg)
parser.add_argument(
"-i", "--ansible_srvr_ip",
help="IP address to provide service on, default %s" % (_WEB_HOST))
parser.add_argument(
"-p", "--ansible_srvr_port",
help="Port to provide service on, default %s" % (_ANSIBLE_SRVR_PORT))
self._args = parser.parse_args(remaining_argv)
self._args.config_file = args.config_file
# end _parse_args
def start_ansible_playbooks(self):
entity = bottle.request.json
pb = ContrailAnsiblePlaybooks(entity, self._args)
pb.start()
self.joinq.put(pb)
# Return success. Actual status will be supplied when the pb thread
# completes and the next status query is made
bottle.response.headers['Content-Type'] = 'application/json'
return json.dumps({'status': 'Provision in Progress'})
开发者ID:Juniper,项目名称:contrail-server-manager,代码行数:97,代码来源:sm_ansible_server.py
示例20: ServerMgrMonBasePlugin
class ServerMgrMonBasePlugin():
val = 1
freq = 300
_config_set = False
_serverDb = None
_monitoring_log = None
_collectors_ip = None
_discovery_server = None
_discovery_port = None
_default_ipmi_username = None
_default_ipmi_password = None
DEBUG = "debug"
INFO = "info"
WARN = "warn"
ERROR = "error"
CRITICAL = "critical"
def __init__(self):
''' Constructor '''
self.MonitoringCfg = {
'monitoring_frequency': _DEF_MON_FREQ,
'monitoring_plugin': _DEF_MONITORING_PLUGIN
}
self.InventoryCfg = {
'inventory_plugin': _DEF_INVENTORY_PLUGIN
}
self._smgr_log = ServerMgrlogger()
self.monitoring_args = None
self.monitoring_config_set = False
self.inventory_args = None
self.inventory_config_set = False
self.server_monitoring_obj = None
self.server_inventory_obj = None
self.monitoring_gevent_thread_obj = None
def set_serverdb(self, server_db):
self._serverDb = server_db
def set_ipmi_defaults(self, ipmi_username, ipmi_password):
self._default_ipmi_username = ipmi_username
self._default_ipmi_password = ipmi_password
def parse_args(self, args_str, section):
# Source any specified config/ini file
# Turn off help, so we print all options in response to -h
conf_parser = argparse.ArgumentParser(add_help=False)
conf_parser.add_argument(
"-c", "--config_file",
help="Specify config file with the parameter values.",
metavar="FILE")
args, remaining_argv = conf_parser.parse_known_args(args_str)
if args.config_file:
config_file = args.config_file
else:
config_file = _DEF_SMGR_CFG_FILE
config = ConfigParser.SafeConfigParser()
config.read([config_file])
parser = argparse.ArgumentParser(
# Inherit options from config_parser
# parents=[conf_parser],
# print script description with -h/--help
description=__doc__,
# Don't mess with format of description
formatter_class=argparse.RawDescriptionHelpFormatter,
)
if section == "MONITORING":
for key in dict(config.items("MONITORING")).keys():
if key in self.MonitoringCfg.keys():
self.MonitoringCfg[key] = dict(config.items("MONITORING"))[key]
else:
self._smgr_log.log(self._smgr_log.DEBUG, "Configuration set for invalid parameter: %s" % key)
self._smgr_log.log(self._smgr_log.DEBUG,
"Arguments read from monitoring config file %s" % self.MonitoringCfg)
parser.set_defaults(**self.MonitoringCfg)
elif section == "INVENTORY":
for key in dict(config.items("INVENTORY")).keys():
if key in self.InventoryCfg.keys():
self.InventoryCfg[key] = dict(config.items("INVENTORY"))[key]
else:
self._smgr_log.log(self._smgr_log.DEBUG, "Configuration set for invalid parameter: %s" % key)
self._smgr_log.log(self._smgr_log.DEBUG,
"Arguments read from inventory config file %s" % self.InventoryCfg)
parser.set_defaults(**self.InventoryCfg)
return parser.parse_args(remaining_argv)
def parse_monitoring_args(self, args_str, args, sm_args, _rev_tags_dict, base_obj):
config = ConfigParser.SafeConfigParser()
config.read([args.config_file])
try:
if dict(config.items("MONITORING")).keys():
# Handle parsing for monitoring
monitoring_args = self.parse_args(args_str, "MONITORING")
if monitoring_args:
self._smgr_log.log(self._smgr_log.DEBUG, "Monitoring arguments read from config.")
self.monitoring_args = monitoring_args
else:
self._smgr_log.log(self._smgr_log.DEBUG, "No monitoring configuration set.")
else:
#.........这里部分代码省略.........
开发者ID:biddyweb,项目名称:contrail-server-manager,代码行数:101,代码来源:server_mgr_mon_base_plugin.py
注:本文中的server_mgr_logger.ServerMgrlogger类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论