Ejemplo n.º 1
0
 def test_instantiation_via_nested_dict_with_tuples(self):
     pn = utils.PseudoNamespace(
         dict(one=(dict(two=2),
                   dict(
                       three=dict(four=4, five=(dict(six=6),
                                                dict(seven=7)))))))
     assert pn.one[1].three.five[1].seven == 7
Ejemplo n.º 2
0
Archivo: client.py Proyecto: zhl003/awx
    def connect(self):
        """Fetch top-level resources from /api/v2"""
        config.base_url = self.get_config('host')
        config.client_connection_attempts = 1
        config.assume_untrusted = False
        if self.get_config('insecure'):
            config.assume_untrusted = True

        config.credentials = utils.PseudoNamespace({
            'default': {
                'username': self.get_config('username'),
                'password': self.get_config('password'),
            }
        })

        _, remainder = self.parser.parse_known_args()
        if remainder and remainder[0] == 'config':
            # the config command is special; it doesn't require
            # API connectivity
            return
        # ...otherwise, set up a awxkit connection because we're
        # likely about to do some requests to /api/v2/
        self.root = api.Api()
        try:
            self.fetch_version_root()
        except RequestException:
            # If we can't reach the API root (this usually means that the
            # hostname is wrong, or the credentials are wrong)
            if self.help:
                # ...but the user specified -h...
                known, unknown = self.parser.parse_known_args(self.argv)
                if len(unknown) == 1 and os.path.basename(unknown[0]) == 'awx':
                    return
            raise
Ejemplo n.º 3
0
 def test_update_with_nested_dict(self):
     pn = utils.PseudoNamespace()
     pn.update(dict(one=1, two=2, three=3), four=4, five=5)
     assert pn.one == 1
     assert pn.four == 4
     assert pn == dict(one=1, two=2, three=3, four=4, five=5)
     assert len(pn.keys()) == 5
Ejemplo n.º 4
0
 def test_instantiation_via_nested_dict(self):
     pn = utils.PseudoNamespace(dict(one=1, two=2),
                                three=dict(four=4, five=dict(six=6)))
     assert pn.one == 1
     assert pn.three.four == 4
     assert pn.three.five.six == 6
     assert pn == dict(one=1, two=2, three=dict(four=4, five=dict(six=6)))
Ejemplo n.º 5
0
 def test_update_with_nested_dict_with_lists(self):
     pn = utils.PseudoNamespace()
     pn.update(
         dict(one=[
             dict(two=2),
             dict(three=dict(four=4, five=[dict(
                 six=6), dict(seven=7)]))
         ]))
     assert pn.one[1].three.five[1].seven == 7
Ejemplo n.º 6
0
def main():
    exc = None
    try:
        global akit_args
        akit_args = parse_args()
        config.base_url = akit_args.base_url

        if akit_args.credential_file != utils.not_provided:
            config.credentials = utils.load_credentials(
                akit_args.credential_file)
        else:
            config.credentials = utils.PseudoNamespace({
                'default': {
                    'username': os.getenv('AWXKIT_USER', 'admin'),
                    'password': os.getenv('AWXKIT_USER_PASSWORD', 'password')
                }
            })

        if akit_args.project_file != utils.not_provided:
            config.project_urls = utils.load_projects(
                akit_args.project_file)

        global root
        root = api.Api()
        if uses_sessions(root.connection):
            config.use_sessions = True
            root.load_session().get()
        else:
            root.load_authtoken().get()

        if 'v2' in root.available_versions:
            global v2
            v2 = root.available_versions.v2.get()

        rc = 0
        if akit_args.akit_script:
            try:
                exec(open(akit_args.akit_script).read(), globals())
            except Exception as e:
                exc = e
                raise exc
    except Exception as e:
        exc = e
        rc = 1

    if akit_args.non_interactive:
        if exc:
            traceback.print_exc(exc)
        os._exit(rc)

    if exc:
        raise exc
Ejemplo n.º 7
0
    def connect(self):
        """Fetch top-level resources from /api/v2"""
        config.base_url = self.get_config('host')
        config.client_connection_attempts = 1
        config.assume_untrusted = False
        if self.get_config('insecure'):
            config.assume_untrusted = True

        config.credentials = utils.PseudoNamespace({
            'default': {
                'username': self.get_config('username'),
                'password': self.get_config('password'),
            }
        })

        _, remainder = self.parser.parse_known_args()
        if remainder and remainder[0] == 'config':
            # the config command is special; it doesn't require
            # API connectivity
            return
        # ...otherwise, set up a awxkit connection because we're
        # likely about to do some requests to /api/v2/
        self.root = api.Api()
        self.fetch_version_root()
Ejemplo n.º 8
0
 def test_instantiation_via_nested_dict_with_tuple(self):
     pn = utils.PseudoNamespace(dict(one=(dict(two=2), dict(three=3))))
     assert pn.one[0].two == 2
     assert pn.one[1].three == 3
     assert pn == dict(one=(dict(two=2), dict(three=3)))
Ejemplo n.º 9
0
 def test_instantiation_via_dict_and_kwargs(self):
     pn = utils.PseudoNamespace(dict(one=1, two=2, three=3), four=4, five=5)
     assert pn.one == 1
     assert pn.four == 4
     assert pn == dict(one=1, two=2, three=3, four=4, five=5)
     assert len(pn.keys()) == 5
Ejemplo n.º 10
0
 def test_instantiation_via_kwargs(self):
     pn = utils.PseudoNamespace(one=1, two=2, three=3)
     assert pn.one == 1
     assert pn == dict(one=1, two=2, three=3)
     assert len(pn.keys()) == 3
Ejemplo n.º 11
0
 def test_auto_tuple_of_dicts_cast(self):
     pn = utils.PseudoNamespace()
     pn.one = (dict(two=2), dict(three=3))
     assert pn.one[0].two == 2
     assert pn == dict(one=(dict(two=2), dict(three=3)))
Ejemplo n.º 12
0
 def test_auto_list_of_dicts_cast(self):
     pn = utils.PseudoNamespace()
     pn.one = [dict(two=2), dict(three=3)]
     assert pn.one[0].two == 2
     assert pn == dict(one=[dict(two=2), dict(three=3)])
Ejemplo n.º 13
0
 def test_auto_dicts_cast(self):
     pn = utils.PseudoNamespace()
     pn.one = dict()
     pn.one.two = dict(three=3)
     assert pn.one.two.three == 3
     assert pn == dict(one=dict(two=dict(three=3)))
Ejemplo n.º 14
0
 def test_set_attr_check_attr(self):
     pn = utils.PseudoNamespace()
     pn.key = 'value'
     assert pn.key == 'value'
Ejemplo n.º 15
0
 def test_set_item_check_item(self):
     pn = utils.PseudoNamespace()
     pn['key'] = 'value'
     assert pn['key'] == 'value'