- try:
- check_client_version(ctx.obj, ctx.command.name)
- pdu = {}
- if not descriptor_file:
- if not name:
- raise ClientException('in absence of descriptor file, option "--name" is mandatory')
- if not pdu_type:
- raise ClientException('in absence of descriptor file, option "--pdu_type" is mandatory')
- if not interface:
- raise ClientException('in absence of descriptor file, option "--interface" is mandatory (at least once)')
- if not vim_account:
- raise ClientException('in absence of descriptor file, option "--vim_account" is mandatory (at least once)')
- else:
- with open(descriptor_file, 'r') as df:
- pdu = yaml.safe_load(df.read())
- if name: pdu["name"] = name
- if pdu_type: pdu["type"] = pdu_type
- if description: pdu["description"] = description
- if vim_account: pdu["vim_accounts"] = vim_account
- if interface:
- ifaces_list = []
- for iface in interface:
- new_iface={k:v for k,v in [i.split('=') for i in iface.split(',')]}
- new_iface["mgmt"] = (new_iface.get("mgmt","false").lower() == "true")
- ifaces_list.append(new_iface)
- pdu["interfaces"] = ifaces_list
- ctx.obj.pdu.create(pdu)
- except ClientException as e:
- print(str(e))
- exit(1)
+ # try:
+ check_client_version(ctx.obj, ctx.command.name)
+ pdu = {}
+ if not descriptor_file:
+ if not name:
+ raise ClientException('in absence of descriptor file, option "--name" is mandatory')
+ if not pdu_type:
+ raise ClientException('in absence of descriptor file, option "--pdu_type" is mandatory')
+ if not interface:
+ raise ClientException('in absence of descriptor file, option "--interface" is mandatory (at least once)')
+ if not vim_account:
+ raise ClientException('in absence of descriptor file, option "--vim_account" is mandatory (at least once)')
+ else:
+ with open(descriptor_file, 'r') as df:
+ pdu = yaml.safe_load(df.read())
+ if name: pdu["name"] = name
+ if pdu_type: pdu["type"] = pdu_type
+ if description: pdu["description"] = description
+ if vim_account: pdu["vim_accounts"] = vim_account
+ if interface:
+ ifaces_list = []
+ for iface in interface:
+ new_iface={k:v for k,v in [i.split('=') for i in iface.split(',')]}
+ new_iface["mgmt"] = (new_iface.get("mgmt","false").lower() == "true")
+ ifaces_list.append(new_iface)
+ pdu["interfaces"] = ifaces_list
+ ctx.obj.pdu.create(pdu)
+ # except ClientException as e:
+ # print(str(e))
+ # exit(1)