Get login information for a host `hostip` (ipv4) from marvin's `config` @return the tuple username, password for the host else raise keyerror
(config, hostip)
| 215 | ) |
| 216 | |
| 217 | def get_host_credentials(config, hostip): |
| 218 | """Get login information for a host `hostip` (ipv4) from marvin's `config` |
| 219 | |
| 220 | @return the tuple username, password for the host else raise keyerror""" |
| 221 | for zone in config.zones: |
| 222 | for pod in zone.pods: |
| 223 | for cluster in pod.clusters: |
| 224 | for host in cluster.hosts: |
| 225 | if str(host.url).startswith('http'): |
| 226 | hostname = urllib.parse.urlsplit(str(host.url)).netloc |
| 227 | else: |
| 228 | hostname = str(host.url) |
| 229 | try: |
| 230 | if socket.getfqdn(hostip) == socket.getfqdn(hostname): |
| 231 | return host.username, host.password |
| 232 | except socket.error as e: |
| 233 | raise Exception("Unresolvable host %s error is %s" % (hostip, e)) |
| 234 | raise KeyError("Please provide the marvin configuration file with credentials to your hosts") |
| 235 | |
| 236 | def execute_command_in_host(hostip, port, username, password, command, hypervisor=None): |
| 237 | timeout = _configure_timeout(hypervisor) |
no outgoing calls