此内容没有您所选择的语言版本。

Chapter 2. Examples


The following sections demonstrate Red Hat Satellite API usage using different programming languages and their respective XML-RPC requests.

2.1. Python Examples

The following example demonstrates the user.listUsers call. The example prints the name of each group.
#!/usr/bin/python
import xmlrpclib

SATELLITE_URL = "http://satellite.example.com/rpc/api"
SATELLITE_LOGIN = "username"
SATELLITE_PASSWORD = "password"

client = xmlrpclib.Server(SATELLITE_URL, verbose=0)

key = client.auth.login(SATELLITE_LOGIN, SATELLITE_PASSWORD)
list = client.user.list_users(key)
for user in list:
   print user.get('login')

client.auth.logout(key)
Copy to Clipboard Toggle word wrap
The following example shows how to use date-time parameters. This code schedules the installation of package rhnlib-2.5.22.9.el6.noarch to system with id 1000000001.
#!/usr/bin/python
from datetime import datetime
import time
import xmlrpclib

SATELLITE_URL = "http://satellite.example.com/rpc/api"
SATELLITE_LOGIN = "username"
SATELLITE_PASSWORD = "password"

client = xmlrpclib.Server(SATELLITE_URL, verbose=0)

key = client.auth.login(SATELLITE_LOGIN, SATELLITE_PASSWORD)
package_list = client.packages.findByNvrea(key, 'rhnlib', '2.5.22', '9.el6', '', 'noarch')
today = datetime.today()
earliest_occurrence = xmlrpclib.DateTime(today)
client.system.schedulePackageInstall(key, 1000000001, package_list[0]['id'], earliest_occurrence)

client.auth.logout(key)

Copy to Clipboard Toggle word wrap
The following example show how to check channels for their last synchronization:
#!/usr/bin/python
import xmlrpclib

SATELLITE_URL = "http://sat57.example.com/rpc/api"
SATELLITE_LOGIN = "admin"
SATELLITE_PASSWORD = "Redhat123"

client = xmlrpclib.Server(SATELLITE_URL, verbose=0)

key = client.auth.login(SATELLITE_LOGIN, SATELLITE_PASSWORD)
list = client.channel.listAllChannels(key)

for item in list:
  details = client.channel.software.getDetails(key, item['label'])
  print item
  print details
  print "Name: " + details['name']
  try:
    print "Last Sync: " + details['yumrepo_last_sync']
  except:
    print "Last Sync: Never"

client.auth.logout(key)
Copy to Clipboard Toggle word wrap
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat