Verified Commit 047b5b64 authored by Arif Ali's avatar Arif Ali

Update to latest code, and add the end of week slides

parent 26a6017b
......@@ -3,7 +3,7 @@ class FillDropdown
csv_content = $evm.get_state_var(:csv_content) || []
# TODO: make unique
values = csv_content.each_with_object({}) { |line, acc| acc[line[:project]] = "#{line[:project]} (#{line[:email]})" }
values = csv_content.each_with_object({}) { |line, acc| acc[line[:project]] = "#{line[:project]}" }
$evm.object['sort_by'] = 'description'
$evm.object['sort_order'] = 'ascending'
......@@ -34,4 +34,3 @@ end
if __FILE__ == $PROGRAM_NAME
FillDropdown.new.dropdown_values
end
#
# Description: <Method description here>
#
require 'azure/armrest'
require 'csv'
storage_account_name = 'cfmesa'
resource_group = 'cfmerg'
share_name = 'testshare'
filename = 'approver_projects_map.csv'
@category_name = 'custom_tag_category'
@category_description = 'Custom Tag Category'
ems = $evm.root.attributes['ext_management_system']
conf = Azure::Armrest::Configuration.new(
:client_id => ems.authentication_userid,
:client_key => ems.authentication_password,
:tenant_id => ems.uid_ems,
:subscription_id => ems.subscription
)
azure = Azure::Armrest::StorageAccountService.new(conf)
begin
storage_account = azure.get(storage_account_name, resource_group)
$evm.log(:info,'Getting Storage Account was successful')
rescue Azure::Armrest::NotFoundException => e
puts("Couldn't find Storage Account or Resource Group: #{e}")
$evm.log(:error,"Couldn't find Storage Account or Resource Group: #{e}")
exit MIQ_ERROR
end
key = azure.list_account_keys(storage_account.name, resource_group).fetch('key1')
file = nil
begin
file = storage_account.file_content(share_name, filename, key)
$evm.log(:info,"Grabbing the file handle was successful")
rescue Azure::Armrest::NotFoundException => e
puts("Couldn't find file: #{e}")
evm.log(:error,"Couldn't find file: #{e}")
exit MIQ_ERROR
rescue Azure::Armrest::BadRequestException => e
puts("Couldn't find share name: #{e}")
evm.log(:error,"Couldn't find share name: #{e}")
exit MIQ_ERROR
end
@csv_content = CSV.parse(file.to_s, :headers => true)
# List all the project tags from the CSV file, and put them into an Array
def get_project_tags()
list_of_tags = []
@csv_content.each do |line|
list_of_tags.push(line[4])
end
list_of_tags.uniq
end
# Define all the project tags in MS Azure, by grabbing the tags from CSV
def populate_project_tags()
unless $evm.execute('category_exists?', @category_name)
$evm.execute('category_create', :name => @category_name,
:single_value => true,
:description => @category_description)
$evm.log(:info,"Adding tag category: #{@category_name}")
end
get_project_tags().each do |record|
# The tag name needs to be lowercase, otherwise the function will error out
tag_name = record.downcase
# TODO: Maybe have another column, with a more understandable description. So
# that we can understand what the project code is for
tag_display_name = record.force_encoding(Encoding::UTF_8)
unless $evm.execute('tag_exists?', @category_name, tag_name)
$evm.execute('tag_create', @category_name, :name => tag_name,
:description => tag_display_name)
$evm.log(:info,"Adding tag '#{tag_name}' to category '#{@category_name}'")
end
end
end
populate_project_tags()
exit MIQ_OK
class CSVTagImport
attr :csv_content, :file_conf
def initialize()
@csv_content = $evm.get_state_var(:csv_content) || []
@file_conf = {}
end
def set_file_conf(category_name:,category_description:)
@file_conf = {
:category_name => category_name,
:category_description => category_description
}
self
end
# List all the project tags from the CSV file, and put them into an Array
def get_project_tags()
list_of_tags = []
@csv_content.each do |line|
list_of_tags.push(line[:project])
end
list_of_tags.uniq
end
# Define all the project tags in MS Azure, by grabbing the tags from CSV
def populate_project_tags()
unless $evm.execute('category_exists?', @file_conf[:category_name])
$evm.execute('category_create', :name => @file_conf[:category_name],
:single_value => true,
:description => @file_conf[:category_description])
$evm.log(:info,"Adding tag category: #{@file_conf[:category_name]}")
end
get_project_tags().each do |record|
# The tag name needs to be lowercase, otherwise the function will error out
tag_name = record.downcase
# TODO: Maybe have another column, with a more understandable description. So
# that we can understand what the project code is for
tag_display_name = record.force_encoding(Encoding::UTF_8)
unless $evm.execute('tag_exists?', @file_conf[:category_name], tag_name)
$evm.execute('tag_create', @file_conf[:category_name], :name => tag_name,
:description => tag_display_name)
$evm.log(:info,"Adding tag '#{tag_name}' to category '#{@file_conf[:category_name]}'")
end
end
end
end
if __FILE__ == $PROGRAM_NAME
importer = CSVTagImport.new
importer.set_file_conf(
:category_name => $evm.object['cf_category_name'],
:category_description => $evm.object['cf_category_description']
)
importer.populate_project_tags
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment