Skip to content

Commit

Permalink
Merge pull request #29 from lenovo/add_logs
Browse files Browse the repository at this point in the history
Add logs in new places
  • Loading branch information
rodneyhbrown7 authored Jun 7, 2017
2 parents 419def1 + 4064c93 commit 4c80d42
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/xclarity_client/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def initialize(args)
args.each { |key, value| send("#{key}=", value) }

if [username, password, host, verify_ssl].any? { |item| item.nil? }
$lxca_log.error "XClarityClient::Configuration initialize","username, password, host, and verify_ssl must all be specified"
raise ArgumentError, "username, password, host, and verify_ssl must all be specified"
end

Expand All @@ -18,6 +19,8 @@ def initialize(args)
@auth_type = 'basic_auth'
end

$lxca_log.info "XClarityClient::Configuration initialize","Configuration built successfuly"

@csrf_token ||= SecureRandom.base64(120) if @auth_type == 'token'
end

Expand Down
4 changes: 4 additions & 0 deletions lib/xclarity_client/node_management.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,16 @@ def set_node_power_state(uuid, powerState = OFF)
else
JSON.generate(powerState: 'powerOn')
end
$lxca_log.info "XclarityClient::ManagementMixin set_node_power_state", "Power state action has been sent"

do_put(Node::BASE_URI + '/' + uuid, power_request)
end

def set_loc_led_state(uuid, state, name = 'Identify')
request = JSON.generate(leds: [{ name: name, state: state }])

$lxca_log.info "XclarityClient::ManagementMixin set_loc_led_state", "Loc led state action has been sent"

do_put("#{Node::BASE_URI}/#{uuid}", request)
end
end
Expand Down
5 changes: 5 additions & 0 deletions lib/xclarity_client/virtual_appliance_management.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def configuration_settings=()

def ip_enablement_state
uri = BASE_URI+NETWORK_URI+IPDISABLE_URI
$lxca_log.info "XclarityClient::VirtualApplianceManagement ip_enablement_state", "Action has been sent to #{uri}"
response = connection(uri)
response
end
Expand All @@ -33,6 +34,7 @@ def ip_enablement_state=()

def host_settings
uri = BASE_URI+NETWORK_URI+IPDISABLE_URI
$lxca_log.info "XclarityClient::VirtualApplianceManagement host_settings", "Action has been sent to #{uri}"
response = connection(uri)
response
end
Expand All @@ -43,6 +45,7 @@ def host_settings=()

def network_interface_settings(interface)
uri = BASE_URI+NETWORK_URI+INTERFACES_URI+"/#{interface}"
$lxca_log.info "XclarityClient::VirtualApplianceManagement network_interface_settings", "Action has been sent to #{uri}"
response = connection(uri)
response
end
Expand All @@ -53,6 +56,7 @@ def host_settings=()

def route_settings
uri = BASE_URI+NETWORK_URI+ROUTES_URI
$lxca_log.info "XclarityClient::VirtualApplianceManagement route_settings", "Action has been sent to #{uri}"
response = connection(uri)
response
end
Expand All @@ -63,6 +67,7 @@ def route_settings=()

def subscriptions
uri = BASE_URI+SUBSCRIPTIONS_URI
$lxca_log.info "XclarityClient::VirtualApplianceManagement subscriptions", "Action has been sent to #{uri}"
response = connection(uri)
response
end
Expand Down
13 changes: 12 additions & 1 deletion lib/xclarity_client/xclarity_management_mixin.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
module XClarityClient
module ManagementMixin
def get_all_resources (resource, opts = {})
$lxca_log.info "XclarityClient::ManagementMixin get_all_resources", "Sending request to #{resource} resource"

response = connection(resource::BASE_URI, opts)

$lxca_log.info "XclarityClient::ManagementMixin get_all_resources", "Response received from #{resource::BASE_URI}"

return [] unless response.success?

body = JSON.parse(response.body)
Expand All @@ -15,6 +19,8 @@ def get_all_resources (resource, opts = {})

def get_object(uuids, includeAttributes, excludeAttributes, resource)

$lxca_log.info "XclarityClient::ManagementMixin get_object", "Sending request to #{resource} resource"

uuids.reject! { |uuid| UUID.validate(uuid).nil? } unless uuids.nil?

response = if not includeAttributes.nil?
Expand All @@ -39,6 +45,8 @@ def get_object(uuids, includeAttributes, excludeAttributes, resource)

def get_object_with_include_attributes(uuids, attributes, resource)

$lxca_log.info "XclarityClient::ManagementMixin get_object_with_include", "Sending request to #{resource} resource including the following attributes: #{attributes.join(",")}"

uuids.reject! { |uuid| UUID.validate(uuid).nil? } unless uuids.nil?

response = if not uuids.nil?
Expand All @@ -51,6 +59,8 @@ def get_object_with_include_attributes(uuids, attributes, resource)

def get_object_with_exclude_attributes(uuids, attributes, resource)

$lxca_log.info "XclarityClient::ManagementMixin get_object_with_include", "Sending request to #{resource} resource excluding the following attributes: #{attributes.join(",")}"

uuids.reject! { |uuid| UUID.validate(uuid).nil? } unless uuids.nil?

response = if not uuids.nil?
Expand Down Expand Up @@ -78,7 +88,8 @@ def get_object_with_opts(opts, resource)
else
filter += "?type=#{opts["type"]}"
end
connection(resource::BASE_URI + filter)
$lxca_log.info "XclarityClient::ManagementMixin get_object_with_include", "Sending request to #{resource} resource using the following filter: #{filter}"
connection(resource::BASE_URI + filter)
end

return [] unless response.success?
Expand Down

0 comments on commit 4c80d42

Please sign in to comment.