Top Level Namespace

Defined Under Namespace

Modules: HTTParty, Net, Occi

Instance Method Summary collapse

Instance Method Details

#helper_create(options, output = nil) ⇒ Object


76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/occi/bin/helpers.rb', line 76

def helper_create(options, output = nil)
  location = nil

  if resource_types.include? options.resource
    Occi::Log.debug "#{options.resource} is a resource type."
    raise "Not yet implemented!" unless options.resource.include? "compute"

    res = resource options.resource

    Occi::Log.debug "Creating #{options.resource}:\n#{res.inspect}"

    if options.links
      Occi::Log.debug "with links: #{options.links}"

      options.links.each do |link|
        link = options.endpoint.chomp('/') + link unless link.start_with? options.endpoint

        if link.include? "/storage/"
          Occi::Log.debug "Adding storagelink to #{options.resource}"
          res.storagelink link
        elsif link.include? "/network/"
          Occi::Log.debug "Adding networkinterface to #{options.resource}"
          res.networkinterface link
        else
          raise "Unknown link type #{link}, stopping here!"
        end
      end
    end

    if options.mixins
      Occi::Log.debug "with mixins: #{options.mixins}"

      options.mixins.keys.each do |type|
        Occi::Log.debug "Adding mixins of type #{type} to #{options.resource}"

        options.mixins[type].each do |name|
          mxn = mixin name, type

          raise "Unknown mixin #{type}##{name}, stopping here!" if mxn.nil?
          Occi::Log.debug "Adding mixin #{mxn} to #{options.resource}"
          res.mixins << mxn
        end
      end
    end

    #TODO: set other attributes
    res.title = options.attributes[:title]

    Occi::Log.debug "Creating #{options.resource}:\n#{res.inspect}"

    location = create res
  else
    Occi::Log.warn "I have no idea what #{options.resource} is ..."
    raise "Unknown resource #{options.resource}, there is nothing to create here!"
  end

  return location if output.nil?

  puts location
end

#helper_delete(options, output = nil) ⇒ Object


137
138
139
140
141
142
143
144
145
# File 'lib/occi/bin/helpers.rb', line 137

def helper_delete(options, output = nil)
  if delete(options.resource)
    Occi::Log.info "Resource #{options.resource} successfully removed!"
  else
    raise "Failed to remove resource #{options.resource}!"
  end

  true
end

#helper_describe(options, output = nil) ⇒ Object


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/occi/bin/helpers.rb', line 26

def helper_describe(options, output = nil)
  found = []

  if resource_types.include?(options.resource) || options.resource.start_with?(options.endpoint) || options.resource.start_with?('/')
    Occi::Log.debug "#{options.resource} is a resource type or an actual resource."

    found = describe(options.resource)
  elsif mixin_types.include? options.resource
    Occi::Log.debug "#{options.resourcre} is a mixin type."

    mixins(options.resource).each do |mxn|
      mxn = mxn.split("#").last
      found << mixin(mxn, options.resource, true)
    end
  elsif mixin_types.include? options.resource.split('#').first
    Occi::Log.debug "#{options.resource} is a specific mixin type."

    mxn_type,mxn = options.resource.split('#')
    found << mixin(mxn, mxn_type, true)
  else
    Occi::Log.warn "I have no idea what #{options.resource} is ..."
    raise "Unknown resource #{options.resource}, there is nothing to describe here!"
  end

  return found if output.nil?

  if options.resource.start_with? options.endpoint
    # resource contains full endpoint URI
    # e.g., http://localhost:3300/network/adfgadf-daf5a6df4afadf-adfad65f4ad
    resource_type = options.resource.split('/')[3].to_sym
  elsif options.resource.start_with? '/'
    # resource contains a path relative to endpoint URI
    # e.g., /network/adfgadf-daf5a6df4afadf-adfad65f4ad
    resource_type = options.resource.split('/')[1].to_sym
  elsif mixin_types.include? options.resource.split('#').first
    # resource contains a mixin with a type
    # e.g., os_tpl#debian6
    resource_type = options.resource.split('#').first.to_sym
  else
    # resource probably contains RAW resource_type
    resource_type = options.resource.to_sym
  end

  if Occi::Bin::ResourceOutputFactory.allowed_resource_types.include? resource_type
    puts output.format(found, :resources, resource_type)
  else
    Occi::Log.warn "Not printing, the resource type [#{resource_type.to_s}] is not supported!"
  end
end

#helper_list(options, output = nil) ⇒ Object

a bunch of OCCI client helpers for bin/occi


3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/occi/bin/helpers.rb', line 3

def helper_list(options, output = nil)
  found = []

  if resource_types.include? options.resource
    Occi::Log.debug "#{options.resource} is a resource type."
    found = list options.resource
  elsif mixin_types.include? options.resource
    Occi::Log.debug "#{options.resource} is a mixin type."
    found = mixins options.resource
  else
    Occi::Log.warn "I have no idea what #{options.resource} is ..."
    raise "Unknown resource #{options.resource}, there is nothing to list here!"
  end

  return found if output.nil?

  if Occi::Bin::ResourceOutputFactory.allowed_resource_types.include? options.resource.to_sym
    puts output.format(found, :locations, options.resource.to_sym)
  else
    Occi::Log.warn "Not printing, the resource type is not supported!"
  end
end

#helper_trigger(options, output = nil) ⇒ Object


147
148
149
# File 'lib/occi/bin/helpers.rb', line 147

def helper_trigger(options, output = nil)
  raise "Not yet implemented!"
end