本文整理汇总了Python中Mgmt类的典型用法代码示例。如果您正苦于以下问题:Python Mgmt类的具体用法?Python Mgmt怎么用?Python Mgmt使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Mgmt类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __set_user_password
def __set_user_password(self, username, password):
# XXX/jshilkaitis: lame, should be an action on the mgmtd side
# XXX/jshilkaitis: why doesn't the framework do validation?
valid_password = common.lc_password_validate(password)
if not valid_password:
# XXX/jshilkaitis: hardcode the reason for now, since we know
# length is the only criterion, but that may not be true in the
# future.
raise ServiceError, 'Password must contain at least 6 characters'
use_sha512 = Mgmt.get_value('/rbt/support/config/sha_password/enable')
if use_sha512:
crypted_password = common.sha_encrypt_password(False, password)
else:
crypted_password = common.ltc_encrypt_password(password)
password_node_name = '/auth/passwd/user/%s/password' % username
code, msg = Mgmt.set((password_node_name, 'string', crypted_password))
if code != 0:
raise ServiceError, msg
示例2: reboot
def reboot(self):
"""
reboot(auth) -> None
Reboot the appliance.
Exceptions:
rebootFault - Unable to verify user permissions
rebootFault - Authorization failure: unable to complete action for user
"""
reboot_node = '/pm/actions/reboot'
check_rbm_permissions(reboot_node, RBM_ACTION)
# XXX/jshilkaitis: _highly_ questionable implementation, but we need
# something now. Flaws: relies on arbitrary 3 second sleep, and does
# not report an error to the client if the reboot action fails. The
# action failing should be rare enough to not worry about, though.
if os.fork() == 0:
time.sleep(3) # give parent SOAP server time to respond
# we fork so that the parent SOAP server can respond to the
# client. The following action does not return if it is
# successful.
Mgmt.action(reboot_node)
示例3: getTACACSAuthorizationCfged
def getTACACSAuthorizationCfged():
"""
@returns true if TACACS+ is configured as an authorization method
and that there is a valid TACACS+ server configured.
"""
author = [Mgmt.get_value("/aaa/cmd_author_method/1/name"),
Mgmt.get_value("/aaa/cmd_author_method/2/name")]
return ('tacacs+' in author)
示例4: getTACACSAccountingCfged
def getTACACSAccountingCfged():
"""
@returns true if TACACS+ is configured as an accounting method
and that there is a valid TACACS+ server configured.
"""
acct = [Mgmt.get_value("/aaa/cmd_audit_method/1/name"),
Mgmt.get_value("/aaa/cmd_audit_method/2/name")]
return ('tacacs+' in acct)
示例5: __call__
def __call__(self, *args, **kw):
auth_info = args[1]
# the (de-)serializer turns the empty string into None, which
# ctypes will then turn into NULL. This will crash the
# pam_conversation function, so we protect against it here.
if auth_info.password is None:
auth_info.password = ""
try:
# XXX/jshilkaitis: is using wsmd okay here?
pamh = pam.PamHandle("wsmd", auth_info.username,
auth_info.password)
# XXX/jshilkaitis: check to see if there are flags we want here
pamh.authenticate(0)
# XXX/jshilkaitis: flag check
pamh.acct_mgmt(0)
except:
log(LOG_NOTICE, 'User %s failed to authenticate via the SOAP '
'server.' % auth_info.username)
raise
else:
log(LOG_NOTICE, 'User %s succesfully authenticated via the '
'SOAP server.' % auth_info.username)
# XXX/jshilkaitis: We need to ask PAM for the local username
# and use that to get the proper uid/gid.
# XXX/jshilkaitis: is username the LOCAL username?
# We need to make sure that Tac+ and RADIUS auths play
# nicely with the setuid/setgid.
pwd_db_entry = pwd.getpwnam(auth_info.username)
uid = pwd_db_entry[2]
gid = pwd_db_entry[3]
os.setegid(gid)
os.seteuid(uid)
# strip out auth_info
args = list(args)
args.pop(1)
try:
try:
Mgmt.open()
except:
raise ServiceError, "Unable to connect to the " \
"management backend."
return self.func(*args, **kw)
finally:
Mgmt.close()
示例6: is_interceptor_in_cluster
def is_interceptor_in_cluster():
RSI = '/rbt/sport/intercept'
names = Mgmt.get_children(RSI + '/config/neighbor/name')[0]
for name in names:
is_interceptor = Mgmt.get_value(RSI + '/neighbor/' + \
name + '/is_interceptor') == 'true'
if is_interceptor:
return True
return False;
示例7: __start_sport
def __start_sport(self):
val = Mgmt.get_value('/pm/monitor/process/sport/state')
if val is None:
raise ServiceError, "Could not determine the service's state"
if val != 'running':
code, msg, bindings = Mgmt.action(
'/rbt/sport/main/action/restart_service')
if code != 0:
raise ServiceError, msg
示例8: start_vmware_vmx
def start_vmware_vmx(path):
"""!
Start vmware-vmx with given vm
"""
Logging.log(Logging.LOG_INFO, "Starting vm %s" % path)
vsp_ramfs = RamFs.RamFs(vsp_ramfs_path)
if vsp_ramfs.is_mounted():
# we generally should not hit this path, we unmount the ramfs when
# we stop vmware-vmx
Logging.log(Logging.LOG_INFO,
"VSP ramfs is already mounted %s, unmounting" % \
vsp_ramfs_path)
try:
vsp_ramfs.unmount_ramfs()
except RamFs.RamFsCmdException as e:
# we'll proceed with starting vmx even if we can't unmount
Logging.log(Logging.LOG_ERR, e.msg)
if not vsp_ramfs.is_mounted():
try:
vsp_ramfs.mount_ramfs(vsp_ovhd_ramfs_min_size_mb)
except (OSError, RamFs.RamFsCmdException) as e:
Logging.log(Logging.LOG_ERR, str(e))
Logging.log(Logging.LOG_ERR,
"Unable to create ramfs %s" \
" not starting VMX" % vsp_ramfs_path)
# skip starting VMX, the caller will look for vmx status
return
# Link in performance tweaks library
env_dict = os.environ.copy()
Mgmt.open()
if Vsp.is_memlock_enabled():
if env_dict.has_key("LD_PRELOAD"):
env_dict["LD_PRELOAD"] = vmperf_path + " " + env_dict["LD_PRELOAD"]
else:
env_dict["LD_PRELOAD"] = vmperf_path
# Check the ESXi debug option to see which binary we need to run
vmx_option = get_debug_option()
Mgmt.close()
binary_path = option_to_path[vmx_option]
Logging.log(Logging.LOG_DEBUG, "BINARY PATH: %s" % binary_path)
pobj = subprocess.Popen([binary_path, "-qx", path], env = env_dict)
pobj.wait()
示例9: set_top_talkers_interval
def set_top_talkers_interval(self, interval):
"""
set_top_talkers_interval(auth, interval) -> None
Set the Top Talkers collection period.
Parameters:
interval (integer) - Interval in hours (must be 24 or 48)
Exceptions:
set_top_talkers_intervalFault - Interval must be 24 or 48 hours
"""
if interval != 24 and interval != 48:
raise ServiceError, 'Top Talkers interval must be 24 or 48 hours'
# convert collection period to snapshot interval (24->300, 48->600)
interval = interval / 24 * 300
code, msg = Mgmt.set(
('/rbt/sport/netflow/config/top_talkers/snapshot_interval',
'duration_sec', interval)
)
if code != 0:
raise ServiceError, msg
示例10: get_stats_internal
def get_stats_internal(self, report_name, num_sets, start_time, end_time,
subclass=None):
start_time = time_to_local_time(start_time)
end_time = time_to_local_time(end_time)
bns = [('time_lb', 'datetime_sec', start_time),
('time_ub', 'datetime_sec', end_time)]
if subclass is not None:
bns.append(('subclass', 'uint32', subclass))
code, msg, bindings = Mgmt.action(
'/stats/actions/generate_report/%s' % report_name,
*bns
)
if code != 0:
raise ServiceError, msg
# save off the file name so we can remove it in self.onReturn()
results = bindings['results']
res = bulk_stats.bsp_to_data_val_sets(results, num_sets)
return res
示例11: get_pfs_stats
def get_pfs_stats(self, start_time, end_time, share_name):
"""
get_pfs_stats(auth, start_time, end_time, share_name) ->
[
[share size],
[bytes received],
[bytes sent]
]
Fetch the system's PFS statistics.
Parameters:
start_time (datetime) - start of the stats query period
end_time (datetime) - end of the stats query period
share_name (string) - share whose stats are desired or 'all' for the
sum of all shares
Exceptions:
get_pfs_statsFault - Datetime not in known format
get_pfs_statsFault - Unknown share name
"""
if share_name == 'all':
share_id = 0
else:
share_id = Mgmt.get_value('/rbt/rcu/share/%s/config/id'
% share_name)
if share_id is None:
raise ServiceError, 'Unknown share name: %s' % share_name
return self.get_stats_internal('pfs', 3,
start_time, end_time, share_id)
示例12: __set_banner
def __set_banner(self, node_list, motd):
"""Helper function for setting motd/login banner"""
nodes_to_set = [(x, 'string', motd) for x in node_list]
code, msg = Mgmt.set(*nodes_to_set)
if code != 0:
raise ServiceError, msg
示例13: check_rbm_permissions
def check_rbm_permissions(node_name, write_needed):
"""
Raises an exception if the user does not have at least the permissions
specified by write_needed for the node specified by node_name.
A questionable interface, but it works well for the SOAP server.
"""
import pwd
username = pwd.getpwuid(os.geteuid())[0]
# XXX/jshilkaitis: a small hack to get around the fact that the RBM
# nodes verify action doesn't do what I want for admin or monitor.
# I should figure out a cleaner way to do this in the future.
if username == 'admin' or username == 'monitor':
return
code, msg, bindings = Mgmt.action('/rbm/action/nodes/verify',
('username', 'string', username),
('nodenames', 'string', node_name))
if code != 0:
raise ServiceError, msg
try:
perms = bindings['permissions']
except:
raise ServiceError, 'Server Error: Unable to authorize current user'
if ((write_needed and perms != 'write') or
(not write_needed and perms != 'write' and perms != 'read')):
# XXX/jshilkaitis: make this match the message returned by the backend
# someday. Same goes for the CLI.
raise ServiceError, "Insufficient permissions for command execution."
示例14: generate_mgmt_event
def generate_mgmt_event(event, reason, version_info):
"""!
Generate Mgmt event.
"""
binding_to_send = None
if event == READY_EVENT:
binding_to_send = ("version_info", "string", version_info)
elif event == DISCONNECTED_EVENT:
binding_to_send = ("reason", "string", reason)
else:
Logging.log(Logging.LOG_ERR, "Unknown event")
# suicide!
sys.exit()
Mgmt.event(event, binding_to_send)
示例15: main
def main():
"""!
Entry point to the watchdog. Initialize logger and starts attempting to
communicate with ESXi
"""
global g_mgmtd_pid
g_mgmtd_pid = None
mgmtd_pids = []
Logging.log_init('esxi_watchdog', 'esxi_watchdog', 0,
Logging.component_id(Logging.LCI_VSP), Logging.LOG_DEBUG,
Logging.LOG_LOCAL0, Logging.LCT_SYSLOG)
Logging.log(Logging.LOG_INFO, "esxi watchdog started")
# Bug 117274: It may happen that we get multiple pids for mgmtd process,
# pidof ran between fork-exec call, retry to allow mgmtd to settle
for i in range(1, MAX_MGMTD_SETTLE_RETRY):
mgmtd_pids = Vsp.get_pids('mgmtd')
if len(mgmtd_pids) > 1:
# multiple pids detected, give mgmtd sometime to settle
time.sleep(MGMTD_SETTLE_TIMEOUT)
else:
g_mgmtd_pid = mgmtd_pids[0]
break
# Bug 112192: monitor mgmtd pid, if mgmtd crashes/exits
# terminate watchdog as well
if g_mgmtd_pid == None:
# mgmtd not up kill watchdog process
Logging.log(Logging.LOG_ERR, "Mgmtd is not ready, kill watchdog!")
sys.exit();
Mgmt.open()
signal.signal(signal.SIGINT, terminate_handler)
signal.signal(signal.SIGTERM, terminate_handler)
signal.signal(signal.SIGQUIT, terminate_handler)
# Invalidate the session file if it exists on startup
if os.path.exists(SESSION_FILE):
os.remove(SESSION_FILE)
monitor_esxi()
Mgmt.close()