Class: OvirtSDK4::AffinityLabelService

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

Instance Method Summary (collapse)

Instance Method Details

- (AffinityLabel) get(opts = {})

Retrieves details about a label.

Parameters:

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

    Additional options.

Returns:



1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
# File 'lib/ovirtsdk4/services.rb', line 1184

def get(opts = {})
  query = {}
  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 AffinityLabelReader.read_one(reader)
    ensure
      reader.close
    end
  else
    check_fault(response)
  end
end

- (AffinityLabelHostsService) hosts_service

List all Hosts with this label.

Returns:



1253
1254
1255
# File 'lib/ovirtsdk4/services.rb', line 1253

def hosts_service
  return AffinityLabelHostsService.new(@connection, "#{@path}/hosts")
end

- (Object) remove(opts = {})

Removes a label from system and clears all assignments of the removed label.

Parameters:

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

    Additional options.



1207
1208
1209
1210
1211
1212
1213
1214
# File 'lib/ovirtsdk4/services.rb', line 1207

def remove(opts = {})
  query = {}
  request = Request.new(:method => :DELETE, :path => @path, :query => query)
  response = @connection.send(request)
  unless response.code == 200
    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.

Raises:

  • (Error)


1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
# File 'lib/ovirtsdk4/services.rb', line 1272

def service(path)
  if path.nil? || path == ''
    return self
  end
  if path == 'hosts'
    return hosts_service
  end
  if path.start_with?('hosts/')
    return hosts_service.service(path[6..-1])
  end
  if path == 'vms'
    return vms_service
  end
  if path.start_with?('vms/')
    return vms_service.service(path[4..-1])
  end
  raise Error.new("The path \"#{path}\" doesn't correspond to any service")
end

- (String) to_s

Returns an string representation of this service.

Returns:

  • (String)


1296
1297
1298
# File 'lib/ovirtsdk4/services.rb', line 1296

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

- (Object) update(label)

Updates a label.

This call will update all metadata like name or description.



1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
# File 'lib/ovirtsdk4/services.rb', line 1222

def update(label)
  if label.is_a?(Hash)
    label = OvirtSDK4::AffinityLabel.new(label)
  end
  request = Request.new(:method => :PUT, :path => @path)
  begin
    writer = XmlWriter.new(nil, true)
    AffinityLabelWriter.write_one(label, writer, 'label')
    request.body = writer.string
  ensure
    writer.close
  end
  response = @connection.send(request)
  case response.code
  when 200
    begin
      reader = XmlReader.new(response.body)
      return AffinityLabelReader.read_one(reader)
    ensure
      reader.close
    end
    return result
  else
    check_fault(response)
  end
end

- (AffinityLabelVmsService) vms_service

List all VMs with this label.

Returns:



1261
1262
1263
# File 'lib/ovirtsdk4/services.rb', line 1261

def vms_service
  return AffinityLabelVmsService.new(@connection, "#{@path}/vms")
end