Replace subprocess.call with fabric.api.local

Also Puppet hand-weaven SCP and SSH replaced with Fabric.
This commit is contained in:
Przemyslaw Kaminski 2015-06-24 14:20:51 +02:00
parent 26431333b9
commit d1b1c31db9
6 changed files with 14 additions and 17 deletions

View File

@ -12,3 +12,4 @@ enum34==1.0.4
redis==2.10.3 redis==2.10.3
pytest pytest
fakeredis fakeredis
Fabric==1.10.2

View File

@ -18,11 +18,11 @@ On create "golden" resource should be moved to special place
""" """
import click import click
from fabric import api as fabric_api
import json import json
import networkx as nx import networkx as nx
import os import os
import pprint import pprint
import subprocess
import sys import sys
import yaml import yaml
@ -245,7 +245,7 @@ def init_cli_connections():
end_with=end_with) end_with=end_with)
nx.write_dot(g, 'graph.dot') nx.write_dot(g, 'graph.dot')
subprocess.call(['dot', '-Tpng', 'graph.dot', '-o', 'graph.png']) fabric_api.local('dot', '-Tpng', 'graph.dot', '-o', 'graph.png')
# Matplotlib # Matplotlib
#pos = nx.spring_layout(g) #pos = nx.spring_layout(g)

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from fabric import api as fabric_api
import os import os
import subprocess
from solar.core.log import log from solar.core.log import log
from solar.core.handlers.base import BaseHandler from solar.core.handlers.base import BaseHandler
@ -16,8 +16,8 @@ class Ansible(BaseHandler):
log.debug('EXECUTING: %s', ' '.join(call_args)) log.debug('EXECUTING: %s', ' '.join(call_args))
try: try:
subprocess.check_output(call_args) fabric_api.local(' '.join(call_args))
except subprocess.CalledProcessError as e: except Exception as e:
log.error(e.output) log.error(e.output)
log.exception(e) log.exception(e)
raise raise

View File

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import subprocess from fabric import api as fabric_api
from solar.core.handlers.base import BaseHandler from solar.core.handlers.base import BaseHandler
@ -7,4 +7,4 @@ from solar.core.handlers.base import BaseHandler
class Shell(BaseHandler): class Shell(BaseHandler):
def action(self, resource, action_name): def action(self, resource, action_name):
action_file = self._compile_action_file(resource, action_name) action_file = self._compile_action_file(resource, action_name)
subprocess.call(['bash', action_file]) fabric_api.local('bash {}'.format(action_file))

View File

@ -1,7 +1,7 @@
from fabric import api as fabric_api
import os import os
import requests import requests
import StringIO import StringIO
import subprocess
import zipfile import zipfile
from solar import utils from solar import utils
@ -46,7 +46,6 @@ class GitProvider(BaseProvider):
with open('/tmp/git-provider.yaml', 'w') as f: with open('/tmp/git-provider.yaml', 'w') as f:
f.write(""" f.write("""
--- ---
- hosts: all - hosts: all
tasks: tasks:
- git: repo={repository} dest={destination} clone={clone} update=yes - git: repo={repository} dest={destination} clone={clone} update=yes
@ -56,12 +55,9 @@ class GitProvider(BaseProvider):
clone='yes' clone='yes'
)) ))
subprocess.check_call([ fabric_api.local(
'ansible-playbook', 'ansible-playbook -i "localhost," -c local /tmp/git-provider.yaml'
'-i', '"localhost,"', )
'-c', 'local',
'/tmp/git-provider.yaml'
])
class RemoteZipProvider(BaseProvider): class RemoteZipProvider(BaseProvider):

View File

@ -11,8 +11,8 @@ from solar.core import actions
db = get_db() db = get_db()
from dictdiffer import diff, patch, revert from dictdiffer import diff, patch, revert
from fabric import api as fabric_api
import networkx as nx import networkx as nx
import subprocess
def guess_action(from_, to): def guess_action(from_, to):
@ -101,7 +101,7 @@ def execute(res, action):
try: try:
actions.resource_action(res, action) actions.resource_action(res, action)
return state.STATES.success return state.STATES.success
except subprocess.CalledProcessError: except Exception as e:
return state.STATES.error return state.STATES.error