Пример #1
0
 def connection(self, host, port, user, password, ssl=False, **kwargs):
     # must set X-Requested-By in newer versions of Ambari
     self.x_requested_by = user
     if user == 'admin':
         self.x_requested_by = os.getenv('USER', user)
     #log.info("contacting Ambari as '%s'" % self.user)
     if not isHost(host) or not isPort(port) or not isUser(user) or not password:
         raise InvalidOptionException('invalid options passed to AmbariBlueprint()')
     proto = 'http' # pylint: disable=unused-variable
     if ssl:
         proto = 'https'
     self.host = host
     self.port = port
     self.user = user
     self.password = password
     # if kwargs.has_key('strip_config') and kwargs['strip_config']:
     if 'strip_config' in kwargs and kwargs['strip_config']:
         self.strip_config = True
     self.url_base = '%(proto)s://%(host)s:%(port)s/api/v1' % locals()
     if 'dir' in kwargs and kwargs['dir']:
         self.blueprint_dir = kwargs['dir']
     if not isDirname(self.blueprint_dir):
         qquit('UNKNOWN', 'invalid dir arg passed to AmbariBlueprintTool')
     try:
         if not self.blueprint_dir or not os.path.exists(self.blueprint_dir):
             log.info("creating blueprint data dir '%s'" % self.blueprint_dir)
             os.mkdir(self.blueprint_dir)
         if not os.path.isdir(self.blueprint_dir):
             raise IOError("blueprint dir '%s'already taken and is not a directory" % self.blueprint_dir)
     except IOError as _:
         die("'failed to create dir '%s': %s" % (self.blueprint_dir, _))
Пример #2
0
 def connection(self, host, port, user, password, ssl=False, **kwargs):
     # must set X-Requested-By in newer versions of Ambari
     self.x_requested_by = user
     if user == 'admin':
         self.x_requested_by = os.getenv('USER', user)
     #log.info("contacting Ambari as '%s'" % self.user)
     if not isHost(host) or not isPort(port) or not isUser(user) or not password:
         raise InvalidOptionException('invalid options passed to AmbariBlueprint()')
     proto = 'http' # pylint: disable=unused-variable
     if ssl:
         proto = 'https'
     self.host = host
     self.port = port
     self.user = user
     self.password = password
     # if kwargs.has_key('strip_config') and kwargs['strip_config']:
     if 'strip_config' in kwargs and kwargs['strip_config']:
         self.strip_config = True
     self.url_base = '%(proto)s://%(host)s:%(port)s/api/v1' % locals()
     if 'dir' in kwargs and kwargs['dir']:
         self.blueprint_dir = kwargs['dir']
     if not isDirname(self.blueprint_dir):
         qquit('UNKNOWN', 'invalid dir arg passed to AmbariBlueprintTool')
     try:
         if not self.blueprint_dir or not os.path.exists(self.blueprint_dir):
             log.info("creating blueprint data dir '%s'" % self.blueprint_dir)
             os.mkdir(self.blueprint_dir)
         if not os.path.isdir(self.blueprint_dir):
             raise IOError("blueprint dir '%s'already taken and is not a directory" % self.blueprint_dir)
     except IOError as _:
         die("'failed to create dir '%s': %s" % (self.blueprint_dir, _))
Пример #3
0
 def add_hostoption(self, name=None, default_host=None, default_port=None):
     name2 = ''
     # if isList(name):
     #     name2 = '%s ' % name[0]
     # elif not isBlankOrNone(name):
     if name is None:
         name = ''
     # because can't reference name=self.name in def
     if not name:
         # pylint will fail if you use these directly as it tries to resolve them
         if 'name' in self.__dict__ and getattr(self, 'name'):
             name = getattr(self, 'name')
         elif 'software' in self.__dict__ and getattr(self, 'software'):
             name = getattr(self, 'software')
     if not default_host and 'default_host' in self.__dict__ and getattr(
             self, 'default_host'):
         default_host = getattr(self, 'default_host')
     if not default_port and 'default_port' in self.__dict__ and getattr(
             self, 'default_port'):
         default_port = getattr(self, 'default_port')
     if not isBlankOrNone(name):
         if isList(name):
             name2 = '{0} '.format(name[0])
         else:
             name2 = '{0} '.format(name)
     if default_host is not None and not isHost(default_host):
         raise CodingError(
             'invalid default host supplied to add_hostoption()')
     if default_port is not None and not isPort(default_port):
         raise CodingError(
             'invalid default port supplied to add_hostoption()')
     (host_envs_help, default_host) = getenvs2(my_vars='HOST',
                                               default=default_host,
                                               name=name)
     (port_envs_help, default_port) = getenvs2(my_vars='PORT',
                                               default=default_port,
                                               name=name)
     self.add_opt('-H',
                  '--host',
                  dest='host',
                  help='%sHost (%s)' % (name2, host_envs_help),
                  default=default_host)
     self.add_opt('-P',
                  '--port',
                  dest='port',
                  help='%sPort (%s)' % (name2, port_envs_help),
                  default=default_port)