This file is indexed.

/usr/lib/ruby/vendor_ruby/fog/compute/ecloud/requests/virtual_machine_create_from_template.rb is in ruby-fog-ecloud 0.1.1-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 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
 75
 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
module Fog
  module Compute
    class Ecloud
      module Shared
        def validate_create_server_options(template_uri, options)
          required_opts = [:name, :cpus, :memory, :row, :group, :customization, :network_uri]
          if options[:customization] == :windows
            required_opts.push(:windows_password)
          else
            required_opts.push(:ssh_key_uri)
          end
          unless required_opts.all? { |opt| options.key?(opt) }
            raise ArgumentError.new("Required data missing: #{(required_opts - options.keys).map(&:inspect).join(", ")}")
          end

          options[:network_uri] = options[:network_uri].is_a?(String) ? [options[:network_uri]] : options[:network_uri]
          options[:network_uri].map! do |uri|
            network = get_network(uri).body
            if options[:ips]
              ip = options[:ips][options[:network_uri].index(uri)]
            end
            {:href => uri, :name => network[:name], :ip => ip}
          end
          options[:template_uri] = template_uri
          options
        end

        def build_request_body(options)
          xml = Builder::XmlMarkup.new
          xml.CreateVirtualMachine(:name => options[:name]) do
            xml.ProcessorCount options[:cpus]
            xml.Memory do
              xml.Unit "MB"
              xml.Value options[:memory]
            end
            xml.Layout do
              xml.NewRow options[:row]
              xml.NewGroup options[:group]
            end
            xml.Description options[:description]
            xml.Tags do
              options[:tags].each do |tag|
                xml.Tag tag
              end
            end
            if options[:customization] == :windows
              xml.WindowsCustomization do
                xml.NetworkSettings do
                  xml.NetworkAdapterSettings do
                    options[:network_uri].each do |uri|
                      xml.NetworkAdapter do
                        xml.Network(:href => uri[:href], :name => uri[:name], :type => "application/vnd.tmrk.cloud.network")
                        xml.IpAddress uri[:ip]
                      end
                    end
                  end
                  if options[:dns_settings]
                    xml.DnsSettings do
                      xml.PrimaryDns options[:dns_settings][:primary_dns]
                      if options[:dns_settings][:secondary_dns]
                        xml.SecondaryDns options[:dns_settings][:secondary_dns]
                      end
                    end
                  end
                end
                xml.Password options[:windows_password]
                if options[:windows_license_key]
                  xml.LicenseKey options[:windows_license_key]
                end
              end
            else
              xml.LinuxCustomization do
                xml.NetworkSettings do
                  xml.NetworkAdapterSettings do
                    options[:network_uri] = options[:network_uri].is_a?(String) ? [options[:network_uri]] : options[:network_uri]
                    options[:network_uri].each do |uri|
                      xml.NetworkAdapter do
                        xml.Network(:href => uri[:href], :name => uri[:name], :type => "application/vnd.tmrk.cloud.network")
                        xml.IpAddress uri[:ip]
                      end
                    end
                  end
                  if options[:dns_settings]
                    xml.DnsSettings do
                      xml.PrimaryDns options[:dns_settings][:primary_dns]
                      if options[:dns_settings][:secondary_dns]
                        xml.SecondaryDns options[:dns_settings][:secondary_dns]
                      end
                    end
                  end
                end
                xml.SshKey(:href => options[:ssh_key_uri])
              end
            end
            xml.PoweredOn options[:powered_on]
            xml.Template(:href => options[:template_uri], :type => options[:template_type])
          end
        end
      end

      class Real
        def virtual_machine_create_from_template(template_uri, options)
          options = validate_create_server_options(template_uri, options)

          request(
            :expects => 201,
            :method  => "POST",
            :body    => build_request_body(options),
            :uri     => options[:uri],
            :parse   => true
          )
        end
      end

      class Mock
        def virtual_machine_create_from_template(template_uri, options)
          options                      = validate_create_server_options(template_uri, options)
          server_id                    = Fog::Mock.random_numbers(7).to_i
          row_id                       = Fog::Mock.random_numbers(6).to_i
          group_id                     = Fog::Mock.random_numbers(6).to_i
          template_id, compute_pool_id = template_uri.match(/\/templates\/(\d+)\/computepools\/(\d+)$/).captures
          compute_pool                 = self.data[:compute_pools][compute_pool_id.to_i].dup
          environment                  = self.data[:environments][compute_pool[:environment_id]]
          layout                       = self.data[:layouts][environment[:id]]
          networks                     = options[:network_uri]
          nics                         = networks.each_with_index.map do |network, i|
            {
              :UnitNumber => i.to_s,
              :Name       => "Network adapter #{i}",
              :MacAddress => Fog::Ecloud.mac_address,
              :Network    => Fog::Ecloud.keep(network, :name, :href, :type),
            }
          end

          links = [Fog::Ecloud.keep(compute_pool, :name, :href, :type), Fog::Ecloud.keep(environment, :name, :href, :type)]
          networks.each do |network|
            links << Fog::Ecloud.keep(network, :name, :href, :type)
            network_id = id_from_uri(network[:href])
            ip = self.data[:networks][network_id][:IpAddresses][:IpAddress].find { |ip| ip[:id] = network[:ip] }
            ip[:DetectedOn] = {:href => "/cloudapi/ecloud/networkhosts/#{server_id}", :name => options[:name], :type => "application/vnd.tmrk.cloud.networkHost"}
            ip[:Host]       = {:href => "/cloudapi/ecloud/networkhosts/#{server_id}", :name => options[:name], :type => "application/vnd.tmrk.cloud.networkHost"}
          end

          server = {
            :href                  => "/cloudapi/ecloud/virtualmachines/#{server_id}",
            :name                  => options[:name],
            :type                  => "application/vnd.tmrk.cloud.virtualMachine",
            :Description           => options[:description],
            :Status                => "Deployed",
            :HardwareConfiguration => {
              :href => "/cloudapi/ecloud/virtualmachines/#{server_id}/hardwareconfiguration",
              :type => "application/vnd.tmrk.cloud.virtualMachineHardware",
              :Links => {
                :Link => {
                  :href => "/cloudapi/ecloud/virtualmachines/#{server_id}",
                  :name => options[:name],
                  :type => "application/vnd.tmrk.cloud.virtualMachine",
                  :rel  => "up",
                }
              },
              :ProcessorCount => options[:cpus],
              :Memory => {
                :Unit  => "MB",
                :Value => options[:memory],
              },
              :Disks => {
                :Disk => [{
                  :Index => "0",
                  :Name  => "Hard Disk 1",
                  :Size  => {
                    :Unit  => "GB",
                    :Value => "25",
                  },
                }],
              },
              :Nics => {
                :Nic => nics,
              },
            },
            :IpAddresses => {
              :AssignedIpAddresses => {
                :Networks => {
                  :Network => self.data[:networks].dup.values,
                }
              }
            },
            :Links => { :Link => links },
          }

          row = {
            :id => row_id,
            :name => options[:row],
            :href => "/cloudapi/ecloud/layoutrows/#{row_id}",
            :type => "application/vnd.tmrk.cloud.layoutRow",
            :Links => {
              :Link => [
                Fog::Ecloud.keep(environment, :name, :href, :type)
              ],
            },
            :Index => 0,
            :Groups => {
              :Group => [
              ],
            },
            :environment_id => environment[:id],
          }

          group = {
            :id => group_id,
            :name => options[:group],
            :href => "/cloudapi/ecloud/layoutgroups/#{group_id}",
            :type => "application/vnd.tmrk.cloud.layoutGroup",
            :Links => {
              :Link => [
                Fog::Ecloud.keep(row, :name, :href, :type),
              ],
            },
            :Index => 0,
            :VirtualMachines => {
              :VirtualMachine => [
                server,
              ],
            },
            :row_id => row_id,
          }
          row[:Groups][:Group].push(group)
          layout[:Rows][:Row].push(row)

          server.merge!(:OperatingSystem => options[:operating_system].merge(:type => "application/vnd.tmrk.cloud.operatingSystem")) if options[:operating_system]

          server_response = response(:body =>  server)

          server.merge!(:compute_pool_id => compute_pool[:id])

          self.data[:servers][server_id] = server
          self.data[:rows][row_id]       = row
          self.data[:groups][group_id]   = group

          server_response
        end
      end
    end
  end
end