Module: ViprVcenter

Included in:
Vipr
Defined in:
lib/vipruby/objects/vcenter.rb

Overview

The Following vCenter calls will get vCenter information for all tenants

Instance Method Summary collapse

Instance Method Details

#add_vcenter(fqdn_or_ip = nil, name = nil, user_name = nil, password = nil, port = nil, tenant = nil, auth = nil, cert = nil) ⇒ Hash

Add a vCenters to a specified tenant

Examples:

vipr.add_vcenter('vcenter1.mydomain.com', 'vCENTER1', 'DOMAIN\user', 'userpw')
vipr.add_vcenter('vcenter2.mydomain.com', 'vCENTER2', 'DOMAIN\user', 'userpw', '1092')
vipr.add_vcenter('vcenter3.mydomain.com', 'vCENTER3', 'DOMAIN\user', 'userpw', nil, 'diff_tenant_uid')

Parameters:

  • fqdn_or_ip (String) (defaults to: nil)

    FQDN or IP Address of the vCenter server to add. This is a required string.

  • name (String) (defaults to: nil)

    Name of the vCenter server. This name is arbitrary and only exists within ViPR. This is a required string.

  • user_name (String) (defaults to: nil)

    User Name that will be used for authenticating against the vCenter Server. This is a required string.

  • password (String) (defaults to: nil)

    Password for the user_name that will be used for authenticating against the vCenter Server. This is a required string.

  • port (String) (defaults to: nil)

    Port of the vCenter server. This is an optional parameter. If no parameter is present, the default port of ‘443’ will be used. If registering to a different tenant than default, set this param to nil

  • tenant (String) (defaults to: nil)

    Specify a tenant_uid where the vCenter will be registered. By default it will be added to the tenant of the current logged in ViPR user. This string is optional.

Returns:

  • (Hash)

    The resulted post operation



92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/vipruby/objects/vcenter.rb', line 92

def add_vcenter(fqdn_or_ip=nil, name=nil, user_name=nil, password=nil, port=nil, tenant=nil, auth=nil, cert=nil)
  check_vcenter_post(fqdn_or_ip, name, user_name, password)
  port.nil? ? port = '443' : port = port
  payload = {
      ip_address: fqdn_or_ip,
      name: name,
      port_number: port,
      user_name: user_name,
      password: password
    }.to_json
  rest_post(payload, "#{@base_url}/tenants/#{@tenant_uid}/vcenters", auth.nil? ? @auth_token : auth, cert.nil? ? @verify_cert : cert)
end

#check_vcenter(vcenter_id = nil) ⇒ Boolean (private)

Error Handling method to check for Missing vCenter ID param. If the pass fails, an error exception is raised

Parameters:

  • vcenter_id (String) (defaults to: nil)

    Requires the string of the vcenter uid

Returns:

  • (Boolean)

    True if pass, false if it fails



129
130
131
132
133
# File 'lib/vipruby/objects/vcenter.rb', line 129

def check_vcenter(vcenter_id=nil)
  if vcenter_id == nil
      raise "Missing vCenter ID param (vcenter_id)"
  end
end

#check_vcenter_object_hash(vcenter_search_hash = nil) ⇒ Boolean (private)

Error Handling method to check for Missing vCenter Object param. If the pass fails, an error exception is raised

Parameters:

  • vcenter_search_hash (String) (defaults to: nil)

    Requires the string of something to search

Returns:

  • (Boolean)

    True if pass, false if it fails



141
142
143
144
145
# File 'lib/vipruby/objects/vcenter.rb', line 141

def check_vcenter_object_hash(vcenter_search_hash=nil)
  if vcenter_search_hash == nil
      raise "Missing vCenter Object to search as a param"
  end
end

#check_vcenter_post(fqdn_or_ip = nil, name = nil, user_name = nil, password = nil) ⇒ Boolean (private)

Error Handling method to check for Missing Param. If the pass fails, an error exception is raised

Parameters:

  • fqdn_or_ip (String) (defaults to: nil)

    Requires the string of the vcenter FQDN or IP Address

  • name (String) (defaults to: nil)

    Requires the name of the vCenter

  • user_name (String) (defaults to: nil)

    Requires the User Name used for authentication to vCenter

  • password (String) (defaults to: nil)

    Requires the password of the User Name used for authentication to vCenter

Returns:

  • (Boolean)

    True if pass, false if it fails



156
157
158
159
160
# File 'lib/vipruby/objects/vcenter.rb', line 156

def check_vcenter_post(fqdn_or_ip=nil, name=nil, user_name=nil, password=nil)
  if fqdn_or_ip == nil || name == nil || user_name == nil || password == nil
    raise "Missing a Required Param of fqdn_or_ip, name, port, user_name, or password"
  end
end

#delete_vcenter(vcenter_id = nil, auth = nil, cert = nil) ⇒ Hash

Delete a vCenter from any tenant based on vCenter ID

Examples:

x = vipr.get_all_vcenters['id'][0]
vipr.delete_vcenter(x)

Parameters:

  • vcenter_id (String) (defaults to: nil)

    Requires the string of the vcenter uid

Returns:

  • (Hash)

    The resulted post operation



113
114
115
116
117
118
# File 'lib/vipruby/objects/vcenter.rb', line 113

