|
11 | 11 | from cf_remote import paths |
12 | 12 | from cf_remote.utils import whoami, read_json |
13 | 13 | from cf_remote.aramid import ExecutionResult |
14 | | -from cf_remote.paths import SSH_CONFIG_FPATH, SSH_CONFIGS_JSON_FPATH |
| 14 | +from cf_remote.paths import SSH_CONFIG_FPATH, SSH_CONFIGS_JSON_FPATH, CLOUD_STATE_FPATH |
15 | 15 |
|
16 | 16 |
|
17 | 17 | class LocalConnection: |
@@ -77,8 +77,8 @@ def __init__(self, host, user, connect_kwargs=None, port=aramid._DEFAULT_SSH_POR |
77 | 77 | % " ".join(control_master_args) |
78 | 78 | ) |
79 | 79 | self._ssh_control_master = subprocess.Popen( |
80 | | - control_master_args, |
81 | | - ) # stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) |
| 80 | + control_master_args, stderr=subprocess.DEVNULL # stdout=subprocess.DEVNULL, |
| 81 | + ) |
82 | 82 |
|
83 | 83 | self.needs_sudo = self.run("echo $UID", hide=True).stdout.strip() != "0" |
84 | 84 | log.debug("Connection initialized") |
@@ -129,17 +129,34 @@ def _build_ssh_config(): |
129 | 129 | f.write(config) |
130 | 130 |
|
131 | 131 |
|
| 132 | +def host_is_vagrant(host): |
| 133 | + |
| 134 | + config = read_json(CLOUD_STATE_FPATH) |
| 135 | + |
| 136 | + if config is None: |
| 137 | + return False |
| 138 | + |
| 139 | + for group in config.values(): |
| 140 | + for curr_host in group.keys(): |
| 141 | + if curr_host == host and group["meta"]["provider"] == "vagrant": |
| 142 | + return True |
| 143 | + |
| 144 | + return False |
| 145 | + |
| 146 | + |
132 | 147 | def connect(host, users=None): |
133 | 148 | log.debug("Connecting to '%s'" % host) |
134 | 149 | log.debug("users= '%s'" % users) |
135 | 150 |
|
136 | | - log.debug("Building config file") |
137 | | - |
138 | 151 | parts = urlparse("ssh://%s" % host) |
139 | 152 | host = parts.hostname |
140 | 153 | if not users and parts.username: |
141 | 154 | users = [parts.username] |
142 | 155 | port = parts.port or aramid._DEFAULT_SSH_PORT |
| 156 | + |
| 157 | + if host_is_vagrant(host): |
| 158 | + users = ["vagrant"] |
| 159 | + |
143 | 160 | if not users: |
144 | 161 | users = [ |
145 | 162 | "Administrator", |
@@ -179,6 +196,7 @@ def connect(host, users=None): |
179 | 196 | # and connection should be a keyword argument with default None |
180 | 197 | # Uses a context manager (with) to ensure connections are closed |
181 | 198 | def auto_connect(func): |
| 199 | + log.debug("Building config file") |
182 | 200 | _build_ssh_config() |
183 | 201 |
|
184 | 202 | def connect_wrapper(host, *args, **kwargs): |
|
0 commit comments