virtengine_api 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (151) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +21 -0
  3. data/.travis.yml +11 -0
  4. data/Gemfile +5 -0
  5. data/LICENSE +21 -0
  6. data/README.md +27 -0
  7. data/Rakefile +10 -0
  8. data/lib/megam/api.rb +329 -0
  9. data/lib/megam/api/accounts.rb +96 -0
  10. data/lib/megam/api/addons.rb +27 -0
  11. data/lib/megam/api/assemblies.rb +49 -0
  12. data/lib/megam/api/assembly.rb +56 -0
  13. data/lib/megam/api/backups.rb +57 -0
  14. data/lib/megam/api/balances.rb +45 -0
  15. data/lib/megam/api/billedhistories.rb +35 -0
  16. data/lib/megam/api/billingtransactions.rb +25 -0
  17. data/lib/megam/api/components.rb +24 -0
  18. data/lib/megam/api/credits.rb +34 -0
  19. data/lib/megam/api/disks.rb +44 -0
  20. data/lib/megam/api/domains.rb +25 -0
  21. data/lib/megam/api/errors.rb +29 -0
  22. data/lib/megam/api/eventsall.rb +36 -0
  23. data/lib/megam/api/eventsbilling.rb +35 -0
  24. data/lib/megam/api/eventscontainer.rb +35 -0
  25. data/lib/megam/api/eventsmarketplace.rb +35 -0
  26. data/lib/megam/api/eventsstorage.rb +24 -0
  27. data/lib/megam/api/eventsvm.rb +35 -0
  28. data/lib/megam/api/flavors.rb +56 -0
  29. data/lib/megam/api/license.rb +26 -0
  30. data/lib/megam/api/marketplaces.rb +68 -0
  31. data/lib/megam/api/organizations.rb +50 -0
  32. data/lib/megam/api/promos.rb +18 -0
  33. data/lib/megam/api/quotas.rb +47 -0
  34. data/lib/megam/api/rawimages.rb +36 -0
  35. data/lib/megam/api/reports.rb +24 -0
  36. data/lib/megam/api/requests.rb +36 -0
  37. data/lib/megam/api/sensors.rb +35 -0
  38. data/lib/megam/api/snapshots.rb +46 -0
  39. data/lib/megam/api/sshkeys.rb +35 -0
  40. data/lib/megam/api/subscriptions.rb +26 -0
  41. data/lib/megam/api/version.rb +6 -0
  42. data/lib/megam/core/account.rb +245 -0
  43. data/lib/megam/core/account_collection.rb +122 -0
  44. data/lib/megam/core/addons.rb +169 -0
  45. data/lib/megam/core/addons_collection.rb +121 -0
  46. data/lib/megam/core/assemblies.rb +191 -0
  47. data/lib/megam/core/assemblies_collection.rb +122 -0
  48. data/lib/megam/core/assembly.rb +226 -0
  49. data/lib/megam/core/assembly_collection.rb +122 -0
  50. data/lib/megam/core/backups.rb +259 -0
  51. data/lib/megam/core/backups_collection.rb +122 -0
  52. data/lib/megam/core/balances.rb +187 -0
  53. data/lib/megam/core/balances_collection.rb +121 -0
  54. data/lib/megam/core/billedhistories.rb +190 -0
  55. data/lib/megam/core/billedhistories_collection.rb +121 -0
  56. data/lib/megam/core/billingtransactions.rb +214 -0
  57. data/lib/megam/core/billingtransactions_collection.rb +122 -0
  58. data/lib/megam/core/components.rb +326 -0
  59. data/lib/megam/core/components_collection.rb +123 -0
  60. data/lib/megam/core/credits.rb +146 -0
  61. data/lib/megam/core/credits_collection.rb +121 -0
  62. data/lib/megam/core/disks.rb +199 -0
  63. data/lib/megam/core/disks_collection.rb +122 -0
  64. data/lib/megam/core/domain_collection.rb +122 -0
  65. data/lib/megam/core/domains.rb +118 -0
  66. data/lib/megam/core/error.rb +70 -0
  67. data/lib/megam/core/eventsall.rb +186 -0
  68. data/lib/megam/core/eventsall_collection.rb +122 -0
  69. data/lib/megam/core/eventsbilling.rb +174 -0
  70. data/lib/megam/core/eventsbilling_collection.rb +122 -0
  71. data/lib/megam/core/eventscontainer.rb +187 -0
  72. data/lib/megam/core/eventscontainer_collection.rb +122 -0
  73. data/lib/megam/core/eventsmarketplace.rb +187 -0
  74. data/lib/megam/core/eventsmarketplace_collection.rb +122 -0
  75. data/lib/megam/core/eventsstorage.rb +156 -0
  76. data/lib/megam/core/eventsstorage_collection.rb +122 -0
  77. data/lib/megam/core/eventsvm.rb +187 -0
  78. data/lib/megam/core/eventsvm_collection.rb +122 -0
  79. data/lib/megam/core/flavors.rb +294 -0
  80. data/lib/megam/core/flavors_collection.rb +121 -0
  81. data/lib/megam/core/json_compat.rb +289 -0
  82. data/lib/megam/core/konipai.rb +42 -0
  83. data/lib/megam/core/license.rb +101 -0
  84. data/lib/megam/core/license_collection.rb +122 -0
  85. data/lib/megam/core/log.rb +19 -0
  86. data/lib/megam/core/marketplace.rb +308 -0
  87. data/lib/megam/core/marketplace_collection.rb +123 -0
  88. data/lib/megam/core/monologger.rb +89 -0
  89. data/lib/megam/core/organizations.rb +142 -0
  90. data/lib/megam/core/organizations_collection.rb +121 -0
  91. data/lib/megam/core/promos.rb +145 -0
  92. data/lib/megam/core/quotas.rb +215 -0
  93. data/lib/megam/core/quotas_collection.rb +121 -0
  94. data/lib/megam/core/rawimages.rb +194 -0
  95. data/lib/megam/core/rawimages_collection.rb +121 -0
  96. data/lib/megam/core/reports.rb +176 -0
  97. data/lib/megam/core/reports_collection.rb +121 -0
  98. data/lib/megam/core/request.rb +197 -0
  99. data/lib/megam/core/request_collection.rb +121 -0
  100. data/lib/megam/core/rest_adapter.rb +44 -0
  101. data/lib/megam/core/sensors.rb +141 -0
  102. data/lib/megam/core/sensors_collection.rb +121 -0
  103. data/lib/megam/core/snapshots.rb +268 -0
  104. data/lib/megam/core/snapshots_collection.rb +122 -0
  105. data/lib/megam/core/sshkey.rb +173 -0
  106. data/lib/megam/core/sshkey_collection.rb +122 -0
  107. data/lib/megam/core/stuff.rb +22 -0
  108. data/lib/megam/core/subscriptions.rb +167 -0
  109. data/lib/megam/core/subscriptions_collection.rb +121 -0
  110. data/lib/megam/core/text.rb +87 -0
  111. data/lib/megam/core/text_formatter.rb +64 -0
  112. data/lib/megam/mixins/assemblies.rb +16 -0
  113. data/lib/megam/mixins/assembly.rb +59 -0
  114. data/lib/megam/mixins/common_deployable.rb +78 -0
  115. data/lib/megam/mixins/components.rb +182 -0
  116. data/lib/megam/mixins/megam_attributes.rb +30 -0
  117. data/lib/megam/mixins/outputs.rb +23 -0
  118. data/lib/megam/mixins/policies.rb +27 -0
  119. data/lib/megam_api.rb +1 -0
  120. data/megam_api.gemspec +26 -0
  121. data/test/mixins/test_assemblies.rb +113 -0
  122. data/test/mixins/test_assembly.rb +74 -0
  123. data/test/mixins/test_component.rb +19 -0
  124. data/test/test_accounts.rb +127 -0
  125. data/test/test_addons.rb +26 -0
  126. data/test/test_assemblies.rb +88 -0
  127. data/test/test_assembly.rb +37 -0
  128. data/test/test_backups.rb +29 -0
  129. data/test/test_balances.rb +38 -0
  130. data/test/test_billedhistories.rb +30 -0
  131. data/test/test_billingtranscations.rb +35 -0
  132. data/test/test_components.rb +42 -0
  133. data/test/test_credits.rb +28 -0
  134. data/test/test_disks.rb +25 -0
  135. data/test/test_domains.rb +29 -0
  136. data/test/test_eventsbilling.rb +30 -0
  137. data/test/test_eventscontainer.rb +26 -0
  138. data/test/test_eventsstorage.rb +12 -0
  139. data/test/test_eventsvm.rb +26 -0
  140. data/test/test_helper.rb +77 -0
  141. data/test/test_marketplaces.rb +38 -0
  142. data/test/test_organizations.rb +45 -0
  143. data/test/test_promos.rb +11 -0
  144. data/test/test_quotas.rb +33 -0
  145. data/test/test_reports.rb +32 -0
  146. data/test/test_requests.rb +95 -0
  147. data/test/test_sensors.rb +50 -0
  148. data/test/test_snapshots.rb +30 -0
  149. data/test/test_sshkeys.rb +50 -0
  150. data/test/test_subscriptions.rb +22 -0
  151. metadata +325 -0
