Skip to content

Commit

Permalink
Merge pull request #18418 from kbrock/classification_parent_yml
Browse files Browse the repository at this point in the history
Classification.yml don't use parent_id=0
  • Loading branch information
bdunne authored Jun 13, 2019
2 parents fa99bd9 + 6c8d9ba commit d1f1db7
Show file tree
Hide file tree
Showing 10 changed files with 8 additions and 51 deletions.
17 changes: 5 additions & 12 deletions app/models/classification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -382,14 +382,9 @@ def self.export_to_yaml
end

def export_to_array
h = attributes
h = attributes.except(*%w(id tag_id reserved parent_id))
h["name"] = name
if category?
["id", "tag_id", "reserved"].each { |k| h.delete(k) }
h["entries"] = entries.collect(&:export_to_array).flatten
else
["id", "tag_id", "reserved", "parent_id"].each { |k| h.delete(k) }
end
h["entries"] = entries.collect(&:export_to_array).flatten if category?
[h]
end

Expand All @@ -402,7 +397,7 @@ def self.import_from_hash(classification, parent = nil)

stats = {"categories" => 0, "entries" => 0}

if classification["parent_id"] == 0 # category
if parent.nil? # category
cat = find_by_name(classification["name"])
if cat
_log.info("Skipping Classification (already in DB): Category: name=[#{classification["name"]}]")
Expand All @@ -411,6 +406,7 @@ def self.import_from_hash(classification, parent = nil)

_log.info("Importing Classification: Category: name=[#{classification["name"]}]")

classification.delete("parent_id")
entries = classification.delete("entries")
cat = create(classification)
stats["categories"] += 1
Expand Down Expand Up @@ -454,15 +450,12 @@ def self.seed
category = find_by_name(c[:name], my_region_number, (c[:ns] || DEFAULT_NAMESPACE))
next if category

category = new(c.except(:entries))
category = is_category.new(c.except(:entries))
next unless category.valid? # HACK: Skip seeding if categories aren't valid/unique
_log.info("Creating category #{c[:name]}")
category.save!
add_entries_from_hash(category, c[:entries])
end

# Fix categories that have a nill parent_id
where(:parent_id => nil).update_all(:parent_id => 0)
end

