CLOUDSTACK-4608: Resolve the hostname to fqdn from marvin config

In case the marvin configuration does not contain fqdn information fetch
and compare the fqdns of hostip from `cloud`.`host` with the fqdn
available on the client.

Signed-off-by: Prasanna Santhanam <tsp@apache.org>
This commit is contained in:
Prasanna Santhanam 2013-09-09 11:41:13 +05:30
parent b11a8e12e8
commit 433d5839a1
1 changed files with 13 additions and 4 deletions

View File

@ -25,6 +25,8 @@ import string
import random
import imaplib
import email
import socket
import urlparse
import datetime
from marvin.cloudstackAPI import *
from marvin.remoteSSHClient import remoteSSHClient
@ -154,16 +156,23 @@ def fetch_api_client(config_file='datacenterCfg'):
)
)
def get_host_credentials(config, hostname):
"""Get login information for a host `hostname` from marvin's `config`
def get_host_credentials(config, hostip):
"""Get login information for a host `hostip` (ipv4) from marvin's `config`
@return the tuple username, password for the host else raise keyerror"""
for zone in config.zones:
for pod in zone.pods:
for cluster in pod.clusters:
for host in cluster.hosts:
if str(host.url).find(str(hostname)) > 0:
return host.username, host.password
if str(host.url).startswith('http'):
hostname = urlparse.urlsplit(str(host.url)).netloc
else:
hostname = str(host.url)
try:
if socket.getfqdn(hostip) == socket.getfqdn(hostname):
return host.username, host.password
except socket.error, e:
raise Exception("Unresolvable host %s error is %s" % (hostip, e))
raise KeyError("Please provide the marvin configuration file with credentials to your hosts")