Class: Fog::Compute::Vsphere::Interface
- Inherits:
-
Model
- Object
- Model
- Fog::Compute::Vsphere::Interface
- Defined in:
- lib/fog/vsphere/models/compute/interface.rb
Constant Summary collapse
- SAVE_MUTEX =
Mutex.new
Instance Method Summary collapse
- #destroy ⇒ Object
-
#initialize(attributes = {}) ⇒ Interface
constructor
A new instance of Interface.
- #save ⇒ Object
- #server ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Interface
Returns a new instance of Interface.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/fog/vsphere/models/compute/interface.rb', line 19 def initialize(attributes = {}) # Assign server first to prevent race condition with persisted? self.server_id = attributes.delete(:server_id) if attributes.key? :type then if attributes[:type].is_a? String then attributes[:type] = Fog::Vsphere.class_from_string(attributes[:type], "RbVmomi::VIM") end else attributes[:type] = Fog::Vsphere.class_from_string("VirtualE1000", "RbVmomi::VIM") end super defaults.merge(attributes) end |
Instance Method Details
#destroy ⇒ Object
43 44 45 46 47 |
# File 'lib/fog/vsphere/models/compute/interface.rb', line 43 def destroy requires :server_id, :key, :type service.destroy_vm_interface(server_id, :key => key, :type => type) end |
#save ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/fog/vsphere/models/compute/interface.rb', line 49 def save raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted? requires :server_id, :type, :network # Our approach of finding the newly created interface is rough. We assume that the :key value always increments # and thus the highest :key value must correspond to the created interface. Since this has an inherent race # condition we need to gate the saves. SAVE_MUTEX.synchronize do data = service.add_vm_interface(server_id, attributes) if data['task_state'] == 'success' # We have to query vSphere to get the interface attributes since the task handle doesn't include that info. created = server.interfaces.all.sort_by(&:key).last self.mac = created.mac self.name = created.name self.status = created.status self.summary = created.summary self.key = created.key self.virtualswitch = created.virtualswitch true else false end end end |
#server ⇒ Object
38 39 40 41 |
# File 'lib/fog/vsphere/models/compute/interface.rb', line 38 def server requires :server_id service.servers.get(server_id) end |
#to_s ⇒ Object
34 35 36 |
# File 'lib/fog/vsphere/models/compute/interface.rb', line 34 def to_s name end |