Skip to content

Commit

Permalink
Merge pull request #14040 from himdel/decorator-vms
Browse files Browse the repository at this point in the history
API - VMs collection - replace decorators with SupportsFeatureMixin
  • Loading branch information
abellotti committed Mar 16, 2017
2 parents 3b7fd39 + 21934bf commit e646755
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
10 changes: 0 additions & 10 deletions app/controllers/api/base_controller/parameters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,6 @@ def search_option?(what)
search_options.map(&:downcase).include?(what.to_s)
end

def decorator_selection
params['decorators'].to_s.split(",")
end

def decorator_selection_for(collection)
decorator_selection.collect do |attr|
/\A#{collection}\.(?<name>.*)\z/.match(attr) { |m| m[:name] }
end.compact
end

def attribute_selection
if !@req.attributes.empty? || @additional_attributes
@req.attributes | Array(@additional_attributes) | ID_ATTRS
Expand Down
21 changes: 18 additions & 3 deletions app/controllers/api/subcollections/vms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,31 @@ def vms_query_resource(object)

private

def decorator_selection
params['decorators'].to_s.split(",")
end

def decorator_selection_for(collection)
decorator_selection.collect do |attr|
/\A#{collection}\.(?<name>.*)\z/.match(attr) { |m| m[:name] }
end.compact
end

def create_vm_attributes_hash(vm_attrs, vm)
vm_attrs.each_with_object({}) do |attr, hash|
hash[attr] = vm.public_send(attr.to_sym) if vm.respond_to?(attr.to_sym)
end.compact
end

def create_vm_decorators_hash(vm_decorators, vm)
vm_decorators.each_with_object({}) do |name, hash|
hash[name] = vm.decorate.public_send(name.to_sym) if vm.decorate.respond_to?(name.to_sym)
end.compact
hash = {}
if vm_decorators.include? 'supports_console?'
hash['supports_console?'] = vm.supports_console?
end
if vm_decorators.include? 'supports_cockpit?'
hash['supports_cockpit?'] = vm.supports_launch_cockpit?
end
hash
end
end
end
Expand Down
1 change: 1 addition & 0 deletions app/models/mixins/supports_feature_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ module SupportsFeatureMixin
:create_host_aggregate => 'Host Aggregate Creation',
:create_network_router => 'Network Router Creation',
:create_security_group => 'Security Group Creation',
:console => 'Remote Console',
:external_logging => 'Launch External Logging UI',
:swift_service => 'Swift storage service',
:delete => 'Deletion',
Expand Down
6 changes: 6 additions & 0 deletions app/models/vm_or_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1835,6 +1835,12 @@ def tenant_identity
user
end

supports :console do
unless console_supported?('spice') || console_supported?('vnc')
unsupported_reason_add(:console, N_("Console not supported"))
end
end

private

def set_tenant_from_group
Expand Down

0 comments on commit e646755

Please sign in to comment.