本文整理汇总了Python中mmc.support.mmctools.SecurityContext类的典型用法代码示例。如果您正苦于以下问题:Python SecurityContext类的具体用法?Python SecurityContext怎么用?Python SecurityContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SecurityContext类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getContext
def getContext(self):
s = SecurityContext()
s.userid = self.userid
s.locationsCount = ComputerLocationManager().getLocationsCount()
s.userids = ComputerLocationManager().getUsersInSameLocations(self.userid)
s.filterType = "mine"
return s
示例2: purge_removed_computers
def purge_removed_computers():
from mmc.plugins.base.computers import ComputerManager
from mmc.plugins.base import LdapUserGroupControl
# Get all imaging targets
targets = ImagingDatabase().getAllRegisteredComputers()
# Creating root context to query ComputerManager
ctx = SecurityContext()
ctx.userid = 'root'
ctx.userdn = LdapUserGroupControl().searchUserDN(ctx.userid)
# Init to_delete computer list
to_delete = []
for uuid in targets:
if ComputerManager().getComputerCount(ctx, {'uuid': uuid}) == 0:
# If the target computer is not in ComputerManager database anymore
# we unregister it from imaging
to_delete.append(uuid)
# Unregistering orphan targets without backup
if to_delete:
logging.getLogger().info('Orphan imaging computer(s) found')
logging.getLogger().info('Going to purge %s' % ' '.join(to_delete))
computersUnregister(to_delete, False)
return True
示例3: get_machines_update_status
def get_machines_update_status():
"""
Get machine update status as a dict as key
and status string as value.
commons status values :"unknown","up-to-date","need_update","update_available",
"update_planned"
"""
# Creating root context
ctx = SecurityContext()
ctx.userid = 'root'
machines_status = {}
uuids = []
# get computer list who returned update
machines_update = updateDatabase().get_machines()
# get uuid for all computer
ComputerList = ComputerManager().getComputersList(ctx, {}).keys()
uuids = []
for uuid in ComputerList:
uuids.append(int(uuid.lower().replace('uuid', '')))
#get status of all machines
for uuid in uuids:
if uuid in machines_update:
if len(updateDatabase().get_neutral_updates_for_host(uuid)) == 0:
if len(updateDatabase().get_eligible_updates_for_host(uuid)) == 0:
machines_status["UUID" + str(uuid)] = "up-to-date"
else:
machines_status["UUID" + str(uuid)] = "update_planned"
else:
machines_status["UUID" + str(uuid)] = "update_available"
else:
machines_status["UUID" + str(uuid)] = "unknown"
return machines_status
示例4: getSubscriptionInfo
def getSubscriptionInfo():
# Creating root context
ctx = SecurityContext()
ctx.userid = 'root'
# Get all machine count
count = ComputerManager().getComputerCount(ctx)
# Get license max_machines
out, err, ec = runInShell('/usr/sbin/pulse-licensed -G /etc/pulse-licensing/installation_id -l /etc/pulse-licensing/license.dat -p /etc/pulse-licensing/license -i')
if ec == 0:
data = loads(out)
for license in data:
if license['alias'] == 'pulse':
max_machines = int(license['custon_number'])
ts_expiration = int(license['licencingtime'])
break
else:
max_machines = 5
else:
max_machines = 5
if max_machines == 5:
ts_expiration = 0
return [count, max_machines, ts_expiration]
示例5: get_machines_update_status
def get_machines_update_status(not_supported=False):
"""
Get machine update status as a dict as key
and status string as value.
commons status values :"not_supported","not_registered",
"up-to-date","need_update","update_available","update_planned",
"os_update_disabled".
The "not_supported" value can be disabled with not_supported param.
"""
# Creating root context
ctx = SecurityContext()
ctx.userid = 'root'
machines_status = {}
uuids = []
# get computer list who returned update
machines_update = updateDatabase().get_machines()
# get activated os computers:
machines_os_enabled = _get_updatable_computers(ctx, activated=True)
# get disabled os computers:
machines_os_disabled = _get_updatable_computers(ctx, activated=False)
# get uuid for all computer
ComputerList = ComputerManager().getComputersList(ctx, {}).keys()
uuids = []
# convert uuid as string number
for uuid in ComputerList:
uuids.append(int(uuid.lower().replace('uuid', '')))
machines_os_enabled = [
int(uuid.lower().replace('uuid', '')) for uuid in machines_os_enabled]
machines_os_disabled = [
int(uuid.lower().replace('uuid', '')) for uuid in machines_os_disabled]
# get status of all machines
for uuid in uuids:
if uuid in machines_os_disabled:
machines_status["UUID" + str(uuid)] = "os_update_disabled"
elif uuid in machines_os_enabled:
if uuid in machines_update:
# if no neutral update not installed on this machine
if len(updateDatabase().get_neutral_updates_for_host(uuid, 0)) == 0:
# if no eligible update
if len(updateDatabase().get_eligible_updates_for_host(uuid)) == 0:
machines_status["UUID" + str(uuid)] = "up-to-date"
else:
machines_status["UUID" + str(uuid)] = "update_planned"
else:
machines_status["UUID" + str(uuid)] = "update_available"
else:
machines_status["UUID" + str(uuid)] = "not_registered"
elif not_supported:
machines_status["UUID" + str(uuid)] = "not_supported"
return machines_status
示例6: create_update_commands
def create_update_commands():
# TODO: ensure that this method is called by taskmanager
# and not directly by XMLRPC
# Creating root context
ctx = SecurityContext()
ctx.userid = 'root'
# Get active computer manager
computer_manager = ComputerManager().getManagerName()
if computer_manager == 'inventory':
dyngroup_pattern = '%d==inventory::Hardware/OperatingSystem==%s'
elif computer_manager == 'glpi':
dyngroup_pattern = '%d==glpi::Operating system==%s'
else:
logging.getLogger().error(
'Update module: Unsupported computer manager %s' %
computer_manager)
return False
# Get all enabled os_classes
os_classes = updateDatabase().get_os_classes({'filters': {'enabled': 1}})
# Create update command for enabled os_classes
for os_class in os_classes['data']:
patterns = os_class['pattern'].split('||')
request = []
equ_bool = []
for i in xrange(len(patterns)):
request.append(dyngroup_pattern % (i + 1, patterns[i]))
equ_bool.append(str(i + 1))
request = '||'.join(request)
equ_bool = 'OR(%s)' % ','.join(equ_bool)
targets = ComputerManager().getComputersList(
ctx, {
'request': request, 'equ_bool': equ_bool}).keys()
# Fetching all targets
for uuid in targets:
machine_id = int(uuid.lower().replace('uuid', ''))
updates = updateDatabase().get_eligible_updates_for_host(
machine_id)
update_list = [update['uuid'] for update in updates]
# Create update command for this host with update_list
create_update_command(ctx, [uuid], update_list)
return True
示例7: create_update_commands
def create_update_commands():
# TODO: ensure that this method is called by taskmanager
# and not directly by XMLRPC
# Creating root context
ctx = SecurityContext()
ctx.userid = 'root'
targets = _get_updatable_computers(ctx)
# Fetching all targets
for uuid in targets:
machine_id = int(uuid.lower().replace('uuid', ''))
updates = updateDatabase().get_eligible_updates_for_host(
machine_id)
update_list = [update['uuid'] for update in updates]
# Create update command for this host with update_list
create_update_command(ctx, [uuid], update_list)
return True
示例8: _get_updates_for_group
def _get_updates_for_group(params):
"""
Get updates from uuids list if params['uuids'] is a correct list of uuid
and from group if params['gid'] is a correct group id
"""
if 'gid' in params:
params['uuids'] = []
# Creating root context
ctx = SecurityContext()
ctx.userid = 'root'
# get uuid for all computer of this group
ComputerList = ComputerGroupManager().get_group_results(
ctx, params['gid'], 0, -1, {})
for uuid in ComputerList:
params['uuids'].append(int(uuid.lower().replace('uuid', '')))
# get updates for this group
updates = updateDatabase().get_updates_for_group(params)
return updates
示例9: getLicensesCount
def getLicensesCount(vendor, software, version):
ctx = SecurityContext()
ctx.userid = "root"
def replace_splat(param):
if '*' in param:
return param.replace('*', '%')
return param
def check_param(param):
if param == '' or param == '*' or param == '%':
return None
return replace_splat(param)
software = check_param(software)
vendor = check_param(vendor)
version = check_param(version)
if software is None:
software = '%'
return xmlrpcCleanup(Inventory().getAllSoftwaresImproved(ctx,
software,
vendor=vendor,
version=version,
count=1))
示例10: getContext
def getContext(self):
s = SecurityContext()
s.userid = self.userid
return s
示例11: getContext
def getContext(self):
s = SecurityContext()
s.userid = self.userid
s.userdn = LdapUserGroupControl().searchUserDN(self.userid)
return s