Module: Occi::Cli::Helpers::LinkHelper
- Defined in:
- lib/occi/cli/helpers/link_helper.rb
Instance Method Summary collapse
- #helper_link(options, output = nil) ⇒ Object
- #helper_link_attach_mixins(mixins, link) ⇒ Object
- #helper_link_create_link(options, link_kind, link) ⇒ Object
- #helper_link_kind(options, link) ⇒ Object
Instance Method Details
#helper_link(options, output = nil) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/occi/cli/helpers/link_helper.rb', line 3 def helper_link(, output = nil) location = nil unless .resource.start_with?(.endpoint) || .resource.start_with?('/') raise "Given resource is not a valid instance URL! #{options.resource.inspect}" end unless .links.length == 1 raise "You can assign only one link at a time!" end link = sanitize_instance_link(.links.first) unless link.start_with?('/') raise "Given link is not a valid instance URL! #{link.inspect}" end link_kind = helper_link_kind(, link) location = helper_link_create_link(, link_kind, link) return location if output.nil? puts location end |
#helper_link_attach_mixins(mixins, link) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/occi/cli/helpers/link_helper.rb', line 63 def helper_link_attach_mixins(mixins, link) return if mixins.blank? Occi::Cli::Log.debug "with mixins: #{mixins.inspect}" mixins.to_a.each do |mxn| Occi::Cli::Log.debug "Adding mixin #{mxn.inspect} to #{link.inspect}" orig_mxn = model.get_by_id(mxn.type_identifier) if orig_mxn.blank? orig_mxn = mixin(mxn.term, mxn.scheme.chomp('#'), true) raise Occi::Cli::Errors::MixinLookupError, "The specified mixin is not declared in the model! #{mxn.type_identifier.inspect}" if orig_mxn.blank? end link.mixins << orig_mxn end end |
#helper_link_create_link(options, link_kind, link) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/occi/cli/helpers/link_helper.rb', line 47 def helper_link_create_link(, link_kind, link) Occi::Cli::Log.debug "Linking #{link.inspect} to #{options.resource.inspect}" link_instance = Occi::Core::Link.new(link_kind) link_instance.source = sanitize_instance_link(.resource) link_instance.target = link helper_link_attach_mixins(.mixins, link_instance) .attributes.names.each_pair do |attribute, value| link_instance.attributes[attribute.to_s] = value end create link_instance end |
#helper_link_kind(options, link) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/occi/cli/helpers/link_helper.rb', line 27 def helper_link_kind(, link) raise "No valid links given!" if link.blank? case link when /\/network\//, /\/ipreservation\// link_kind = model.get_by_id("http://schemas.ogf.org/occi/infrastructure#networkinterface") raise "#{options.endpoint.inspect} does not support networkinterface links!" unless link_kind when /\/storage\// link_kind = model.get_by_id("http://schemas.ogf.org/occi/infrastructure#storagelink") raise "#{options.endpoint.inspect} does not support storagelink links!" unless link_kind when /\/securitygroup\// link_kind = model.get_by_id("http://schemas.ogf.org/occi/infrastructure#securitygrouplink") raise "#{options.endpoint.inspect} does not support securitygroup links!" unless link_kind else raise "Unknown link target #{link.inspect}! Only network and storage targets are supported!" end link_kind end |