MintPress Console Ruby Client
This gem provides a Ruby client for interacting with MintPress console.
Usage
Please see the following for usage instructions
MintPress Console Client
Instantiate a client object to interact with MintPress console.
You can create a config file located in ~/.mintpress/config
to store your credentials and details of MintPress console instances
$ cat ~/.mintpress/config
# Default profile
[default]
api_url = http://foo.mintpress.io:8080
api_username = admin
api_password = admin
[profile bar]
api_url = http://bar.mintpress.io:8080
api_username = admin
api_password = admin
[profile fum]
api_url = http://fum.mintpress.io:8080
api_username = admin
api_password = admin
The Client supports the following properties. These can also be added to the above ~/.mintpress/config
file as required.
api_url = URL of MintPress Console
api_username = Username login for MintPress Console
api_password = Password for MintPress Console
verify_ssl = [ true | false], default: false, whether or not to verify SSL for HTTPS API_URL
retries = default: 3, the number of retries in the event of a REST request issue
timeout = default: 300, the amount of seconds to allow for connect and read timeouts on the REST client
autoload = [ true | false ], default: true, whether to autoload all console objects into the client by performing all the REST calls upfront and populate all objects (providers, instances, nodes, databags, environments). Note: In large environments, this could have an initial delay whilst these values are populated.
To create a new client in Ruby, please use the following
Example: MintPress Console client using profile from ~/.mintpress/config
require 'mintpress-console'
ENV['MINTPRESS_DEFAULT_PROFILE'] = 'foo'
console = MintPress::Console::Client.new(autoload: false)
Example: MintPress Console client using options directly
require 'mintpress-console'
console = MintPress::Console::Client.new(api_url: "http://foo.mintpress.io:8080", api_username: "admin", api_password: "admin")
MintPress Console Client: Providers
Once you have instantiated a MintPress Console client, you can now interact with MintPress console providers.
Example: Provider - List
require 'mintpress-console'
ENV['MINTPRESS_DEFAULT_PROFILE'] = 'foo'
console = MintPress::Console::Client.new(autoload: false)
providers = console.providers.list
# This returns a Hash of providers (MintPress::Console::Provider objects)
puts JSON.pretty_generate(providers)
#RESULT:
#{
# "vmware-vsphere": "#<MintPress::Console::Provider:0x00007f8844667fa0>"
#}
# Now you can interact with the provider
puts providers['vmware-vsphere'].name
puts providers['vmware-vsphere'].code
puts providers['vmware-vsphere'].id
puts providers['vmware-vsphere'].properties
Example: Provider - Create
require 'mintpress-console'
ENV['MINTPRESS_DEFAULT_PROFILE'] = 'foo'
console = MintPress::Console::Client.new(autoload: false)
provider = {
"code" => "test-vmware",
"name" => "My vSphere Provider",
"type" => "vmware-vsphere",
"description" => "Test vSphere Provider",
"vsphere.vcenter_host" => "...",
"vsphere.vcenter_username" => "..",
"vsphere.vcenter_password" => "...",
"vsphere.default_datacenter" => "...",
"vsphere.default_network_name" => "...",
"vsphere.default_resource_pool" => "...",
"vsphere.default_template_name" => "...",
"vsphere.default_vm_folder" => "...",
"vsphere.default_vm_datastore" => "...",
"vsphere.default_vm_ssh_user" => "...",
"vsphere.default_vm_ssh_password" =>"..."
}
console.providers.create(provider: provider)
Example: Provider - Delete
require 'mintpress-console'
ENV['MINTPRESS_DEFAULT_PROFILE'] = 'foo'
console = MintPress::Console::Client.new(autoload: false)
console.providers.delete(code: "test-vmware")
MintPress Console Client: Instances
Once you have instantiated a MintPress Console client, you can now interact with MintPress console service catalog instances.
Example: Instances - List
List all service catalog instances and its associated data
require 'mintpress-console'
ENV['MINTPRESS_DEFAULT_PROFILE'] = 'foo'
console = MintPress::Console::Client.new(autoload: false)
# To get the list of of all instances
instances = console.instances.list
# To get the list of all instances including the list of Console URLs in those instances, e.g. if the instance if of type Weblogic and you want the Weblogic Console URL
# Remember that this might slow things down if you have a lot of instances.
instances = console.instances.list(fetch_consoles: true)
# This returns a Hash of providers (MintPress::Console::Instance objects)
puts JSON.pretty_generate(instances)
#{
# "f2028085-d7f8-4adf-9d24-ad5c9e6e2776": "#<MintPress::Console::Instance:0x00007f9d0e918db0>",
# "db9368a7-a53b-4078-beaa-9a98ff1e2e6f": "#<MintPress::Console::Instance:0x00007f9d0e91f200>",
# "0c192684-67a3-4548-b6df-540e6cae2abc": "#<MintPress::Console::Instance:0x00007f9d0e950378>",
# "a578f065-8c7a-4a5c-99b2-bcfd212ccf8d": "#<MintPress::Console::Instance:0x00007f9d0d882d48>",
# "117719f8-2ec9-4f0c-87ef-02a3a74720b2": "#<MintPress::Console::Instance:0x00007f9d0ab74b58>",
# "f1214e8b-be48-4f9d-99a0-aa8c28b2c509": "#<MintPress::Console::Instance:0x00007f9d0acc88b0>",
# "0edaabbf-93ab-4301-8914-d2237eeb640a": "#<MintPress::Console::Instance:0x00007f9d0ad48c90>",
# "3f08eae1-b59d-49e1-b29b-ee86505376be": "#<MintPress::Console::Instance:0x00007f9d0ade88a8>"
#}
# Now you can interact with the provider
puts instances[instances.keys[0]].uuid
puts instances[instances.keys[0]].type
puts instances[instances.keys[0]].dateCreated
puts instances[instances.keys[0]].planState
puts instances[instances.keys[0]].launchDetails
puts instances[instances.keys[0]].environment
puts instances[instances.keys[0]].providerCode
puts instances[instances.keys[0]].providerTypeCode
puts instances[instances.keys[0]].item
puts instances[instances.keys[0]].consoles
puts instances[instances.keys[0]].properties
Example: Instances - Get an instance
List all service catalog instances and its associated data
require 'mintpress-console'
ENV['MINTPRESS_DEFAULT_PROFILE'] = 'foo'
console = MintPress::Console::Client.new(autoload: false)
i = console.instances.get_instance(provider: "vmware-vsphere", environment: "itvsp350", item: "CHEFOTD")
puts i.to_hash
puts console.providers.get('vmware-vsphere').pretty_print
Example: Instances - Launch
Launch a new service catalog instances
require 'mintpress-console'
ENV['MINTPRESS_DEFAULT_PROFILE'] = 'foo'
console = MintPress::Console::Client.new(autoload: false)
# Set wait: true if you want your client to wait for completion of this item, otherwise set wait: false
result = console.instances.launch(provider: "vmware-vsphere", environment: "itvsp350", item: "OSI", action: "provision", wait: true)
puts result
# Wait for completion of instance when action 'provision' was requested
console.instances.wait_for_completion(uuid: result['uuid'], action: "provision")
Example: Instances - Trigger
Trigger action on an existing service catalog instances
require 'mintpress-console'
ENV['MINTPRESS_DEFAULT_PROFILE'] = 'foo'
console = MintPress::Console::Client.new(autoload: false)
instances = console.instances.list
console.instances.trigger_action(uuid: instances[instances.keys[0]].uuid, action: "destroy")
MintPress Console Client: Nodes
Once you have instantiated a MintPress Console client, you can now interact with MintPress console nodes. These are nodes that are defined in the MintPress Chef Server.
require 'mintpress-console'
ENV['MINTPRESS_DEFAULT_PROFILE'] = 'foo'
console = MintPress::Console::Client.new(autoload: false)
nodes = console.nodes.list
puts nodes.inspect
nodes.each do | k,v |
puts k.inspect
puts JSON.pretty_generate(console.nodes.get(k))
end
MintPress Console Client: Environments
Once you have instantiated a MintPress Console client, you can now interact with MintPress console environments. These are environments that are defined in the MintPress Chef Server.
require 'mintpress-console'
ENV['MINTPRESS_DEFAULT_PROFILE'] = 'foo'
console = MintPress::Console::Client.new(autoload: false)
environments = console.environments.list
puts environments.inspect
environments.each do | k,v |
puts k.inspect
puts JSON.pretty_generate(console.environments.get(k))
end
MintPress Console Client: Data Bags
Once you have instantiated a MintPress Console client, you can now interact with MintPress console databags. These are databags that are defined in the MintPress Chef Server.
require 'mintpress-console'
ENV['MINTPRESS_DEFAULT_PROFILE'] = 'foo'
console = MintPress::Console::Client.new(autoload: false)
databags = console.databags.list
puts databags.inspect
databags.each do | k,v |
puts k.inspect
puts JSON.pretty_generate(console.databags.get(k))
end
db_item = console.databags.get_item("password_vault", "mintpress")
puts db_item.inspect
MintPress Console Client: Refresh
Once you have instantiated a MintPress Console client, you can now interact with MintPress console objects. To refresh the object data, you can call the refresh
method on the underlying object or on the client to refresh everything.
require 'mintpress-console'
ENV['MINTPRESS_DEFAULT_PROFILE'] = 'foo'
console = MintPress::Console::Client.new(autoload: false)
# Refresh all
console.refresh
#refresh just instances
console.instances.refresh
MintPress Console Client: Secrets
The mintpress console client provides access to the mintpress vault, assuming the connect user has access.
require 'mintpress-console'
ENV['MINTPRESS_DEFAULT_PROFILE'] = 'foo'
client = MintPress::Console::Client.new(autoload: false)
puts "Vaults: #{client.secrets.list.inspect}"
puts "Groups: #{client.secrets.list_groups(vault: 'mintpress').inspect}"
puts "Creds: #{client.secrets.list_credentials(vault: 'mintpress', group: 'designtime').inspect}"
puts "A cred: #{client.secrets.get_credential(vault: 'mintpress', group: 'designtime', credential: 'superuser').inspect}"
puts "A cred decrypted: #{client.secrets.get_credential(vault: 'mintpress', group: 'designtime', credential: 'superuser', decrypt: true).inspect}"
License & Authors
-
Author:: LimePoint (support@limepoint.com)
# MintPress® - Automation and Configuration Management
#
# Copyright © 2014 LimePoint. All rights reserved.
#
# This program and its contents are confidential and owned by LimePoint.
# Only licenced users are permitted to access and use of this file.
# This program (or any part of it) may not be disclosed, copied or used
# except as expressly permitted in LimePoint’s End User Licence Agreement.
#
# LimePoint® and MintPress® are Registered Trademarks of LimePoint IP Limited.
# For more information contact LimePoint at http://www.limepoint.com