mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-22 20:13:59 -07:00
pep8 fixes for contrib (#24344)
This commit is contained in:
parent
c7ae6b9fd5
commit
d3249e7875
37 changed files with 326 additions and 380 deletions
|
@ -16,20 +16,21 @@
|
|||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import sys
|
||||
from subprocess import Popen,PIPE
|
||||
from subprocess import Popen, PIPE
|
||||
|
||||
try:
|
||||
import json
|
||||
except ImportError:
|
||||
import simplejson as json
|
||||
|
||||
|
||||
class SetEncoder(json.JSONEncoder):
|
||||
def default(self, obj):
|
||||
if isinstance(obj, set):
|
||||
return list(obj)
|
||||
return json.JSONEncoder.default(self, obj)
|
||||
|
||||
VBOX="VBoxManage"
|
||||
VBOX = "VBoxManage"
|
||||
|
||||
|
||||
def get_hosts(host=None):
|
||||
|
@ -39,7 +40,7 @@ def get_hosts(host=None):
|
|||
if host:
|
||||
p = Popen([VBOX, 'showvminfo', host], stdout=PIPE)
|
||||
else:
|
||||
returned = { 'all': set(), '_metadata': {} }
|
||||
returned = {'all': set(), '_metadata': {}}
|
||||
p = Popen([VBOX, 'list', '-l', 'vms'], stdout=PIPE)
|
||||
except:
|
||||
sys.exit(1)
|
||||
|
@ -50,7 +51,7 @@ def get_hosts(host=None):
|
|||
for line in p.stdout.readlines():
|
||||
|
||||
try:
|
||||
k,v = line.split(':',1)
|
||||
k, v = line.split(':', 1)
|
||||
except:
|
||||
continue
|
||||
|
||||
|
@ -62,11 +63,11 @@ def get_hosts(host=None):
|
|||
if v not in hostvars:
|
||||
curname = v
|
||||
hostvars[curname] = {}
|
||||
try: # try to get network info
|
||||
x = Popen([VBOX, 'guestproperty', 'get', curname,"/VirtualBox/GuestInfo/Net/0/V4/IP"],stdout=PIPE)
|
||||
try: # try to get network info
|
||||
x = Popen([VBOX, 'guestproperty', 'get', curname, "/VirtualBox/GuestInfo/Net/0/V4/IP"], stdout=PIPE)
|
||||
ipinfo = x.stdout.read()
|
||||
if 'Value' in ipinfo:
|
||||
a,ip = ipinfo.split(':',1)
|
||||
a, ip = ipinfo.split(':', 1)
|
||||
hostvars[curname]['ansible_ssh_host'] = ip.strip()
|
||||
except:
|
||||
pass
|
||||
|
@ -83,11 +84,11 @@ def get_hosts(host=None):
|
|||
returned['all'].add(curname)
|
||||
continue
|
||||
|
||||
pref_k = 'vbox_' + k.strip().replace(' ','_')
|
||||
pref_k = 'vbox_' + k.strip().replace(' ', '_')
|
||||
if k.startswith(' '):
|
||||
if prevkey not in hostvars[curname]:
|
||||
hostvars[curname][prevkey] = {}
|
||||
hostvars[curname][prevkey][pref_k]= v
|
||||
hostvars[curname][prevkey][pref_k] = v
|
||||
else:
|
||||
if v != '':
|
||||
hostvars[curname][pref_k] = v
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue