Skip to content

Commit

Permalink
Merge pull request #14416 from mkanoor/add_to_service
Browse files Browse the repository at this point in the history
Add a add_to_service method to Vm
  • Loading branch information
gmcculloug authored Mar 20, 2017
2 parents 340d760 + c13b5fd commit fe31966
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions app/models/vm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ def validate_remote_console_vmrc_support
_("VMRC remote console is not supported on %{vendor}.") % {:vendor => vendor})
end

def add_to_service(service)
service.add_resource!(self)
end

def self.find_all_by_mac_address_and_hostname_and_ipaddress(mac_address, hostname, ipaddress)
return [] if mac_address.blank? && hostname.blank? && ipaddress.blank?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def remote_console_url=(url)

def add_to_service(service)
raise ArgumentError, "service must be a MiqAeServiceService" unless service.kind_of?(MiqAeMethodService::MiqAeServiceService)
ar_method { wrap_results(Service.find_by(:id => service.id).add_resource!(@object)) }
ar_method { wrap_results(@object.add_to_service(Service.find_by(:id => service.id))) }
end

def remove_from_service
Expand Down
9 changes: 9 additions & 0 deletions spec/models/vm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -262,4 +262,13 @@
expect(console.url).to eq(url)
expect(console.url_secret).to be
end

it '#add_to_service' do
vm = FactoryGirl.create(:vm_vmware)
service = FactoryGirl.create(:service)

vm.add_to_service(service)
service.reload
expect(service.vms.count).to eq(1)
end
end

0 comments on commit fe31966

Please sign in to comment.