Creates a new implementation of the service.
@param connection [Connection] The connection to be used by this service.
@param path [String] The relative path of this service, for example `vms/123/disks`.
@api private
# File lib/ovirtsdk4/services.rb, line 5821 def initialize(connection, path) @connection = connection @path = path end
Creates a new data center.
Creation of a new data center requires the `name` and `local` elements. For example, to create a data center named `mydc` that uses shared storage (NFS, iSCSI or fibre channel) send a request like this:
POST /ovirt-engine/api/datacenters
With a request body like this:
<data_center>
<name>mydc</name> <local>false</local>
</data_center>
@param data_center [DataCenter] The data center that is being added.
@param opts [Hash] Additional options.
@return [DataCenter]
# File lib/ovirtsdk4/services.rb, line 5853 def add(data_center, opts = {}) if data_center.is_a?(Hash) data_center = OvirtSDK4::DataCenter.new(data_center) end query = {} request = HttpRequest.new(method: :POST, url: @path, query: query) begin writer = XmlWriter.new(nil, true) DataCenterWriter.write_one(data_center, writer) request.body = writer.string ensure writer.close end response = @connection.send(request) case response.code when 200, 201, 202 begin reader = XmlReader.new(response.body) return DataCenterReader.read_one(reader) ensure reader.close end else check_fault(response) end end
Reference to the service that manages a specific data center.
@param id [String] The identifier of the `data_center`.
@return [DataCenterService] A reference to the `data_center` service.
# File lib/ovirtsdk4/services.rb, line 5996 def data_center_service(id) DataCenterService.new(@connection, "#{@path}/#{id}") end
Lists the data centers.
The following request retrieves a representation of the data centers:
GET /ovirt-engine/api/datacenters
The above request performed with `curl`:
curl \ –request GET \ –cacert /etc/pki/ovirt-engine/ca.pem \ –header “Version: 4” \ –header “Accept: application/xml” \ –user “admin@internal:mypassword” \ myengine.example.com/ovirt-engine/api/datacenters
This is what an example response could look like:
<data_center href=“/ovirt-engine/api/datacenters/123” id=“123”>
<name>Default</name> <description>The default Data Center</description> <link href="/ovirt-engine/api/datacenters/123/networks" rel="networks"/> <link href="/ovirt-engine/api/datacenters/123/storagedomains" rel="storagedomains"/> <link href="/ovirt-engine/api/datacenters/123/permissions" rel="permissions"/> <link href="/ovirt-engine/api/datacenters/123/clusters" rel="clusters"/> <link href="/ovirt-engine/api/datacenters/123/qoss" rel="qoss"/> <link href="/ovirt-engine/api/datacenters/123/iscsibonds" rel="iscsibonds"/> <link href="/ovirt-engine/api/datacenters/123/quotas" rel="quotas"/> <local>false</local> <quota_mode>disabled</quota_mode> <status>up</status> <supported_versions> <version> <major>4</major> <minor>0</minor> </version> </supported_versions> <version> <major>4</major> <minor>0</minor> </version>
</data_center>
Note the `id` code of your `Default` data center. This code identifies this data center in relation to other resources of your virtual environment.
The data center also contains a link to the storage domains collection. The data center uses this collection to attach storage domains from the storage domains main collection.
@param opts [Hash] Additional options.
@option opts [Boolean] :case_sensitive 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`.
@option opts [Boolean] :filter Indicates if the results should be filtered according to the permissions of the user.
@option opts [Integer] :max Sets the maximum number of data centers to return. If not specified all the data centers are returned.
@option opts [String] :search A query string used to restrict the returned data centers.
@return [Array<DataCenter>]
# File lib/ovirtsdk4/services.rb, line 5953 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 = HttpRequest.new(method: :GET, url: @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
Locates the service corresponding to the given path.
@param path [String] The path of the service.
@return [Service] A reference to the service.
# File lib/ovirtsdk4/services.rb, line 6007 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
Returns an string representation of this service.
@return [String]
# File lib/ovirtsdk4/services.rb, line 6023 def to_s "#<#{DataCentersService}:#{@path}>" end