Skip to content

Instantly share code, notes, and snippets.

@jsmartt
Last active November 16, 2017 16:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsmartt/fdd804617ae962f899af79b800d8c341 to your computer and use it in GitHub Desktop.
Save jsmartt/fdd804617ae962f899af79b800d8c341 to your computer and use it in GitHub Desktop.
Method to get the network_type of a particular ServerHardware
def get_oneview_hw_network_type(client, hw)
enclosure = find_oneview_resource(:Enclosure, client, uri: hw['locationUri'])
logical_enclosure = find_oneview_resource(:LogicalEnclosure, client, uri: enclosure['logicalEnclosureUri'])
interconnect_type_uris = [] # List of InterconnectType URIs in this LogicalEnclosure
return 'unmanaged' if logical_enclosure['logicalInterconnectUris'].blank?
logical_enclosure['logicalInterconnectUris'].each do |li_uri|
li = find_oneview_logical_interconnect!(client, uri: li_uri)
# Keep track of the LogicalInterconnect URIs for this LogicalEnclosure
interconnect_type_uris |= li['interconnectMap']['interconnectMapEntries'].map { |e| e['permittedInterconnectTypeUri'] }.compact
end
# Get the full list of InterconnectTypes
interconnect_types = client.response_handler(client.rest_get('/rest/interconnect-types'))['members']
# Keep only the InterconnectType names of the types in this LogicalEnclosure
interconnect_type_names = interconnect_types.select { |i| interconnect_type_uris.include?(i['uri']) }.pluck('name')
# Return the network_type based on InterconnectType names
interconnect_type_names.each do |name|
case name
when /^(?=.*\bSynergy\b)(?=.*\b(VC|Virtual ?Connect)\b).*$/i then return 'synergy-vc'
when /\b(VC|Virtual ?Connect)\b/ then return 'vc'
end
end
nil # else return nil (unknown type)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment