Revision 56de025f
Added by Tomáš Strachota almost 6 years ago
app/models/compute_resources/foreman/model/ec2.rb | ||
---|---|---|
client.images.get(image).present?
|
||
end
|
||
|
||
def normalize_vm_attrs(vm_attrs)
|
||
normalized = slice_vm_attributes(vm_attrs, ['flavor_id', 'availability_zone', 'subnet_id', 'image_id', 'managed_ip'])
|
||
|
||
normalized['flavor_name'] = self.flavors.detect { |f| f.id == normalized['flavor_id'] }.try(:name)
|
||
normalized['subnet_name'] = self.subnets.detect { |f| f.subnet_id == normalized['subnet_id'] }.try(:cidr_block)
|
||
normalized['image_name'] = self.images.find_by(:uuid => vm_attrs['image_id']).try(:name)
|
||
|
||
group_ids = vm_attrs['security_group_ids'] || []
|
||
group_ids = group_ids.select { |gid| gid != '' }
|
||
normalized['security_groups'] = group_ids.map.with_index do |gid, idx|
|
||
[idx.to_s, {
|
||
'id' => gid,
|
||
'name' => self.security_groups.detect { |g| g.group_id == gid }.try(:name)
|
||
}]
|
||
end.to_h
|
||
|
||
normalized
|
||
rescue Fog::Compute::AWS::Error => e
|
||
Foreman::Logging.exception("Unhandled EC2 error", e)
|
||
{}
|
||
end
|
||
|
||
private
|
||
|
||
def subnet_implies_is_vpc?(args)
|
Also available in: Unified diff
Fixes #21580 - normalize compute attributes (#4980)
Normalizes compute attributes in API show actions. For backwards
compatibility reasons this patch adds a new rabl node instead of
replacing 'vm_attrs'.