Compare commits

..

5 Commits

Author SHA1 Message Date
85e7e69764 Use blue color for info messages 2017-10-18 14:12:11 +02:00
46f3493be9 Add optional colored logging 2017-10-18 14:07:04 +02:00
709e79f835 Fix post-create ping 2017-10-18 14:03:37 +02:00
0d3e515909 Fix binary symlinks 2017-08-30 17:44:47 +02:00
2ac1b84133 Handle missing token exception 2017-08-30 17:44:26 +02:00
2 changed files with 16 additions and 4 deletions

View File

@@ -5,3 +5,4 @@ libvirt-python>=1.3.1
ovh==0.4.7
termcolor==1.1.0
terminaltables==3.1.0
coloredlogs==7.3

19
vm.py
View File

@@ -16,7 +16,18 @@ __version__ = '0.1'
import logging
logging.basicConfig(level=logging.DEBUG)
logging.getLogger('ovh.vendor').setLevel(logging.WARNING)
logformat = '%(asctime)s %(name)s %(levelname)-7s %(message)s'
logdatefmt = '%Y-%m-%d %H:%M:%S'
loglevel = logging.INFO
try:
import coloredlogs
coloredlogs.DEFAULT_LEVEL_STYLES['info'] = {'color': 'blue'}
coloredlogs.install(level=loglevel, fmt=logformat, datefmt=logdatefmt)
except:
logging.basicConfig(level=loglevel, format=logformat, datefmt=logdatefmt)
logger = logging.getLogger(__name__)
from docopt import docopt
@@ -34,7 +45,7 @@ import ovh
import ovh.exceptions
from collections import namedtuple
BASE = os.path.dirname(os.path.abspath(__file__))
BASE = os.path.dirname(os.path.realpath(__file__))
config = {
'vg': '/dev/vg',
@@ -242,7 +253,7 @@ IP: {0.ip}
Username: {0.user}
Password: {0.password}'''.format(instance))
subprocess.call(['ping', '-c', '1', '-W', '240', instance.ip])
subprocess.call(['ping', '-n', '-c', '1', '-w', '240', instance.ip])
def cmd_iplist(args):
@@ -458,7 +469,7 @@ def main(gargv):
if __name__ == '__main__':
try:
exit(main(sys.argv[1:]))
except ovh.exceptions.InvalidCredential:
except (ovh.exceptions.InvalidCredential, ovh.exceptions.NotCredential):
req = ovh.Client().request_consumerkey([
{'method': 'GET', 'path': '/ip'},
{'method': 'GET', 'path': '/dedicated/server'},