本文整理汇总了Python中stratuslab.Util类的典型用法代码示例。如果您正苦于以下问题:Python Util类的具体用法?Python Util怎么用?Python Util使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Util类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _generateOpensslConfig
def _generateOpensslConfig(self):
config = """
[ req ]
distinguished_name = req_distinguished_name
x509_extensions = v3_ca
prompt = no
input_password = %(certPassword)s
output_password = %(certPassword)s
dirstring_type = nobmp
[ req_distinguished_name ]
C = EU
O = StratusLab Project
OU = Testing Department
CN = %(commonName)s
[ v3_ca ]
basicConstraints = CA:false
nsCertType=client, email, objsign
keyUsage=critical, digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment, keyAgreement
subjectKeyIdentifier=hash
authorityKeyIdentifier=keyid:always,issuer:always
subjectAltName=email:%(subjectEmail)s
""" % self.configHolder.options
conf_filename = os.path.join(self.tmp_dir, 'openssl.cfg')
open(conf_filename, 'w').write(config)
Util.printDetail("Generated openssl configuration in: %s" % conf_filename,
self.configHolder.verboseLevel)
Util.printDetail("Openssl configuration: %s" % open(conf_filename).read(),
self.configHolder.verboseLevel,
Util.VERBOSE_LEVEL_DETAILED)
示例2: testfilePutGetContentUnicode
def testfilePutGetContentUnicode(self):
_, filename = tempfile.mkstemp()
try:
Util.filePutContent(filename, unicode('Élément', encoding='utf8'))
assert 'Élément' == Util.fileGetContent(filename)
finally:
os.unlink(filename)
示例3: _validateParameters
def _validateParameters(self):
Util.printStep('Validating parameters')
if not self.registrationLdapScheme:
raise ValidationException('registration_ldap_scheme is not defined')
if not self.registrationLdapHost:
raise ValidationException('registration_ldap_host is not defined')
if not self.registrationLdapPort:
raise ValidationException('registration_ldap_port is not defined')
if not self.registrationLdapManagerDn:
raise ValidationException('registration_ldap_manager_dn is not defined')
if not self.registrationLdapManagerPassword:
raise ValidationException('registration_ldap_manager_password is not defined')
if not self.registrationAdminEmail:
raise ValidationException('registration_admin_email is not defined')
if not self.registrationMailHost:
raise ValidationException('registration_mail_host is not defined')
if not self.registrationMailPort:
raise ValidationException('registration_mail_port is not defined')
if not self.registrationMailUser:
raise ValidationException('registration_mail_user is not defined')
if not self.registrationMailPassword:
raise ValidationException('registration_mail_password is not defined')
if not self.registrationMailSsl:
raise ValidationException('registration_mail_ssl is not defined')
if not self.registrationMailDebug:
raise ValidationException('registration_mail_debug is not defined')
if not self.registrationSslTruststore:
self.registrationSslTruststore = ''
示例4: testfilePutGetContentStr
def testfilePutGetContentStr(self):
_, filename = tempfile.mkstemp()
try:
Util.filePutContent(filename, str('Element'))
assert 'Element' == Util.fileGetContent(filename)
finally:
os.unlink(filename)
示例5: _shutdownNode
def _shutdownNode(self):
if self.shutdownVm:
self._stopMachine()
else:
self._printStep('Machine ready for use')
msg = '\n\tMachine IP: %s\tRemember to stop the machine when finished' % self.vmIp
Util.printInfo(msg)
示例6: addNetworkAcl
def addNetworkAcl(self, users, net_id_int, rights):
"""
users - hex
net_id_int - integer, network ID
rights - hex
"""
# "magic" number
_magic = self.ACL_USERS['UID']
net_resource = hex(self.ACL_RESOURCES['NET'] + _magic + net_id_int)
# Hack to retry on SSL errors
maxRetries = 3
retries = 0
while True:
try:
ret, info, _ = self._rpc.one.acl.addrule(self._sessionString,
users,
net_resource,
rights)
break
except ssl.SSLError as e:
retries += 1
t = strftime("%Y-%m-%d %H:%M:%S", gmtime())
Util.printDetail('SSL ERROR ENCOUNTERED (%s): %s' % (t, str(e)))
if retries >= maxRetries:
raise e
if not ret:
raise OneException(info)
return info
示例7: _killMachine
def _killMachine(self):
self._printStep('Killing machine')
if self.vmId:
self.cloud.vmKill(self.vmId)
else:
Util.printWarning('Undefined VM ID, when trying to kill machine.')
示例8: listVms
def listVms(self, showVmsFromAllUsers=False):
fromAllUsers = -2
currentUserOnly = -3
if showVmsFromAllUsers:
visibilitySwitch = fromAllUsers
else:
visibilitySwitch = currentUserOnly
# Hack to retry on SSL errors.
maxRetries = 3
retries = 0
while True:
try:
ret, info, _ = self._rpc.one.vmpool.info(self._sessionString, visibilitySwitch, -1, -1, -1)
break
except ssl.SSLError as e:
retries += 1
t = strftime("%Y-%m-%d %H:%M:%S", gmtime())
Util.printDetail('SSL ERROR ENCOUNTERED (%s): %s' % (t, str(e)))
if retries >= maxRetries:
raise e
if not ret:
raise OneException(info)
vmlist = Util.etree_from_text(info)
for xml in vmlist.findall('VM'):
self._addStateSummary(xml)
return etree.tostring(vmlist)
示例9: _configureNetworkInterface
def _configureNetworkInterface(self, device, ip, netmask):
deviceConf = '/etc/sysconfig/network-scripts/ifcfg-%s' % device
data = """DEVICE=%s
IPADDR=%s
NETMASK=%s
""" % (device, ip, netmask)
Util.filePutContent(deviceConf, data)
示例10: _remoteFileAppendContents
def _remoteFileAppendContents(self, filename, data):
data = Util.escapeDoubleQuotes(data, times=4)
rc, output = self._nodeShell('"echo \\"%s\\" >> %s"' % (data, filename),
withOutput=True, shell=True)
if rc != 0:
Util.printError("Failed to append to %s\n%s" % (filename, output))
示例11: _configureSudo
def _configureSudo(self):
Util.appendOrReplaceInFile(self.sudoersFilePath,
'Defaults:%s !requiretty' % self.cloudUsername,
'Defaults:%s !requiretty' % self.cloudUsername)
Util.appendOrReplaceInFile(self.sudoersFilePath,
'%s ALL= NOPASSWD: %s' % (self.cloudUsername, self.firewall.binary),
'%s ALL= NOPASSWD: %s' % (self.cloudUsername, self.firewall.binary))
示例12: doWork
def doWork(self):
# checking marketplace endpoint URL
url_is_ok = Util.checkUrlExists(ENDPOINT_MKP, 30)
if url_is_ok is True:
req = urllib2.Request(ENDPOINT_MKP)
response = urllib2.urlopen(req)
content = response.read()
xml = Util.etree_from_text(content)
desc_nodes = xml.iter("{" + RDF + "}Description")
all_desc = []
desc = {}
for desc_node in desc_nodes:
desc["description"] = desc_node.find('{' + DCTERMS + '}description').text
desc["identifier"] = desc_node.find('{' + DCTERMS + '}identifier').text
desc["creator"] = desc_node.find('{' + DCTERMS + '}creator').text
desc["created"] = desc_node.find('{' + DCTERMS + '}created').text
desc["os"] = desc_node.find('{' + SLTERMS + '}os').text
desc["os-version"] = desc_node.find('{' + SLTERMS + '}os-version').text
desc["os-arch"] = desc_node.find('{' + SLTERMS + '}os-arch').text
# cast in str for NoneType object (otherwise, we should use try/Except)
print "Description: " + str(desc["description"])
print "ID: " + str(desc["identifier"])
print "OS: " + str(desc["os"]), str(desc["os-version"]), "| Arch: " + str(desc["os-arch"])
print "Creator: " + str(desc["creator"])
print "Created at: " + str(desc["created"].replace("Z", "").split('T'))
print "####\n"
all_desc.append(desc)
示例13: _lcmStateToString
def _lcmStateToString(self):
lcm = self._lcmStateAsInt()
if (lcm is not None) and (lcm >= 0) and (lcm < len(self.lcmStateDefintion)):
return self.lcmStateDefintion[lcm]
else:
Util.printError('Invalid state: %s' % lcm, exit=False)
return self.invalidState
示例14: _configureVirtualNetInterface
def _configureVirtualNetInterface(self, device, ip, netmask):
device = device + ":privlan"
Util.printDetail("Configuring network interface %s." % device)
self._configureNetworkInterface(device, ip, netmask)
Util.printDetail("Starting network interface %s." % device)
self.executeCmd(["ifup", device])
示例15: _installPackages
def _installPackages(self):
Util.printStep('Removing CIMI server package')
cmd = 'yum erase -y %s' % self._package
self._executeExitOnError(cmd)
Util.printStep('Installing CIMI server package')
cmd = 'yum install --nogpgcheck -y %s' % self._package
self._executeExitOnError(cmd)