HewlettPackard / oneview-chef

This project is no longer being developed and has limited support. In the near future this repository will be fully deprecated. Please consider using other OneView projects, such as Terraform and Ansible Collection
https://supermarket.chef.io/cookbooks/oneview
Apache License 2.0
17 stars 15 forks source link

connection_template resource does not support NetworkSet, FCoENetwork and FCNetwork #218

Closed vranystepan closed 7 years ago

vranystepan commented 7 years ago

Description

I'm trying to configure Bandwidth parameter within the NetworkSet and FcNetwork. connection_template resource obviously supports EthernetNetwork only but connection_template can be configured at the three locations: Ethernet Networks, FC Networks and Network Sets

Environment Details

Intent / Proposal

I suppose that additional methods would do the job. Something like:

# oneview/libraries/resource_providers/api200/connection_template_provider.rb

      def load_resource_from_ethernet
        return unless @context.associated_ethernet_network
        @item.data.delete('name')
        ethernet = resource_named(:EthernetNetwork).find_by(@item.client, name: @context.associated_ethernet_network).first
        @item['uri'] = ethernet['connectionTemplateUri']
      end

and

# oneview/libraries/resource_providers/api200/connection_template_provider.rb

      def create_or_update
        load_resource_from_ethernet
        load_resource_from_network_set
        super
      end

and

# oneview/resources/connection_template.rb

OneviewCookbook::ResourceBaseProperties.load(self)

default_action :update

property :associated_ethernet_network, String
property :associated_network_set, String

action :update do
  OneviewCookbook::Helper.do_resource_action(self, :ConnectionTemplate, :create_or_update)
end

action :reset do
  OneviewCookbook::Helper.do_resource_action(self, :ConnectionTemplate, :reset)
end

and something similar for FC Networks.

Do you think it's reasonable enhancement?

vranystepan commented 7 years ago

Or something like single method for all three resources?

      def load_connection_template
        if @context.associated_ethernet_network
          resource_class_name = :EthernetNetwork
          resource_name = @context.associated_ethernet_network
        elsif @context.associated_fc_network
          resource_class_name = :FcNetwork
          resource_name = @context.associated_fc_network
        elsif @context.associated_network_set
          resource_class_name = :NetworkSet
          resource_name = @context.associated_network_set
        else
          return
        end
        @item.data.delete('name')
        res = resource_named(resource_class_name).find_by(@item.client, name: resource_name).first
        @item['uri'] = res['connectionTemplateUri']
      end

      def create_or_update
        load_connection_template
        super
      end

      def reset
        load_connection_template
        @item['bandwidth'] = resource_named(:ConnectionTemplate).get_default(@item.client)['bandwidth']
        create_or_update
      end
fgbulsoni commented 7 years ago

It does seem like a reasonable enhancement @vranystepan . I'm guessing FCoE networks will also require that, and to avoid adding lots of similar methods, I do like your load_connection_template method. Maybe I could suggest using the method load_resource instead of resource_named with find_by? If you'd like, please feel free to submit your code. :octocat:

vranystepan commented 7 years ago

@fgbulsoni Ok, will implement your suggestion & submit. I'll also add FCoE option. Thank you!

jsmartt commented 7 years ago

Related to #94