@@ -0,0 +1,121 @@
1
+ module Megam
2
+ class SubscriptionsCollection
3
+ include Enumerable
4
+
5
+ attr_reader :iterator
6
+ def initialize
7
+ @subscriptions = Array.new
8
+ @subscriptions_by_name = Hash.new
9
+ @insert_after_idx = nil
10
+ end
11
+
12
+ def all_subscriptions
13
+ @subscriptions
14
+ end
15
+
16
+ def [](index)
17
+ @subscriptions[index]
18
+ end
19
+
20
+ def []=(index, arg)
21
+ is_megam_subscriptions(arg)
22
+ @subscriptions[index] = arg
23
+ @subscriptions_by_name[arg.account_id] = index
24
+ end
25
+
26
+ def <<(*args)
27
+ args.flatten.each do |a|
28
+ is_megam_subscriptions(a)
29
+ @subscriptions << a
30
+ @subscriptions_by_name[a.account_id] =@subscriptions.length - 1
31
+ end
32
+ self
33
+ end
34
+
35
+ # 'push' is an alias method to <<
36
+ alias_method :push, :<<
37
+
38
+ def insert(subscriptions)
39
+ is_megam_subscriptions(subscriptions)
40
+ if @insert_after_idx
41
+ # in the middle of executing a run, so any predefs inserted now should
42
+ # be placed after the most recent addition done by the currently executing
43
+ # subscriptions
44
+ @subscriptions.insert(@insert_after_idx + 1, subscriptions)
45
+ # update name -> location mappings and register new subscriptions
46
+ @subscriptions_by_name.each_key do |key|
47
+ @subscriptions_by_name[key] += 1 if@subscriptions_by_name[key] > @insert_after_idx
48
+ end
49
+ @subscriptions_by_name[subscriptions.account_id] = @insert_after_idx + 1
50
+ @insert_after_idx += 1
51
+ else
52
+ @subscriptions << subscriptions
53
+ @subscriptions_by_name[subscriptions.account_id] =@subscriptions.length - 1
54
+ end
55
+ end
56
+
57
+ def each
58
+ @subscriptions.each do |subscriptions|
59
+ yield subscriptions
60
+ end
61
+ end
62
+
63
+ def each_index
64
+ @subscriptions.each_index do |i|
65
+ yield i
66
+ end
67
+ end
68
+
69
+ def empty?
70
+ @subscriptions.empty?
71
+ end
72
+
73
+ def lookup(subscriptions)
74
+ lookup_by = nil
75
+ if Subscriptions.kind_of?(Megam::Subscriptions)
76
+ lookup_by = subscriptions.account_id
77
+ elsif subscriptions.kind_of?(String)
78
+ lookup_by = subscriptions
79
+ else
80
+ raise ArgumentError, "Must pass a Megam::Subscriptions or String to lookup"
81
+ end
82
+ res =@subscriptions_by_name[lookup_by]
83
+ unless res
84
+ raise ArgumentError, "Cannot find a subscriptions matching #{lookup_by} (did you define it first?)"
85
+ end
86
+ @subscriptions[res]
87
+ end
88
+
89
+ def to_s
90
+ @subscriptions.join(", ")
91
+ end
92
+
93
+ def for_json
94
+ to_a.map { |item| item.to_s }
95
+ end
96
+
97
+ def to_json(*a)
98
+ Megam::JSONCompat.to_json(for_json, *a)
99
+ end
100
+
101
+ def self.json_create(o)
102
+ collection = self.new()
103
+ o["results"].each do |subscriptions_list|
104
+ subscriptions_array = subscriptions_list.kind_of?(Array) ? subscriptions_list : [ subscriptions_list ]
105
+ subscriptions_array.each do |subscriptions|
106
+ collection.insert(subscriptions)
107
+ end
108
+ end
109
+ collection
110
+ end
111
+
112
+ private
113
+
114
+ def is_megam_subscriptions(arg)
115
+ unless arg.kind_of?(Megam::Subscriptions)
116
+ raise ArgumentError, "Members must be Megam::subscriptions's"
117
+ end
118
+ true
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,87 @@
1
+ require "megam/core/text_formatter"
2
+ module Megam
3
+ class Text
4
+
5
+ attr_reader :stdout
6
+ attr_reader :stderr
7
+ attr_reader :stdin
8
+ attr_reader :config
9
+
10
+ def initialize(stdout, stderr, stdin, config)
11
+ @stdout, @stderr, @stdin, @config = stdout, stderr, stdin, config
12
+ end
13
+
14
+ def highline
15
+ @highline ||= begin
16
+ require 'highline'
17
+ HighLine.new
18
+ end
19
+ end
20
+
21
+ # Summarize the data. Defaults to text format output,
22
+ # which may not be very summary-like
23
+ def summarize(data)
24
+ text_format(data)
25
+ end
26
+
27
+ # Converts the +data+ to a String in the text format. Uses
28
+ # Chef::Knife::Core::TextFormatter
29
+ def text_format(data)
30
+ Megam::TextFormatter.new(data, self).formatted_data
31
+ end
32
+
33
+ def msg(message)
34
+ stdout.puts message
35
+ end
36
+
37
+ # Prints a message to stdout. Aliased as +info+ for compatibility with
38
+ # the logger API.
39
+
40
+ def info(message)
41
+ stdout.puts("#{color('INFO:', :green, :bold)} #{message}")
42
+ end
43
+
44
+ # Prints a msg to stderr. Used for warn, error, and fatal.
45
+ def err(message)
46
+ stderr.puts message
47
+ end
48
+
49
+ # Print a warning message
50
+ def warn(message)
51
+ err("#{color('WARNING:', :yellow, :bold)} #{message}")
52
+ end
53
+
54
+ # Print an error message
55
+ def error(message)
56
+ err("#{color('ERROR:', :red, :bold)} #{message}")
57
+ end
58
+
59
+ # Print a message describing a fatal error.
60
+ def fatal(message)
61
+ err("#{color('FATAL:', :red, :bold)} #{message}")
62
+ end
63
+
64
+ def color(string, *colors)
65
+ if color?
66
+ highline.color(string, *colors)
67
+ else
68
+ string
69
+ end
70
+ end
71
+
72
+ # Should colored output be used ?. When output is not to a
73
+ # terminal, colored output is never used
74
+ def color?
75
+ stdout.tty?
76
+ end
77
+
78
+ def list(*args)
79
+ highline.list(*args)
80
+ end
81
+
82
+ def pretty_print(data)
83
+ stdout.puts data
84
+ end
85
+
86
+ end
87
+ end
@@ -0,0 +1,64 @@
1
+ module Megam
2
+ class TextFormatter
3
+
4
+ attr_reader :data
5
+ attr_reader :ui
6
+
7
+ def initialize(data, ui)
8
+ @ui = ui
9
+ @data = if data.respond_to?(:display_hash)
10
+ data.display_hash
11
+ elsif data.kind_of?(Array)
12
+ data
13
+ elsif data.respond_to?(:to_hash)
14
+ data.to_hash
15
+ else
16
+ data
17
+ end
18
+ end
19
+
20
+ def formatted_data
21
+ @formatted_data ||= text_format(data)
22
+ end
23
+
24
+ def text_format(data)
25
+ buffer = ''
26
+
27
+ if data.respond_to?(:keys)
28
+ justify_width = data.keys.map {|k| k.to_s.size }.max.to_i + 1
29
+ data.sort.each do |key, value|
30
+ # key: ['value'] should be printed as key: value
31
+ if value.kind_of?(Array) && value.size == 1 && is_singleton(value[0])
32
+ value = value[0]
33
+ end
34
+ if is_singleton(value)
35
+ # Strings are printed as key: value.
36
+ justified_key = ui.color("#{key}:".ljust(justify_width), :cyan)
37
+ buffer << "#{justified_key} #{value}\n"
38
+ else
39
+ # Arrays and hashes get indented on their own lines.
40
+ buffer << ui.color("#{key}:\n", :cyan)
41
+ lines = text_format(value).split("\n")
42
+ lines.each { |line| buffer << " #{line}\n" }
43
+ end
44
+ end
45
+ elsif data.kind_of?(Array)
46
+ data.each_index do |index|
47
+ item = data[index]
48
+ buffer << text_format(data[index])
49
+ # Separate items with newlines if it's an array of hashes or an
50
+ # array of arrays
51
+ buffer << "\n" if !is_singleton(data[index]) && index != data.size-1
52
+ end
53
+ else
54
+ buffer << "#{data}\n"
55
+ end
56
+ buffer
57
+ end
58
+
59
+ def is_singleton(value)
60
+ !(value.kind_of?(Array) || value.respond_to?(:keys))
61
+ end
62
+
63
+ end
64
+ end
@@ -0,0 +1,16 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/assembly")
2
+
3
+ module Megam
4
+ class Mixins
5
+ class Assemblies
6
+ attr_reader :assembly
7
+ def initialize(params)
8
+ @assembly = Assembly.new(params)
9
+ end
10
+
11
+ def to_hash
12
+ assembly.to_hash
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,59 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/common_deployable")
2
+ require File.expand_path("#{File.dirname(__FILE__)}/components")
3
+ require File.expand_path("#{File.dirname(__FILE__)}/outputs")
4
+
5
+ module Megam
6
+ class Mixins
7
+ class Assembly
8
+ attr_reader :id, :name, :components, :policies, :outputs, :envs, :mixins
9
+ DEFAULT_VERTICE_PREFIX = 'vertice'.freeze
10
+ DEFAULT_DOCKER_PREFIX = 'docker'.freeze
11
+ TORPEDO = 'TORPEDO'.freeze
12
+ def initialize(params)
13
+ params = Hash[params.map { |k, v| [k.to_sym, v] }]
14
+ @id = params[:id] || params[:assemblyID] || ''
15
+ @name = params[:assemblyname]
16
+ @mixins = CommonDeployable.new(params)
17
+ @outputs = Outputs.new(params)
18
+ @components = add_components(params)
19
+ @tosca_type = add_assembly_tosca_type(params)
20
+ @policies = []
21
+ end
22
+
23
+ def to_hash
24
+ result = @mixins.to_hash
25
+ result[:id] = @id if @id
26
+ result[:name] = @name if @name
27
+ result[:components] = @components if @components
28
+ result[:outputs] = @outputs.to_array if @outputs
29
+ result[:policies] = @policies if @policies
30
+ result[:tosca_type] = @tosca_type if @tosca_type
31
+ result
32
+ end
33
+
34
+ private
35
+
36
+ # If @components_enabled for type
37
+ def components_enabled?(params)
38
+ true if params[:cattype] != 'TORPEDO'.freeze
39
+ end
40
+
41
+ def add_components(params)
42
+ if components_enabled?(params)
43
+ @components = Components.new(params).to_a
44
+ else
45
+ @components = []
46
+ end
47
+ end
48
+
49
+ def add_assembly_tosca_type(params)
50
+ if params[:scm_name] == DEFAULT_DOCKER_PREFIX
51
+ @tosca_type = params[:scm_name] + ".#{TORPEDO.downcase}.#{params[:os_name].downcase}" if params[:os_name] != nil
52
+ else
53
+ @tosca_type = DEFAULT_VERTICE_PREFIX + ".#{TORPEDO.downcase}.#{params[:os_name].downcase}" if params[:os_name] != nil
54
+ end
55
+ end
56
+
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,78 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/megam_attributes")
2
+
3
+ module Megam
4
+ class Mixins
5
+ class CommonDeployable
6
+ include Nilavu::MegamAttributes
7
+ attr_reader :status, :state, :inputs
8
+ ATTRIBUTES = [
9
+ :status,
10
+ :state,
11
+ :inputs]
12
+
13
+ def attributes
14
+ ATTRIBUTES
15
+ end
16
+
17
+ def initialize(params)
18
+ @status = 'initialized'
19
+ @state = 'initialized'
20
+ set_attributes(params)
21
+ @inputs = InputGroupData.new(params)
22
+
23
+ end
24
+
25
+ def to_hash
26
+ h = {
27
+ status: status,
28
+ state: state,
29
+ inputs: inputs.to_hash
30
+ }
31
+ end
32
+ end
33
+
34
+ class InputGroupData
35
+ include Nilavu::MegamAttributes
36
+
37
+ attr_reader :domain, :keypairoption, :root_password, :sshkey, :provider, :cpu, :ram, :hdd,
38
+ :version, :display_name, :password, :region, :flavor_id, :storage_hddtype,
39
+ :public_ipv4, :private_ipv4, :public_ipv6, :private_ipv6, :bitnami_username, :bitnami_password, :root_username, :backup, :backup_name, :backup_id, :quota_ids,:app_username, :app_password, :user_launch_patternname, :flavor_id
40
+
41
+ ATTRIBUTES = [
42
+ :domain,
43
+ :keypairoption,
44
+ :root_password,
45
+ :sshkey,
46
+ :provider,
47
+ :version,
48
+ :display_name,
49
+ :password,
50
+ :region,
51
+ :flavor_id,
52
+ :storage_hddtype,
53
+ :private_ipv4,
54
+ :public_ipv4,
55
+ :private_ipv6,
56
+ :public_ipv6,
57
+ :bitnami_password,
58
+ :bitnami_username,
59
+ :app_username,
60
+ :app_password,
61
+ :root_username,
62
+ :backup,
63
+ :backup_name,
64
+ :backup_id,
65
+ :quota_ids,
66
+ :user_launch_patternname,]
67
+
68
+ def attributes
69
+ ATTRIBUTES
70
+ end
71
+
72
+ def initialize(params)
73
+ set_attributes(params)
74
+ end
75
+
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,182 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/megam_attributes")
2
+ require File.expand_path("#{File.dirname(__FILE__)}/common_deployable")
3
+ require File.expand_path("#{File.dirname(__FILE__)}/outputs")
4
+
5
+ module Megam
6
+ class Mixins
7
+ class Components
8
+ attr_reader :mixins, :name, :repo, :related_components, :operations, :artifacts, :envs, :outputs, :id, :tosca_type
9
+ DEFAULT_VERTICE_PREFIX = 'vertice'.freeze
10
+ def initialize(params)
11
+ @mixins = CommonDeployable.new(params)
12
+ @id = params[:id] if params[:id]
13
+ @name = params[:componentname] || params[:name] || ''
14
+ @outputs = Outputs.new(params)
15
+ @operations = add_operations(params)
16
+ @related_components = add_related_components(params)
17
+ @artifacts = add_artifacts(params)
18
+ @repo = add_repo(params)
19
+ @envs = params[:envs]
20
+ @tosca_type = add_components_tosca_type(params)
21
+ end
22
+
23
+ def to_hash
24
+ result = @mixins.to_hash
25
+ result[:id] = @id if @id
26
+ result[:name] = @name if @name
27
+ result[:artifacts] = @artifacts if @artifacts
28
+ result[:repo] = @repo if @repo
29
+ result[:operations] = @operations if @operations
30
+ result[:outputs] = @outputs.to_array if @outputs
31
+ result[:related_components] = @related_components if @related_components
32
+ result[:envs] = @envs if @envs
33
+ result[:tosca_type] = @tosca_type if @tosca_type
34
+ result.to_hash
35
+ end
36
+
37
+ def to_a
38
+ [to_hash]
39
+ end
40
+
41
+ private
42
+
43
+ def add_repo(params)
44
+ Repo.new(params).tohash
45
+ end
46
+
47
+ def add_related_components(params)
48
+ @related_components = []
49
+ @related_components << "#{params[:bind_type]}" if params.key?(:bind_type)
50
+ end
51
+
52
+ def add_operations(params)
53
+ operations = []
54
+ operations.push(create_operation(Operations::CI, Operations::CI_DESCRIPTON, params)) if params.key?(:scm_name) && params.key?(:scmtoken)
55
+ operations.push(create_operation(Operations::BIND, Operations::BIND_DESCRIPTON, params)) if params.key?(:bind_type)
56
+ operations
57
+ end
58
+
59
+ def create_operation(type, desc, params)
60
+ Operations.new(params, type, desc).tohash
61
+ end
62
+
63
+ def add_artifacts(params)
64
+ Artifacts.new(params).tohash
65
+ end
66
+
67
+ def add_components_tosca_type(params)
68
+ if params[:scm_name] !=nil
69
+ @tosca_type = params[:scm_name] + ".#{params[:cattype].downcase}.#{params[:mkp_name].downcase}" if params[:cattype] != nil && params[:mkp_name] != nil
70
+ else
71
+ @tosca_type = DEFAULT_VERTICE_PREFIX + ".#{params[:cattype].downcase}.#{params[:mkp_name].downcase}" if params[:cattype] != nil && params[:mkp_name] != nil
72
+ end
73
+ end
74
+
75
+ end
76
+
77
+ class Repo
78
+ include Nilavu::MegamAttributes
79
+ attr_reader :type, :source, :url, :oneclick, :branch
80
+ ATTRIBUTES = [
81
+ :type,
82
+ :source,
83
+ :oneclick,
84
+ :url,
85
+ :branch]
86
+
87
+ def attributes
88
+ ATTRIBUTES
89
+ end
90
+
91
+ def initialize(params)
92
+ set_attributes(params)
93
+ @type = params[:type] || ""
94
+ @source = params[:scm_name] || ""
95
+ @url = params[:source] || ""
96
+ @oneclick = params[:oneclick] || ""
97
+ @branch = params[:scmbranch] || ""
98
+ end
99
+
100
+ def tohash
101
+ { rtype: @type,
102
+ source: @source,
103
+ oneclick: @oneclick,
104
+ url: @url,
105
+ branch: @branch
106
+ }
107
+ end
108
+ end
109
+
110
+ class Operations
111
+ include Nilavu::MegamAttributes
112
+ attr_reader :type, :desc, :prop, :status
113
+
114
+ ATTRIBUTES = [
115
+ :type,
116
+ :desc,
117
+ :prop,
118
+ :status]
119
+
120
+ def attributes
121
+ ATTRIBUTES
122
+ end
123
+
124
+ CI = 'CI'.freeze
125
+ CI_DESCRIPTON = 'always up to date code. sweet.'
126
+ NOTBOUND = "notbound".freeze
127
+ BIND = 'bind'.freeze
128
+ BIND_DESCRIPTON = 'bind. sweet.'
129
+
130
+ def initialize(params, type, desc)
131
+ @type = type
132
+ @desc = desc
133
+ @prop = prop(params)
134
+ end
135
+
136
+ def attributes
137
+ ATTRIBUTES
138
+ end
139
+
140
+ def tohash
141
+ { operation_type: @type,
142
+ description: @desc,
143
+ properties: @prop,
144
+ status: NOTBOUND
145
+ }
146
+ end
147
+
148
+ # Key_name mismatch. Key_name is to be changed.
149
+ def prop(params)
150
+ op = []
151
+ op << { 'key' => 'type', 'value' => params[:scm_name] } if params.key?(:scm_name)
152
+ op << { 'key' => 'token', 'value' => params[:scmtoken] } if params.key?(:scmtoken)
153
+ op << { 'key' => 'username', 'value' => params[:scmowner] } if params.key?(:scmowner)
154
+ op << { 'key' => 'related_component', 'value' => params[:bind_type] } if params.key?(:bind_type)
155
+ op
156
+ end
157
+ end
158
+
159
+ class Artifacts
160
+ include Nilavu::MegamAttributes
161
+ ATTRIBUTES = [
162
+ :type,
163
+ :content,
164
+ :requirements]
165
+
166
+ def attributes
167
+ ATTRIBUTES
168
+ end
169
+
170
+ def initialize(params)
171
+ set_attributes(params)
172
+ end
173
+
174
+ def tohash
175
+ { artifact_type: '',
176
+ content: '',
177
+ requirements: []
178
+ }
179
+ end
180
+ end
181
+ end
182
+ end