lib/virtualbox/forwarded_port.rb in virtualbox-0.6.1 vs lib/virtualbox/forwarded_port.rb in virtualbox-0.7.0
- old
+ new
@@ -65,19 +65,20 @@
# attribute :protocol, :default => "TCP"
# attribute :guestport
# attribute :hostport
#
class ForwardedPort < AbstractModel
- attribute :parent, :readonly => true
+ attribute :parent, :readonly => true, :property => false
+ attribute :parent_collection, :readonly => true, :property => false
attribute :name
attribute :instance, :default => "0"
attribute :device, :default => "pcnet"
attribute :protocol, :default => "TCP"
attribute :guestport
attribute :hostport
- class <<self
+ class << self
# Populates a relationship with another model.
#
# **This method typically won't be used except internally.**
#
# @return [Array<ForwardedPort>]
@@ -87,10 +88,11 @@
caller.extra_data.each do |key, value|
next unless key =~ /^(VBoxInternal\/Devices\/(.+?)\/(.+?)\/LUN#0\/Config\/(.+?)\/)Protocol$/i
port = new({
:parent => caller,
+ :parent_collection => relation,
:name => $4.to_s,
:instance => $3.to_s,
:device => $2.to_s,
:protocol => value,
:guestport => caller.extra_data["#{$1.to_s}GuestPort"],
@@ -180,31 +182,33 @@
result
end
# Destroys the port forwarding mapping.
#
- # @param [Boolean] raise_errors If true, {Exceptions::CommandFailedException}
- # will be raised if the command failed.
# @return [Boolean] True if command was successful, false otherwise.
def destroy
results = []
if !new_record?
results << parent.extra_data.delete("#{key_prefix(true)}Protocol")
results << parent.extra_data.delete("#{key_prefix(true)}GuestPort")
results << parent.extra_data.delete("#{key_prefix(true)}HostPort")
+ # Remove it from any collection
+ parent_collection.delete(self, true) if parent_collection
+
new_record!
end
results.empty? || results.all? { |o| o == true }
end
# Relationship callback when added to a collection. This is automatically
# called by any relationship collection when this object is added.
- def added_to_relationship(parent)
- write_attribute(:parent, parent)
+ def added_to_relationship(proxy)
+ write_attribute(:parent, proxy.parent)
+ write_attribute(:parent_collection, proxy)
end
# Returns the prefix to be used for the extra data key. Forwarded ports
# are created by simply setting {ExtraData} on a {VM}. This class hides most
# of the inner workings of it, but it requires a common prefix. This method
@@ -214,6 +218,6 @@
def key_prefix(old_name=false)
name_value = old_name && name_changed? ? name_was : name
"VBoxInternal\/Devices\/#{device}\/#{instance}\/LUN#0\/Config\/#{name_value}\/"
end
end
-end
\ No newline at end of file
+end