@ -22,12 +22,13 @@ description:
author :
author :
- Andy Hill ( @andyhky )
- Andy Hill ( @andyhky )
- Tim Rupp
- Tim Rupp
- Robin Lee ( @cheese )
options : { }
options : { }
'''
'''
EXAMPLES = '''
EXAMPLES = '''
- name : Gather facts from xenserver
- name : Gather facts from xenserver
xenserver :
xenserver _facts :
- name : Print running VMs
- name : Print running VMs
debug :
debug :
@ -91,11 +92,8 @@ def get_xenapi_session():
def get_networks ( session ) :
def get_networks ( session ) :
recs = session . xenapi . network . get_all_records ( )
recs = session . xenapi . network . get_all_records ( )
xs_networks = { }
networks = change_keys ( recs , key = ' name_label ' )
networks = change_keys ( recs , key = ' uuid ' )
return networks
for network in networks . values ( ) :
xs_networks [ network [ ' name_label ' ] ] = network
return xs_networks
def get_pifs ( session ) :
def get_pifs ( session ) :
@ -132,6 +130,13 @@ def change_keys(recs, key='uuid', filter_func=None):
if filter_func is not None and not filter_func ( rec ) :
if filter_func is not None and not filter_func ( rec ) :
continue
continue
for param_name , param_value in rec . items ( ) :
# param_value may be of type xmlrpc.client.DateTime,
# which is not simply convertable to str.
# Use 'value' attr to get the str value,
# following an example in xmlrpc.client.DateTime document
if hasattr ( param_value , " value " ) :
rec [ param_name ] = param_value . value
new_recs [ rec [ key ] ] = rec
new_recs [ rec [ key ] ] = rec
new_recs [ rec [ key ] ] [ ' ref ' ] = ref
new_recs [ rec [ key ] ] [ ' ref ' ] = ref
@ -146,26 +151,19 @@ def get_host(session):
def get_vms ( session ) :
def get_vms ( session ) :
xs_vms = { }
recs = session . xenapi . VM . get_all_records ( )
recs = session . xenapi . VM . get_all ( )
if not recs :
if not recs :
return None
return None
vms = change_keys ( recs , key = ' name_label ' )
vms = change_keys ( recs , key = ' uuid ' )
return vms
for vm in vms . values ( ) :
xs_vms [ vm [ ' name_label ' ] ] = vm
return xs_vms
def get_srs ( session ) :
def get_srs ( session ) :
xs_srs = { }
recs = session . xenapi . SR . get_all_records ( )
recs = session . xenapi . SR . get_all ( )
if not recs :
if not recs :
return None
return None
srs = change_keys ( recs , key = ' uuid ' )
srs = change_keys ( recs , key = ' name_label ' )
for sr in srs . values ( ) :
return srs
xs_srs [ sr [ ' name_label ' ] ] = sr
return xs_srs
def main ( ) :
def main ( ) :
@ -204,7 +202,7 @@ def main():
if xs_srs :
if xs_srs :
data [ ' xs_srs ' ] = xs_srs
data [ ' xs_srs ' ] = xs_srs
module . exit_json ( ansible = data )
module . exit_json ( ansible _facts = data )
if __name__ == ' __main__ ' :
if __name__ == ' __main__ ' :