def delete_vcenter(vcenter_id=nil, auth=nil, cert=nil)
  check_vcenter(vcenter_id)
  payload = {
    }.to_json
  rest_post(payload, "#{@base_url}/compute/vcenters/#{vcenter_id}/deactivate", auth.nil? ? @auth_token : auth, cert.nil? ? @verify_cert : cert)
end

#find_vcenter_object(vcenter_search_hash = nil, auth = nil, cert = nil) ⇒ Hash

Search for vCenters matching a specific parameter

Examples:

vipr.find_vcenter_object('demo')

Parameters:

  • vcenter_search_hash (String) (defaults to: nil)

    String for searching

Returns:

  • (Hash)

    Will return any vCenter objects containing the search string. The object converted into Hash format and can be parsed with object or object notation



73
74
75
76
# File 'lib/vipruby/objects/vcenter.rb', line 73

def find_vcenter_object(vcenter_search_hash=nil, auth=nil, cert=nil)
  check_vcenter_object_hash(vcenter_search_hash)
  rest_get("#{@base_url}/compute/vcenters/search?name=#{vcenter_search_hash}", auth.nil? ? @auth_token : auth, cert.nil? ? @verify_cert : cert)
end

#get_all_vcenters(auth = nil, cert = nil) ⇒ Hash

Retrive all vCenter Servers registered for all tenants

Returns:

  • (Hash)

    the object converted into Hash format and can be parsed with object or object notation



10
11
12
# File 'lib/vipruby/objects/vcenter.rb', line 10

def get_all_vcenters(auth=nil, cert=nil)
  rest_get("#{@base_url}/compute/vcenters/bulk", auth.nil? ? @auth_token : auth, cert.nil? ? @verify_cert : cert)
end

#get_vcenter(vcenter_id = nil, auth = nil, cert = nil) ⇒ Hash

Retrieve information for a single vCenter server using the uid

Examples:

x = vipr.get_all_vcenters['id'][0]
vipr.get_vcenter(x)

Parameters:

  • vcenter_id (String) (defaults to: nil)

    Requires the string of the vcenter uid

Returns:

  • (Hash)

    the object converted into Hash format and can be parsed with object or object notation



22
23
24
25
# File 'lib/vipruby/objects/vcenter.rb', line 22

def get_vcenter(vcenter_id=nil, auth=nil, cert=nil)
  check_vcenter(vcenter_id)
  rest_get("#{@base_url}/compute/vcenters/#{vcenter_id}", auth.nil? ? @auth_token : auth, cert.nil? ? @verify_cert : cert)
end

#get_vcenter_clusters(vcenter_id = nil, auth = nil, cert = nil) ⇒ Hash

Retrieve Cluster information for a single vCenter server using the uid

Examples:

x = vipr.get_all_vcenters['id'][0]
vipr.get_vcenter_clusters(x)

Parameters:

  • vcenter_id (String) (defaults to: nil)

    Requires the string of the vcenter uid

Returns:

  • (Hash)

    the object converted into Hash format and can be parsed with object or object notation



48
49
50
51
# File 'lib/vipruby/objects/vcenter.rb', line 48

def get_vcenter_clusters(vcenter_id=nil, auth=nil, cert=nil)
  check_vcenter(vcenter_id)
  rest_get("#{@base_url}/compute/vcenters/#{vcenter_id}/clusters", auth.nil? ? @auth_token : auth, cert.nil? ? @verify_cert : cert)
end

#get_vcenter_datacenters(vcenter_id = nil, auth = nil, cert = nil) ⇒ Hash

Retrieve Datacenter information for a single vCenter server using the uid

Examples:

x = vipr.get_all_vcenters['id'][0]
vipr.get_vcenter_datacenters(x)

Parameters:

  • vcenter_id (String) (defaults to: nil)

    Requires the string of the vcenter uid

Returns:

  • (Hash)

    the object converted into Hash format and can be parsed with object or object notation



61
62
63
64
# File 'lib/vipruby/objects/vcenter.rb', line 61

def get_vcenter_datacenters(vcenter_id=nil, auth=nil, cert=nil)
  check_vcenter(vcenter_id)
  rest_get("#{@base_url}/compute/vcenters/#{vcenter_id}/vcenter-data-centers", auth.nil? ? @auth_token : auth, cert.nil? ? @verify_cert : cert)
end

#get_vcenter_hosts(vcenter_id = nil, auth = nil, cert = nil) ⇒ Hash

Retrieve Host information for a single vCenter server using the uid

Examples:

x = vipr.get_all_vcenters['id'][0]
vipr.get_vcenter_hosts(x)

Parameters:

  • vcenter_id (String) (defaults to: nil)

    Requires the string of the vcenter uid

Returns:

  • (Hash)

    the object converted into Hash format and can be parsed with object or object notation



35
36
37
38
# File 'lib/vipruby/objects/vcenter.rb', line 35

def get_vcenter_hosts(vcenter_id=nil, auth=nil, cert=nil)
  check_vcenter(vcenter_id)
  rest_get("#{@base_url}/compute/vcenters/#{vcenter_id}/hosts", auth.nil? ? @auth_token : auth, cert.nil? ? @verify_cert : cert)
end