Ruby Example

What is Ruby?
Ruby is a dynamic, object-oriented programming language known for its simplicity and productivity. It prioritizes developer happiness with its elegant syntax and focuses on human-readable code. Ruby is often used for web development, particularly with the Ruby on Rails framework, as well as for scripting and automation tasks.

Here's a basic example of how to use Ruby to interact with the xcware API:
To interact with the xcware API, you'll need to ensure that you're sending POST requests with JSON data and expect JSON-structured data in response.
Copy
require 'uri'
require 'net/http'
require 'json'

#CREATE CONTAINER API CALL

# replace your_nexus_server_or_ip
apiUrl = URI.parse("https://your_nexus_server_or_ip/api/v3/")

# replace V7d41fdc53-xxxx-xxxx-xxxx-5c1fxxxx3cbc
@data = {
    "cloudid" => "V7d41fdc53-xxxx-xxxx-xxxx-5c1fxxxx3cbc",
    "name" => "My Container",
    "os" => "cn-rocky-9",
    "password" => "test"
}.to_json

http = Net::HTTP.new(apiUrl.host, apiUrl.port)
http.use_ssl = true
###
#    Using OpenSSL::SSL::VERIFY_NONE in the following code as a workaround for
#    self-signed certificate errors is discouraged in production environments.
###
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

req = Net::HTTP::Post.new(apiUrl, initheader = {'Content-Type' => 'application/json'})

# replace YOUR_ACCOUNT_ID
req['x-access-account'] = 'YOUR_ACCOUNT_ID'

# replace YOUR_ACCESS_KEY
req['x-access-authorization'] = 'YOUR_ACCESS_KEY'

# replace YOUR_SECRET_KEY
req['x-secret-key'] = 'YOUR_SECRET_KEY'

req['x-api'] = 'instances-cn'
req['x-api-command'] = 'create'
req.body = @data

#make the api request
res = http.request(req)

# process received JSON data
ret = JSON.parse(res.body)
if ret["result"] == "OK"
    puts "Container was created with the ID: "+ret["id"]
else
    puts "Error: "+ret["message"]
end

Request Headers
Now that we've laid down the groundwork, let's delve into the essential headers needed to construct a valid POST request for the xcware API.

x-access-account
This header denotes the account ID and is required for any request. You can find your account ID in the "Actions" menu situated at the top right corner of the Nexus interface.

x-access-authorization
This header signifies the access key linked to the roles and policies within the specified account, and it's a requisite for all requests. Please obtain your access key from your system administrator.

x-secret-key
This header indicates the secret key tied to the specified account, and it's mandatory for all requests. Please obtain your secret key from your system administrator.

x-api
This header defines the name of the API containing the commands and is obligatory. Refer to the API Builder for potential API names.

x-api-command
This header specifies the name of the function to be executed and is mandatory. Refer to the API Builder for potential command names.

Data
The "@data =" section in the code signifies the JSON structured input data transmitted to the API task and is mandatory. For potential data input options, refer to the API Builder.

Get Started with API Builder

We utilize xcware specifically for our external CAD/CAE workforce needs. Our vGPU Workstations outperform our previously used VMware Horizon on the same hardware. More importantly, it is now easier to onboard and scalable for every project.

— Mark K.
IT-Manager @ Bielomatik

I rely on xcware for crafting and implementing solutions for my clients due to its scalability and quick setup time for projects. 8 out of 10 customers remain with the initial xcware project setup, streamlining my delivery process.

— Thomas B.
Cloud Solutions Architect

We have successfully migrated 500+ servers and desktops from VMware to xcware. We extend our gratitude to the xcware Consulting Team for delivering exceptional work.

— Franco O.
IT Manager @ SportSA

We were pleasantly surprised by how effortlessly we could construct our Big Data platform and extend it to various production lines across the globe.

— Simone C.
Big Data Engineer @ UBX

As a developer specializing in native cloud solutions, I am delighted that xcware is available for free for developers like me. This allows me to enhance my cloud skills and expand my expertise.

— Sindra L.
Cloud Engineer

My favorite is the Flow-fx engine and the API. With Nexus Flow-fx, you can automate everything, and I mean everything! I manage over 150+ Linux servers fully automated.

— Mirco. W.
Linux Administrator @ S&P

xcware Strategic Partners