I am trying to use VIProperty in pysphere but I am getting 'str' object has no attribute 'typecode' .
Code:
for h, mor in server.get_hosts().items():
if mor == 'xxx.com':
prop = VIProperty(server, mor)
Error:
Traceback (most recent call last):
File "teardown.py", line 29, in <module>
prop = VIProperty(server, mor)
File "/usr/local/lib/python2.7/dist-packages/pysphere/vi_property.py", line 38, in __init__
self._type = obj.typecode.type[1]
AttributeError: 'str' object has no attribute 'typecode'
works currect because "mor" stil string type and 'str' object has no attribute 'typecode' .
class VIProperty(object):
def __init__(self, server, obj):
self._server = server
self._obj = obj
self._values_set = False
self._type = obj.typecode.type[1]
your call method:
for h, mor in server.get_hosts().items():
if mor == 'xxx.com':
print type(mor) # <<<< 'str'
prop = VIProperty(server, mor)
try that:
hosts = server.get_hosts()
for hmor, hname in hosts.items():
if hname == 'xxx.com':
p = VIProperty(server, hmor)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.