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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
#!/usr/bin/python
import sys
import os
import argparse
from eos_downloader.cvp import CvFeatureManager, CvpAuthenticationItem
from loguru import logger
ARISTA_AVD_CV_TOKEN = os.getenv('ARISTA_AVD_CV_TOKEN', '')
def read_cli():
parser = argparse.ArgumentParser(description='Cloudvision Image uploader script.')
parser.add_argument('--token', required=False,
default=ARISTA_AVD_CV_TOKEN,
help='CVP Authentication token - can use ENV:ARISTA_AVD_CV_TOKEN')
parser.add_argument('--image', required=False,
default='EOS', help='Type of EOS image required')
parser.add_argument('--cloudvision', required=True,
help='Cloudvision instance where to upload image')
parser.add_argument('--create_bundle', required=False, action='store_true',
help="Option to create image bundle with new uploaded image")
parser.add_argument('--timeout', required=False,
default=1200,
help='Timeout connection. Default is set to 1200sec')
parser.add_argument('--verbose', required=False,
default='info', help='Script verbosity')
return parser.parse_args()
if __name__ == '__main__':
cli_options = read_cli()
logger.remove()
logger.add(sys.stderr, level=str(cli_options.verbose).upper())
cv_authentication = CvpAuthenticationItem(
server=cli_options.cloudvision,
token=cli_options.token,
port=443,
timeout=cli_options.timeout,
validate_cert=False
)
my_cvp_uploader = CvFeatureManager(authentication=cv_authentication)
result_upload = my_cvp_uploader.upload_image(cli_options.image)
if result_upload and cli_options.create_bundle:
bundle_name = os.path.basename(cli_options.image)
logger.info('Creating image bundle {}'.format(bundle_name))
my_cvp_uploader.create_bundle(
name=bundle_name,
images_name=[bundle_name]
)
sys.exit(0)
|