Skip to content

Commit

Permalink
Ensure unique AddressOnParent when cloning an Item. Fixes #17.
Browse files Browse the repository at this point in the history
Prevent spurious warning messages about missing files during 'info'
and 'deploy' operations against an OVA file.
  • Loading branch information
glennmatthews committed Nov 25, 2014
1 parent 3ce2630 commit 0efdc1f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
37 changes: 27 additions & 10 deletions COT/ovf.py
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,13 @@ def validate_file_references(self):
described.
Returns True (all files valid) or False (one or more missing/invalid).
"""
if not self.output_file:
if self.input_file != self.ovf_descriptor:
# Read-only mode, handling an OVA input file.
# In this case we only untarred the ovf descriptor
# and not any other contents of the OVA, so there's
# nothing to check here.
return True
base_dir = os.path.dirname(self.ovf_descriptor)
rc = True
for file in XML.find_all_children(self.references, self.FILE):
Expand Down Expand Up @@ -2351,18 +2358,28 @@ def set_item_count_per_profile(self, resource_type, count, profile_list):
"Address value when cloning an Item "
"of type {0}".format(resource_type))

address = new_item.get(self.ovf.ADDRESS_ON_PARENT)
if address:
parent = new_item.get(self.ovf.PARENT)
if parent:
address_on_parent = new_item.get(self.ovf.ADDRESS_ON_PARENT)
if address_on_parent:
address_set = new_item.get_all_values(self.ovf.ADDRESS_ON_PARENT)
if len(address_set) > 1:
raise NotImplementedError("AddressOnParent is not common "
"across all profiles but has "
"multiple values {0}. COT can't "
"handle this yet."
.format(address_set))
address_on_parent = address_set.pop()
# Currently we only handle integer addresses
try:
address_on_parent = int(address_on_parent)
address_on_parent += 1
new_item.set_property(self.ovf.ADDRESS_ON_PARENT,
str(address_on_parent),
new_item_profiles)
except ValueError:
raise NotImplementedError("Don't know how to ensure a "
"unique AddressOnParent value "
"when cloning an Item with a "
"Parent")
logger.warning("Item (of type {0}) has an AddressOnParent "
"but no Parent - AddressOnParent is meaningless "
"and will not be updated for uniqueness."
.format(resource_type))
"given base value '{0}'"
.format(address_on_parent))

if resource_type == 'ethernet':
# Update ElementName to reflect the NIC number
Expand Down
4 changes: 2 additions & 2 deletions COT/tests/ovf.py
Original file line number Diff line number Diff line change
Expand Up @@ -1169,7 +1169,7 @@ def test_set_nic_count(self):
"""
</ovf:Item>
+ <ovf:Item ovf:configuration="4CPU-4GB-3NIC">
+ <rasd:AddressOnParent>13</rasd:AddressOnParent>
+ <rasd:AddressOnParent>14</rasd:AddressOnParent>
+ <rasd:AutomaticAllocation>true</rasd:AutomaticAllocation>
+ <rasd:Connection>VM Network</rasd:Connection>
+ <rasd:Description>VMXNET3 ethernet adapter on "VM Network"</rasd:Description>
Expand Down Expand Up @@ -1511,7 +1511,7 @@ def test_set_nic_kitchen_sink(self):
+ <rasd:ResourceType>10</rasd:ResourceType>
+ </ovf:Item>
+ <ovf:Item ovf:configuration="4CPU-4GB-3NIC">
+ <rasd:AddressOnParent>13</rasd:AddressOnParent>
+ <rasd:AddressOnParent>14</rasd:AddressOnParent>
+ <rasd:AutomaticAllocation>true</rasd:AutomaticAllocation>
+ <rasd:Connection>UT</rasd:Connection>
+ <rasd:Description>VMXNET3 ethernet adapter on "VM Network"</rasd:Description>
Expand Down

0 comments on commit 0efdc1f

Please sign in to comment.