# rubocop:enable Rails/SkipsModelValidations
Expand Down
3 changes: 1 addition & 2 deletions app/models/vm_or_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1382,10 +1382,9 @@ def self.folder_category(folder_type)
cat_name = "folder_path_#{folder_type}"
cat = Classification.find_by_name(cat_name)
unless cat
cat = Classification.new(
cat = Classification.is_category.new(
:name => cat_name,
:description => "Parent Folder Path (#{folder_type == :blue ? "VMs & Templates" : "Hosts & Clusters"})",
:parent_id => 0,
:single_value => true,
:read_only => true
)
Expand Down
28 changes: 0 additions & 28 deletions db/fixtures/classifications.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
:show: true
:name: location
:example_text: The geographic location of the resource, such as New York, Chicago, or London.
:parent_id: 0
:default: true
:single_value: "1"
- :description: Workload
Expand Down Expand Up @@ -107,7 +106,6 @@
:show: true
:name: function
:example_text: The workloads a resource provides, such as Web Server, Database, or Firewall.
:parent_id: 0
:default: true
:single_value: "0"
- :description: Owner
Expand Down Expand Up @@ -138,7 +136,6 @@
:show: true
:name: owner
:example_text: The individual or group that owns the resource.
:parent_id: 0
:default: true
:single_value: "1"
- :description: Environment
Expand Down Expand Up @@ -183,7 +180,6 @@
:show: true
:name: environment
:example_text: The resource environment, such as Development, QA, Test, or Production
:parent_id: 0
:default: true
:single_value: "1"
- :description: User roles
Expand Down Expand Up @@ -242,7 +238,6 @@
:show: true
:name: role
:example_text:
:parent_id: 0
:default: true
:single_value: "1"
:ns: /managed/user
Expand Down Expand Up @@ -274,7 +269,6 @@
:show: true
:name: service_level
:example_text: The level of service associated with this resource.
:parent_id: 0
:default: true
:single_value: "1"
- :description: Customer
Expand All @@ -285,7 +279,6 @@
:show: true
:name: customer
:example_text: The name of the customer associated with this resource.
:parent_id: 0
:default: true
:single_value: t
- :description: Line of Business
Expand All @@ -296,7 +289,6 @@
:show: true
:name: lob
:example_text: The Line of Business the resource is assigned to, such as Retail, Trading, or Manufacturing.
:parent_id: 0
:default: true
:single_value: "0"
- :description: Department
Expand Down Expand Up @@ -418,7 +410,6 @@
:show: true
:name: department
:example_text: The department the resource is assigned to, such as HR, Accounting, or Sales.
:parent_id: 0
:default: true
:single_value: "0"
- :description: Cost Center
Expand All @@ -442,7 +433,6 @@
:show: true
:name: cc
:example_text: Cost Center
:parent_id: 0
:default: true
:single_value: "1"
- :description: Network Location
Expand Down Expand Up @@ -473,7 +463,6 @@
:show: true
:name: network_location
:example_text: The network location the resource is to be used, such as DMZ, Internal network or Cloud
:parent_id: 0
:default: true
:single_value: "1"
- :description: Exclusions
Expand All @@ -497,7 +486,6 @@
:show: true
:name: exclusions
:example_text: Operations that the resource may be excluded from, such as Analysis or Cloning.
:parent_id: 0
:default: true
:single_value: "0"
- :description: Provisioning Scope
Expand All @@ -521,7 +509,6 @@
:show: true
:name: prov_scope
:example_text: Provisioning Scope
:parent_id: 0
:default: true
:single_value: "0"
- :description: EVM Operations
Expand Down Expand Up @@ -552,7 +539,6 @@
:show: true
:name: operations
:example_text: Operations
:parent_id: 0
:default: true
:single_value: "1"
- :description: Quota - Max CPUs
Expand Down Expand Up @@ -632,7 +618,6 @@
:show: true
:name: quota_max_cpu
:example_text: Maximum number of CPUs allowed by Quota
:parent_id: 0
:default: true
:single_value: "1"
- :description: Auto Approve - Max CPU
Expand Down Expand Up @@ -677,7 +662,6 @@
:show: true
:name: prov_max_cpu
:example_text: Maximum number of CPUs allowed by Auto Approval
:parent_id: 0
:default: true
:single_value: "1"
- :description: Auto Approve - Max VM
Expand Down Expand Up @@ -722,7 +706,6 @@
:show: true
:name: prov_max_vm
:example_text: Maximum number of VMs allowed by Auto Approval
:parent_id: 0
:default: true
:single_value: "1"
- :description: Quota - Max Memory
Expand Down Expand Up @@ -788,7 +771,6 @@
:show: true
:name: quota_max_memory
:example_text: Maximum Memory allowed by Quota (GB)
:parent_id: 0
:default: true
:single_value: "1"
- :description: Auto Approve - Max Memory
Expand Down Expand Up @@ -826,7 +808,6 @@
:show: true
:name: prov_max_memory
:example_text: Maximum Memory allowed by Auto Approval (GB)
:parent_id: 0
:default: true
:single_value: "1"
- :description: Quota - Max Storage
Expand Down Expand Up @@ -885,7 +866,6 @@
:show: true
:name: quota_max_storage
:example_text: Maximum Storage allowed by Quota (GB)
:parent_id: 0
:default: true
:single_value: "1"
- :description: Auto Approve - Max Retirement Days
Expand Down Expand Up @@ -923,7 +903,6 @@
:show: true
:name: prov_max_retirement_days
:example_text: Maximum Days for Retirement allowed by Auto Approval
:parent_id: 0
:default: true
:single_value: "1"
- :description: LifeCycle
Expand All @@ -940,7 +919,6 @@
:show: true
:name: lifecycle
:example_text: LifeCycle Options
:parent_id: 0
:default: true
:single_value: "1"
- :description: Migration Group
Expand Down Expand Up @@ -971,7 +949,6 @@
:show: true
:name: migration_group
:example_text: Group of VMs prepared for migration.
:parent_id: 0
:default: true
:single_value: "1"
- :description: Network Mapping
Expand All @@ -988,7 +965,6 @@
:show: true
:name: network_mapping
:example_text: Mapping between source network(s) and a destination network for migration.
:parent_id: 0
:default: true
:single_value: "1"
- :description: Storage Mapping
Expand Down Expand Up @@ -1019,7 +995,6 @@
:show: true
:name: storage_mapping
:example_text: Mapping between source storage(s) and a destination storage for migration.
:parent_id: 0
:default: true
:single_value: "1"
- :description: V2V - Transformation Host
Expand All @@ -1043,7 +1018,6 @@
:show: true
:name: v2v_transformation_host
:example_text: Transformation Host role enabled for V2V.
:parent_id: 0
:default: true
:single_value: "1"
- :description: V2V - Transformation Method
Expand All @@ -1067,7 +1041,6 @@
:show: true
:name: v2v_transformation_method
:example_text: Transformation methods supported for V2V.
:parent_id: 0
:default: true
:single_value: "0"
- :description: Transformation Status
Expand All @@ -1084,6 +1057,5 @@
:show: true
:name: transformation_status
:example_text: VM has been migrated.
:parent_id: 0
:default: true
:single_value: "1"
3 changes: 2 additions & 1 deletion lib/task_helpers/imports/tags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def import_tags(tag_categories)
def import_classification(tag_category)
ns = tag_category["ns"] ? tag_category["ns"] : "/managed"
tag_category["name"] = tag_category["name"].to_s
tag_category.delete("parent_id")

classification = Classification.find_by_name(tag_category['name'], REGION_NUMBER, ns)

Expand All @@ -65,7 +66,7 @@ def import_classification(tag_category)
if classification
classification.update_attributes(tag_category.select { |k| UPDATE_CAT_FIELDS.include?(k) })
else
classification = Classification.create(tag_category)
classification = Classification.is_category.create(tag_category)
end

raise ClassificationYamlError.new("Tag Category error", classification.errors.full_messages) unless classification.valid?
Expand Down
3 changes: 0 additions & 3 deletions spec/lib/task_helpers/exports/tags_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"syntax" => "string",
"single_value" => false,
"example_text" => nil,
"parent_id" => 0,
"show" => true,
"default" => nil,
"perf_by_tag" => nil,
Expand Down Expand Up @@ -45,7 +44,6 @@
"syntax" => "string",
"single_value" => false,
"example_text" => nil,
"parent_id" => 0,
"show" => true,
"default" => true,
"perf_by_tag" => nil,
Expand All @@ -69,7 +67,6 @@
"syntax" => "string",
"single_value" => false,
"example_text" => nil,
"parent_id" => 0,
"show" => true,
"default" => true,
"perf_by_tag" => nil,
Expand Down
1 change: 0 additions & 1 deletion spec/lib/task_helpers/imports/data/tags/Import_Test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
syntax: string
single_value: true
example_text: Tag Import Test
parent_id: 0
show: true
default:
perf_by_tag: false
Expand Down
1 change: 0 additions & 1 deletion spec/lib/task_helpers/imports/data/tags/Location.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
single_value: true
example_text: The geographic location of the resource, such as New York, Chicago,
or London.
parent_id: 0
show: true
default: true
perf_by_tag:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
syntax: string
single_value: true
example_text: Brant Test
parent_id: 0
show: true
default:
perf_by_tag: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
syntax: string
single_value: true
example_text: Brant Test
parent_id: 0
show: true
default:
perf_by_tag: false
Expand Down
1 change: 0 additions & 1 deletion spec/models/classification_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,6 @@
:read_only => "0",
:syntax => "string",
:show => true,
:parent_id => 0,
:default => true,
:single_value => "1",
:entries => [{:description => "Cost Center 001", :name => "001"},
Expand Down

0 comments on commit d1f1db7

Please sign in to comment.