summaryrefslogtreecommitdiffstats
path: root/modules/opnfv/utils/Connection.py
blob: a3be514096f34f53d76f2ad1b7f5b381dbc1ec38 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env python

# Copyright (c) 2016 Orange and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0


import os
import time


class Connection(object):

    def __init__(self):
        pass

    def verify_connectivity(self, target):
        for x in range(0, 10):
            ping_cmd = ("ping -c 1 -W 1 %s >/dev/null" % target)
            response = os.system(ping_cmd)
            if response == 0:
                return os.EX_OK
            time.sleep(1)
        return os.EX_UNAVAILABLE

    def check_internet_access(self, url="www.google.com"):
        return self.verify_connectivity(url)