Class: OvirtSDK4::DataCentersService

Inherits:
Service
  • Object
show all
Defined in:
lib/ovirtsdk4/services.rb,
lib/ovirtsdk4/services.rb

Instance Method Summary (collapse)

Instance Method Details

- (DataCenter) add(data_center, opts = {})

Adds a new data_center.

Parameters:

Returns:



5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
# File 'lib/ovirtsdk4/services.rb', line 5088

def add(data_center, opts = {})
  if data_center.is_a?(Hash)
    data_center = OvirtSDK4::DataCenter.new(data_center)
  end
  request = Request.new(:method => :POST, :path => @path)
  begin
    writer = XmlWriter.new(nil, true)
    DataCenterWriter.write_one(data_center, writer, 'data_center')
    request.body = writer.string
  ensure
    writer.close
  end
  response = @connection.send(request)
  case response.code
  when 201, 202
    begin
      reader = XmlReader.new(response.body)
      return DataCenterReader.read_one(reader)
    ensure
      reader.close
    end
  else
    check_fault(response)
  end
end

- (DataCenterService) data_center_service(id)

Locates the data_center service.

Parameters:

  • id (String)

    The identifier of the data_center.

Returns:



5174
5175
5176
# File 'lib/ovirtsdk4/services.rb', line 5174

def data_center_service(id)
  return DataCenterService.new(@connection, "#{@path}/#{id}")
end

- (Array<DataCenter>) list(opts = {})

Returns the representation of the object managed by this service.

Parameters:

  • opts (Hash) (defaults to: {})

    Additional options.

Options Hash (opts):

  • :case_sensitive (Boolean)

    Indicates if the search performed using the search parameter should be performed taking case into account. The default value is true, which means that case is taken into account. If you want to search ignoring case set it to false.

  • :filter (Boolean)

    Indicates if the results should be filtered according to the permissions of the user.

  • :max (Integer)

    Sets the maximum number of data centers to return. If not specified all the data centers are returned.

  • :search (String)

    A query string used to restrict the returned data centers.

Returns:



5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
# File 'lib/ovirtsdk4/services.rb', line 5131

def list(opts = {})
  query = {}
  value = opts[:case_sensitive]
  unless value.nil?
    value = Writer.render_boolean(value)
    query['case_sensitive'] = value
  end
  value = opts[:filter]
  unless value.nil?
    value = Writer.render_boolean(value)
    query['filter'] = value
  end
  value = opts[:max]
  unless value.nil?
    value = Writer.render_integer(value)
    query['max'] = value
  end
  value = opts[:search]
  unless value.nil?
    query['search'] = value
  end
  request = Request.new(:method => :GET, :path => @path, :query => query)
  response = @connection.send(request)
  case response.code
  when 200
    begin
      reader = XmlReader.new(response.body)
      return DataCenterReader.read_many(reader)
    ensure
      reader.close
    end
  else
    check_fault(response)
  end
end

- (Service) service(path)

Locates the service corresponding to the given path.

Parameters:

  • path (String)

    The path of the service.

Returns:

  • (Service)

    A reference to the service.



5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
# File 'lib/ovirtsdk4/services.rb', line 5185

def service(path)
  if path.nil? || path == ''
    return self
  end
  index = path.index('/')
  if index.nil?
    return data_center_service(path)
  end
  return data_center_service(path[0..(index - 1)]).service(path[(index +1)..-1])
end

- (String) to_s

Returns an string representation of this service.

Returns:

  • (String)


5201
5202
5203
# File 'lib/ovirtsdk4/services.rb', line 5201

def to_s
  return "#<#{DataCentersService}:#{@path}>"
end