def test_basic_host_serialization(self):

        serializer = Serializer()
        group = Group.create(name='Test_group')
        host = Host.create(group=group,
                           hostname='linux',
                           ip_address='1.1.1.1',
                           username='******',
                           password='******',
                           ssh_key='AAAAB3Nz',
                           post_login_cmd='pwd')

        expected = {
            'ip_address': '1.1.1.1',
            'id': 1,
            'updated_at': host.updated_at.strftime('%Y-%m-%d %H:%M:%S'),
            'group': 1,
            'username': '******',
            'created_at': host.created_at.strftime('%Y-%m-%d %H:%M:%S'),
            'hostname': 'linux',
            'password': '******',
            'post_login_cmd': 'pwd',
            'ssh_key': 'AAAAB3Nz'
        }

        result = serializer.serialize_object(host)

        self.assertDictEqual(result, expected)
Пример #2
0
def add_host(ip_addr, path, user, password, name=""):
    if not (ip_addr and path and user and password):
        return None
    if not name:
        name = ip_addr.split(".")[-1]
    host = Host.create(name=name,
                       ip_addr=ip_addr,
                       path=path,
                       username=user,
                       password=password)
    return host