1 # -*- coding: utf-8 -*-
3 # This file is standalone vmware vcloud director util
6 # Licensed under the Apache License, Version 2.0 (the "License"); you may
7 # not use this file except in compliance with the License. You may obtain
8 # a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15 # License for the specific language governing permissions and limitations
18 # For those usages not covered by the Apache License, Version 2.0 please
19 # contact with: mbayramov@vmware.com
24 Standalone application that leverage openmano vmware connector work with vCloud director rest api.
26 - Provides capability to create and delete VDC for specific organization.
27 - Create, delete and manage network for specific VDC
28 - List deployed VM's , VAPPs, VDSs, Organization
29 - View detail information about VM / Vapp , Organization etc
30 - Operate with images upload / boot / power on etc
34 List organization created in vCloud director
35 vmwarecli.py -u admin -p qwerty123 -c 172.16.254.206 -U Administrator -P qwerty123 -o test -v TEF list org
37 List VDC for particular organization
38 vmwarecli.py -u admin -p qwerty123 -c 172.16.254.206 -U Administrator -P qwerty123 -o test -v TEF list vdc
41 python vmwarerecli.py image upload /Users/spyroot/Developer/Openmano/Ro/vnfs/cirros/cirros.ovf
44 python vmwarerecli.py -u admin -p qwerty123 -c 172.16.254.206 -o test -v TEF image boot cirros cirros
47 python vmwarerecli.py -u admin -p qwerty123 -c 172.16.254.206 -o test -v TEF view vapp 90bd2b4e-f782-46cf-b5e2-c3817dcf6633 -u
50 python vmwarerecli.py -u admin -p qwerty123 -c 172.16.254.206 -o test -v TEF list vms
52 List VDC in OSM format
53 python vmwarerecli.py -u admin -p qwerty123 -c 172.16.254.206 -o test -v TEF list vdc -o
63 from xml
.etree
import ElementTree
as ET
66 from pyvcloud
import Http
75 from vimconn_vmware
import vimconnector
76 from requests
.packages
.urllib3
.exceptions
import InsecureRequestWarning
77 from prettytable
import PrettyTable
79 requests
.packages
.urllib3
.disable_warnings(InsecureRequestWarning
)
81 __author__
= "Mustafa Bayramov"
82 __date__
= "$16-Sep-2016 11:09:29$"
85 # TODO move to main vim
86 def delete_network_action(vca
=None, network_uuid
=None):
88 Method leverages vCloud director and query network based on network uuid
91 vca - is active VCA connection.
92 network_uuid - is a network uuid
95 The return XML respond
98 if vca
is None or network_uuid
is None:
101 url_list
= [vca
.host
, '/api/admin/network/', network_uuid
]
102 vm_list_rest_call
= ''.join(url_list
)
104 if not (not vca
.vcloud_session
or not vca
.vcloud_session
.organization
):
105 response
= Http
.get(url
=vm_list_rest_call
,
106 headers
=vca
.vcloud_session
.get_vcloud_headers(),
109 if response
.status_code
== requests
.codes
.ok
:
110 print response
.content
111 return response
.content
116 def print_vapp(vapp_dict
=None):
117 """ Method takes vapp_dict and print in tabular format
120 vapp_dict: container vapp object.
126 # following key available to print
127 # {'status': 'POWERED_OFF', 'storageProfileName': '*', 'hardwareVersion': '7', 'vmToolsVersion': '0',
129 # 'href': 'https://172.16.254.206/api/vAppTemplate/vm-129e22e8-08dc-4cb6-8358-25f635e65d3b',
130 # 'isBusy': 'false', 'isDeployed': 'false', 'isInMaintenanceMode': 'false', 'isVAppTemplate': 'true',
131 # 'networkName': 'nat', 'isDeleted': 'false', 'catalogName': 'Cirros',
132 # 'containerName': 'Cirros Template', # 'container':
133 # 'https://172.16.254.206/api/vAppTemplate/vappTemplate-b966453d-c361-4505-9e38-ccef45815e5d',
134 # 'name': 'Cirros', 'pvdcHighestSupportedHardwareVersion': '11', 'isPublished': 'false',
135 # 'numberOfCpus': '1', 'vdc': 'https://172.16.254.206/api/vdc/a5056f85-418c-4bfd-8041-adb0f48be9d9',
136 # 'guestOs': 'Other (32-bit)', 'isVdcEnabled': 'true'}
138 if vapp_dict
is None:
141 vm_table
= PrettyTable(['vm uuid',
146 'vcpu', 'memory', 'hw ver','deployed','status'])
150 entry
.append(vapp_dict
[k
]['containerName'])
151 # vm-b1f5cd4c-2239-4c89-8fdc-a41ff18e0d61
152 entry
.append(vapp_dict
[k
]['container'].split('/')[-1:][0][5:])
153 entry
.append(vapp_dict
[k
]['networkName'])
154 entry
.append(vapp_dict
[k
]['storageProfileName'])
155 entry
.append(vapp_dict
[k
]['numberOfCpus'])
156 entry
.append(vapp_dict
[k
]['memoryMB'])
157 entry
.append(vapp_dict
[k
]['pvdcHighestSupportedHardwareVersion'])
158 entry
.append(vapp_dict
[k
]['isDeployed'])
159 entry
.append(vapp_dict
[k
]['status'])
161 vm_table
.add_row(entry
)
166 def print_org(org_dict
=None):
167 """ Method takes vapp_dict and print in tabular format
170 org_dict: dictionary of organization where key is org uuid.
179 org_table
= PrettyTable(['org uuid', 'name'])
181 entry
= [k
, org_dict
[k
]]
182 org_table
.add_row(entry
)
187 def print_vm_list(vm_dict
=None):
188 """ Method takes vapp_dict and print in tabular format
191 vm_dict: dictionary of organization where key is org uuid.
199 vm_table
= PrettyTable(
200 ['vm uuid', 'vm name', 'vapp uuid', 'vdc uuid', 'network name', 'is deployed', 'vcpu', 'memory', 'status'])
206 entry
.append(vm_dict
[k
]['name'])
207 entry
.append(vm_dict
[k
]['container'].split('/')[-1:][0][5:])
208 entry
.append(vm_dict
[k
]['vdc'].split('/')[-1:][0])
209 entry
.append(vm_dict
[k
]['networkName'])
210 entry
.append(vm_dict
[k
]['isDeployed'])
211 entry
.append(vm_dict
[k
]['numberOfCpus'])
212 entry
.append(vm_dict
[k
]['memoryMB'])
213 entry
.append(vm_dict
[k
]['status'])
214 vm_table
.add_row(entry
)
217 logger
.error("wrong key {}".format(KeyError.message
))
221 def print_vdc_list(org_dict
=None):
222 """ Method takes vapp_dict and print in tabular format
225 org_dict: dictionary of organization where key is org uuid.
234 if org_dict
.has_key('vdcs'):
235 vdcs_dict
= org_dict
['vdcs']
236 vdc_table
= PrettyTable(['vdc uuid', 'vdc name'])
238 entry
= [k
, vdcs_dict
[k
]]
239 vdc_table
.add_row(entry
)
243 logger
.error("wrong key {}".format(KeyError.message
))
244 logger
.logger
.debug(traceback
.format_exc())
247 def print_network_list(org_dict
=None):
248 """ Method print network list.
251 org_dict: dictionary of organization that contain key networks with a list of all
252 network for for specific VDC
261 if org_dict
.has_key('networks'):
262 network_dict
= org_dict
['networks']
263 network_table
= PrettyTable(['network uuid', 'network name'])
264 for k
in network_dict
:
265 entry
= [k
, network_dict
[k
]]
266 network_table
.add_row(entry
)
271 logger
.error("wrong key {}".format(KeyError.message
))
272 logger
.logger
.debug(traceback
.format_exc())
275 def print_org_details(org_dict
=None):
276 """ Method takes vapp_dict and print in tabular format
279 org_dict: dictionary of organization where key is org uuid.
289 print_vdc_list(org_dict
=org_dict
)
290 print_network_list(org_dict
=org_dict
)
292 if org_dict
.has_key('catalogs'):
293 catalogs_dict
= org_dict
['catalogs']
295 catalog_table
= PrettyTable(['catalog uuid', 'catalog name'])
296 for k
in catalogs_dict
:
297 entry
= [k
, catalogs_dict
[k
]]
298 catalog_table
.add_row(entry
)
303 logger
.error("wrong key {}".format(KeyError.message
))
304 logger
.logger
.debug(traceback
.format_exc())
307 def delete_actions(vim
=None, action
=None, namespace
=None):
308 if action
== 'network' or namespace
.action
== 'network':
309 logger
.debug("Requesting delete for network {}".format(namespace
.network_name
))
310 network_uuid
= namespace
.network_name
311 # if request name based we need find UUID
312 # TODO optimize it or move to external function
313 if not namespace
.uuid
:
314 org_dict
= vim
.get_org_list()
316 org_net
= vim
.get_org(org
)['networks']
317 for network
in org_net
:
318 if org_net
[network
] == namespace
.network_name
:
319 network_uuid
= network
321 vim
.delete_network_action(network_uuid
=network_uuid
)
324 def list_actions(vim
=None, action
=None, namespace
=None):
325 """ Method provide list object from VDC action
328 vim - is vcloud director vim connector.
329 action - is action for list ( vdc / org etc)
330 namespace - must contain VDC / Org information.
337 myorgs
= vim
.get_org_list()
339 if myorgs
[org
] == namespace
.vcdorg
:
343 print(" Invalid organization.")
346 if action
== 'vms' or namespace
.action
== 'vms':
347 vm_dict
= vim
.get_vm_list(vdc_name
=namespace
.vcdvdc
)
348 print_vm_list(vm_dict
=vm_dict
)
349 elif action
== 'vapps' or namespace
.action
== 'vapps':
350 vapp_dict
= vim
.get_vapp_list(vdc_name
=namespace
.vcdvdc
)
351 print_vapp(vapp_dict
=vapp_dict
)
352 elif action
== 'networks' or namespace
.action
== 'networks':
354 osm_print(vim
.get_network_list(filter_dict
={}))
356 print_network_list(vim
.get_org(org_uuid
=org_id
))
357 elif action
== 'vdc' or namespace
.action
== 'vdc':
359 osm_print(vim
.get_tenant_list(filter_dict
=None))
361 print_vdc_list(vim
.get_org(org_uuid
=org_id
))
362 elif action
== 'org' or namespace
.action
== 'org':
363 print_org(org_dict
=vim
.get_org_list())
368 def print_network_details(network_dict
=None):
370 network_table
= PrettyTable(network_dict
.keys())
371 entry
= [network_dict
.values()]
372 network_table
.add_row(entry
[0])
375 logger
.error("wrong key {}".format(KeyError.message
))
376 logger
.logger
.debug(traceback
.format_exc())
379 def osm_print(generic_dict
=None):
382 for element
in generic_dict
:
383 table
= PrettyTable(element
.keys())
384 entry
= [element
.values()]
385 table
.add_row(entry
[0])
388 logger
.error("wrong key {}".format(KeyError.message
))
389 logger
.logger
.debug(traceback
.format_exc())
392 def view_actions(vim
=None, action
=None, namespace
=None):
394 orgs
= vim
.get_org_list()
396 if orgs
[org
] == namespace
.vcdorg
:
400 print(" Invalid organization.")
403 myorg
= vim
.get_org(org_uuid
=org_id
)
406 if action
== 'org' or namespace
.action
== 'org':
408 orgs
= vim
.get_org_list()
410 if namespace
.org_name
in orgs
:
411 org_id
= namespace
.org_name
413 # we need find UUID based on name provided
415 if orgs
[org
] == namespace
.org_name
:
419 logger
.debug("Requesting view for orgs {}".format(org_id
))
420 print_org_details(vim
.get_org(org_uuid
=org_id
))
423 if action
== 'vapp' or namespace
.action
== 'vapp':
424 if namespace
.vapp_name
is not None and namespace
.uuid
:
425 logger
.debug("Requesting vapp {} for vdc {}".format(namespace
.vapp_name
, namespace
.vcdvdc
))
427 vapp_uuid
= namespace
.vapp_name
428 # if request based on just name we need get UUID
429 if not namespace
.uuid
:
430 vapp_uuid
= vim
.get_vappid(vdc
=namespace
.vcdvdc
, vapp_name
=namespace
.vapp_name
)
431 if vapp_uuid
is None:
432 print("Can't find vapp by given name {}".format(namespace
.vapp_name
))
435 print " namespace {}".format(namespace
)
436 if vapp_dict
is not None and namespace
.osm
:
437 vm_info_dict
= vim
.get_vminstance(vim_vm_uuid
=vapp_uuid
)
439 if vapp_dict
is not None and namespace
.osm
!= True:
440 vapp_dict
= vim
.get_vapp(vdc_name
=namespace
.vcdvdc
, vapp_name
=vapp_uuid
, isuuid
=True)
441 print_vapp(vapp_dict
=vapp_dict
)
444 if action
== 'network' or namespace
.action
== 'network':
445 logger
.debug("Requesting view for network {}".format(namespace
.network_name
))
446 network_uuid
= namespace
.network_name
447 # if request name based we need find UUID
448 # TODO optimize it or move to external function
449 if not namespace
.uuid
:
450 if not myorg
.has_key('networks'):
451 print("Network {} is undefined in vcloud director for org {} vdc {}".format(namespace
.network_name
,
456 my_org_net
= myorg
['networks']
457 for network
in my_org_net
:
458 if my_org_net
[network
] == namespace
.network_name
:
459 network_uuid
= network
462 print print_network_details(network_dict
=vim
.get_vcd_network(network_uuid
=network_uuid
))
465 def create_actions(vim
=None, action
=None, namespace
=None):
466 """Method gets provider vdc view from vcloud director
469 vim - is Cloud director vim connector
470 action - action for create ( network / vdc etc)
473 The return xml content of respond or None
475 if action
== 'network' or namespace
.action
== 'network':
476 logger
.debug("Creating a network in vcloud director".format(namespace
.network_name
))
477 network_uuid
= vim
.create_network(namespace
.network_name
)
478 if network_uuid
is not None:
479 print ("Crated new network {} and uuid: {}".format(namespace
.network_name
, network_uuid
))
481 print ("Failed create a new network {}".format(namespace
.network_name
))
482 elif action
== 'vdc' or namespace
.action
== 'vdc':
483 logger
.debug("Creating a new vdc in vcloud director.".format(namespace
.vdc_name
))
484 vdc_uuid
= vim
.create_vdc(namespace
.vdc_name
)
485 if vdc_uuid
is not None:
486 print ("Crated new vdc {} and uuid: {}".format(namespace
.vdc_name
, vdc_uuid
))
488 print ("Failed create a new vdc {}".format(namespace
.vdc_name
))
493 def validate_uuid4(uuid_string
):
494 """Function validate that string contain valid uuid4
497 uuid_string - valid UUID string
500 The return true if string contain valid UUID format
503 val
= uuid
.UUID(uuid_string
, version
=4)
509 def upload_image(vim
=None, image_file
=None):
510 """Function upload image to vcloud director
513 image_file - valid UUID string
516 The return true if image uploaded correctly
519 catalog_uuid
= vim
.get_image_id_from_path(path
=image_file
, progress
=True)
520 if catalog_uuid
is not None and validate_uuid4(catalog_uuid
):
521 print("Image uploaded and uuid {}".format(catalog_uuid
))
523 except vimconn
.vimconnException
as upload_exception
:
524 print("Failed uploaded {} image".format(image_file
))
525 print("Error Reason: {}".format(upload_exception
.message
))
529 def boot_image(vim
=None, image_name
=None, vm_name
=None):
530 """ Function boot image that resided in vcloud director.
531 The image name can be UUID of name.
535 image_name - image identified by UUID or text string.
540 The return true if image uploaded correctly
545 catalogs
= vim
.vca
.get_catalogs()
546 if not validate_uuid4(image_name
):
547 vim_catalog
= vim
.get_catalogid(catalog_name
=image_name
, catalogs
=catalogs
)
548 if vim_catalog
is None:
551 vim_catalog
= vim
.get_catalogid(catalog_name
=image_name
, catalogs
=catalogs
)
552 if vim_catalog
is None:
555 vm_uuid
= vim
.new_vminstance(name
=vm_name
, image_id
=vim_catalog
)
556 if vm_uuid
is not None and validate_uuid4(vm_uuid
):
557 print("Image booted and vm uuid {}".format(vm_uuid
))
558 vapp_dict
= vim
.get_vapp(vdc_name
=namespace
.vcdvdc
, vapp_name
=vm_uuid
, isuuid
=True)
559 if vapp_dict
is not None:
560 print_vapp(vapp_dict
=vapp_dict
)
563 print("Failed uploaded {} image".format(image_name
))
568 def image_action(vim
=None, action
=None, namespace
=None):
569 """ Function present set of action to manipulate with image.
572 - delete image ( not yet done )
575 vim - vcloud director connector
576 action - string (upload/boot etc)
577 namespace - contain other attributes image name etc
583 if action
== 'upload' or namespace
.action
== 'upload':
584 upload_image(vim
=vim
, image_file
=namespace
.image
)
585 elif action
== 'boot' or namespace
.action
== 'boot':
586 boot_image(vim
=vim
, image_name
=namespace
.image
, vm_name
=namespace
.vmname
)
591 def vmwarecli(command
=None, action
=None, namespace
=None):
592 logger
.debug("Namespace {}".format(namespace
))
593 urllib3
.disable_warnings()
600 if hasattr(__builtins__
, 'raw_input'):
603 if namespace
.vcdvdc
is None:
605 vcduser
= input("Enter vcd username: ")
606 if vcduser
is not None and len(vcduser
) > 0:
609 vcduser
= namespace
.vcduser
611 if namespace
.vcdpassword
is None:
613 vcdpasword
= input("Please enter vcd password: ")
614 if vcdpasword
is not None and len(vcdpasword
) > 0:
617 vcdpasword
= namespace
.vcdpassword
619 if namespace
.vcdhost
is None:
621 vcdhost
= input("Please enter vcd host name or ip: ")
622 if vcdhost
is not None and len(vcdhost
) > 0:
625 vcdhost
= namespace
.vcdhost
627 if namespace
.vcdorg
is None:
629 vcdorg
= input("Please enter vcd organization name: ")
630 if vcdorg
is not None and len(vcdorg
) > 0:
633 vcdorg
= namespace
.vcdorg
636 vim
= vimconnector(uuid
=None,
639 tenant_name
=namespace
.vcdvdc
,
645 config
={'admin_username': namespace
.vcdamdin
, 'admin_password': namespace
.vcdadminpassword
})
646 vim
.vca
= vim
.connect()
648 except vimconn
.vimconnConnectionException
:
649 print("Failed connect to vcloud director. Please check credential and hostname.")
653 if command
== 'list' or namespace
.command
== 'list':
654 logger
.debug("Client requested list action")
655 # route request to list actions
656 list_actions(vim
=vim
, action
=action
, namespace
=namespace
)
659 if command
== 'view' or namespace
.command
== 'view':
660 logger
.debug("Client requested view action")
661 view_actions(vim
=vim
, action
=action
, namespace
=namespace
)
664 if command
== 'delete' or namespace
.command
== 'delete':
665 logger
.debug("Client requested delete action")
666 delete_actions(vim
=vim
, action
=action
, namespace
=namespace
)
669 if command
== 'create' or namespace
.command
== 'create':
670 logger
.debug("Client requested create action")
671 create_actions(vim
=vim
, action
=action
, namespace
=namespace
)
674 if command
== 'image' or namespace
.command
== 'image':
675 logger
.debug("Client requested create action")
676 image_action(vim
=vim
, action
=action
, namespace
=namespace
)
679 if __name__
== '__main__':
680 defaults
= {'vcdvdc': 'default',
682 'vcdpassword': 'admin',
683 'vcdhost': 'https://localhost',
687 parser
= argparse
.ArgumentParser()
688 parser
.add_argument('-u', '--vcduser', help='vcloud director username', type=str)
689 parser
.add_argument('-p', '--vcdpassword', help='vcloud director password', type=str)
690 parser
.add_argument('-U', '--vcdamdin', help='vcloud director password', type=str)
691 parser
.add_argument('-P', '--vcdadminpassword', help='vcloud director password', type=str)
692 parser
.add_argument('-c', '--vcdhost', help='vcloud director host', type=str)
693 parser
.add_argument('-o', '--vcdorg', help='vcloud director org', type=str)
694 parser
.add_argument('-v', '--vcdvdc', help='vcloud director vdc', type=str)
695 parser
.add_argument('-d', '--debug', help='debug level', type=int)
697 parser_subparsers
= parser
.add_subparsers(help='commands', dest
='command')
698 sub
= parser_subparsers
.add_parser('list', help='List objects (VMs, vApps, networks)')
699 sub_subparsers
= sub
.add_subparsers(dest
='action')
701 list_vms
= sub_subparsers
.add_parser('vms', help='list - all vm deployed in vCloud director')
702 list_vapps
= sub_subparsers
.add_parser('vapps', help='list - all vapps deployed in vCloud director')
703 list_network
= sub_subparsers
.add_parser('networks', help='list - all networks deployed')
704 list_network
.add_argument('-o', '--osm', default
=False, action
='store_true', help='provide view in OSM format')
707 list_vdc
= sub_subparsers
.add_parser('vdc', help='list - list all vdc for organization accessible to you')
708 list_vdc
.add_argument('-o', '--osm', default
=False, action
='store_true', help='provide view in OSM format')
710 list_org
= sub_subparsers
.add_parser('org', help='list - list of organizations accessible to you.')
712 create_sub
= parser_subparsers
.add_parser('create')
713 create_sub_subparsers
= create_sub
.add_subparsers(dest
='action')
714 create_vms
= create_sub_subparsers
.add_parser('vms')
715 create_vapp
= create_sub_subparsers
.add_parser('vapp')
716 create_vapp
.add_argument('uuid')
719 create_network
= create_sub_subparsers
.add_parser('network')
720 create_network
.add_argument('network_name', action
='store', help='create a network for a vdc')
723 create_vdc
= create_sub_subparsers
.add_parser('vdc')
724 create_vdc
.add_argument('vdc_name', action
='store', help='create a new VDC for org')
726 delete_sub
= parser_subparsers
.add_parser('delete')
727 del_sub_subparsers
= delete_sub
.add_subparsers(dest
='action')
728 del_vms
= del_sub_subparsers
.add_parser('vms')
729 del_vapp
= del_sub_subparsers
.add_parser('vapp')
730 del_vapp
.add_argument('uuid', help='view vapp based on UUID')
733 del_network
= del_sub_subparsers
.add_parser('network')
734 del_network
.add_argument('network_name', action
='store',
735 help='- delete network for vcloud director by provided name')
736 del_network
.add_argument('-u', '--uuid', default
=False, action
='store_true',
737 help='delete network for vcloud director by provided uuid')
740 del_vdc
= del_sub_subparsers
.add_parser('vdc')
742 view_sub
= parser_subparsers
.add_parser('view')
743 view_sub_subparsers
= view_sub
.add_subparsers(dest
='action')
745 view_vms_parser
= view_sub_subparsers
.add_parser('vms')
746 view_vms_parser
.add_argument('uuid', default
=False, action
='store_true',
747 help='- View VM for specific uuid in vcloud director')
748 view_vms_parser
.add_argument('name', default
=False, action
='store_true',
749 help='- View VM for specific vapp name in vcloud director')
752 view_vapp_parser
= view_sub_subparsers
.add_parser('vapp')
753 view_vapp_parser
.add_argument('vapp_name', action
='store',
754 help='- view vapp for specific vapp name in vcloud director')
755 view_vapp_parser
.add_argument('-u', '--uuid', default
=False, action
='store_true', help='view vapp based on uuid')
756 view_vapp_parser
.add_argument('-o', '--osm', default
=False, action
='store_true', help='provide view in OSM format')
759 view_network
= view_sub_subparsers
.add_parser('network')
760 view_network
.add_argument('network_name', action
='store',
761 help='- view network for specific network name in vcloud director')
762 view_network
.add_argument('-u', '--uuid', default
=False, action
='store_true', help='view network based on uuid')
764 # view VDC command and actions
765 view_vdc
= view_sub_subparsers
.add_parser('vdc')
766 view_vdc
.add_argument('vdc_name', action
='store',
767 help='- View VDC based and action based on provided vdc uuid')
768 view_vdc
.add_argument('-u', '--uuid', default
=False, action
='store_true', help='view vdc based on uuid')
770 # view organization command and actions
771 view_org
= view_sub_subparsers
.add_parser('org')
772 view_org
.add_argument('org_name', action
='store',
773 help='- View VDC based and action based on provided vdc uuid')
774 view_org
.add_argument('-u', '--uuid', default
=False, action
='store_true', help='view org based on uuid')
776 # upload image action
777 image_sub
= parser_subparsers
.add_parser('image')
778 image_subparsers
= image_sub
.add_subparsers(dest
='action')
779 upload_parser
= image_subparsers
.add_parser('upload')
780 upload_parser
.add_argument('image', default
=False, action
='store', help='- valid path to OVF image ')
781 upload_parser
.add_argument('catalog', default
=False, action
='store_true', help='- catalog name')
784 boot_parser
= image_subparsers
.add_parser('boot')
785 boot_parser
.add_argument('image', default
=False, action
='store', help='- Image name')
786 boot_parser
.add_argument('vmname', default
=False, action
='store', help='- VM name')
787 boot_parser
.add_argument('-u', '--uuid', default
=False, action
='store_true', help='view org based on uuid')
789 namespace
= parser
.parse_args()
790 # put command_line args to mapping
791 command_line_args
= {k
: v
for k
, v
in vars(namespace
).items() if v
}
795 d
.update(command_line_args
)
797 logger
= logging
.getLogger('mano.vim.vmware')
798 formatter
= logging
.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
799 ch
= logging
.StreamHandler()
800 ch
.setLevel(str.upper(d
['debug']))
801 ch
.setFormatter(formatter
)
802 logger
.addHandler(ch
)
803 logger
.setLevel(getattr(logging
, str.upper(d
['debug'])))
805 "Connecting {} username: {} org: {} vdc: {} ".format(d
['vcdhost'], d
['vcduser'], d
['vcdorg'], d
['vcdvdc']))
807 logger
.debug("command: \"{}\" actio: \"{}\"".format(d
['command'], d
['action']))
810 vmwarecli(namespace
=namespace
)