class Chef::Knife::IonoscloudLabelAdd
Attributes
description[R]
required_options[R]
Public Class Methods
new(args = [])
click to toggle source
Calls superclass method
# File lib/chef/knife/ionoscloud_label_add.rb, line 36 def initialize(args = []) super(args) @description = 'Add a Label to a Resource.' @required_options = [:type, :resource_id, :key, :value, :ionoscloud_username, :ionoscloud_password] end
Public Instance Methods
run()
click to toggle source
# File lib/chef/knife/ionoscloud_label_add.rb, line 43 def run $stdout.sync = true handle_extra_config validate_required_params(@required_options, config) label_api = Ionoscloud::LabelApi.new(api_client) label_properties = { properties: { key: config[:key], value: config[:value], }, } case config[:type] when 'datacenter' label = label_api.datacenters_labels_post(config[:resource_id], label_properties) when 'server' validate_required_params([:datacenter_id], config) label = label_api.datacenters_servers_labels_post(config[:datacenter_id], config[:resource_id], label_properties) when 'volume' validate_required_params([:datacenter_id], config) label = label_api.datacenters_volumes_labels_post(config[:datacenter_id], config[:resource_id], label_properties) when 'ipblock' label = label_api.ipblocks_labels_post(config[:resource_id], label_properties) when 'snapshot' label = label_api.snapshots_labels_post(config[:resource_id], label_properties) else ui.error("#{config[:type]} is not a valid Resource Type.") exit(1) end print "#{ui.color('Adding label...', :magenta)}" puts "\n" puts "#{ui.color('Resource ID', :cyan)}: #{config[:resource_id]}" puts "#{ui.color('Resource Type', :cyan)}: #{config[:type]}" puts "#{ui.color('Label Key', :cyan)}: #{label.properties.key}" puts "#{ui.color('Value', :cyan)}: #{label.properties.value}" puts 'done' end