3 # Copyright (c) 2016 Orange and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Usage example (note: Fuel actually uses key-based auth, not user/pass):
11 # from opnfv.utils.Credentials import Credentials as credentials
12 # credentials("fuel", "10.20.0.2", "user", "password").fetch('./openrc')
17 import opnfv.installer_adapters.InstallerHandler as ins_handler
18 import opnfv.utils.Connection as con
19 import opnfv.utils.OPNFVLogger as logger
22 class Credentials(object):
24 def __init__(self, installer, ip, user, password=None):
25 self.installer = installer
27 self.logger = logger.Logger("Credentials", level="DEBUG").getLogger()
28 self.connection = con.Connection()
30 if self.__check_installer_name(self.installer) != os.EX_OK:
31 self.logger.error("Installer %s not supported!" % self.installer)
34 self.logger.debug("Installer %s supported." % self.installer)
36 if self.connection.verify_connectivity(self.ip) != os.EX_OK:
37 self.logger.error("Installer %s not reachable!" % self.ip)
38 return os.EX_UNAVAILABLE
40 self.logger.debug("IP %s is reachable!" % self.ip)
43 "Trying to stablish ssh connection to %s ..." % self.ip)
44 self.handler = ins_handler.InstallerHandler(installer,
49 def __check_installer_name(self, installer):
50 if installer not in ("apex", "compass", "daisy", "fuel", "joid"):
55 def __check_path(self, path):
64 def __fetch_creds_apex(self, target_path):
68 def __fetch_creds_compass(self, target_path):
72 def __fetch_creds_daisy(self, target_path):
76 def __fetch_creds_fuel(self, target_path):
80 def __fetch_creds_joid(self, target_path):
84 def fetch(self, target_path):
85 if self.__check_path(target_path) != os.EX_OK:
87 "Target path %s does not exist!" % target_path)
90 self.logger.debug("Target path correct.")
92 self.logger.info("Fetching credentials from the deployment...")
93 if self.installer == "apex":
94 self.__fetch_creds_apex(target_path)
95 elif self.installer == "compass":
96 self.__fetch_creds_compass(target_path)
97 elif self.installer == "daisy":
98 self.__fetch_creds_daisy(target_path)
99 elif self.installer == "fuel":
100 self.__fetch_creds_fuel(target_path)
101 elif self.installer == "joid":
102 self.__fetch_creds_joid(target_path)