lib/puppet/provider/compellent_cluster_server_map/compellent_cluster_server_map.rb
# Assume cluster object and server object are already created.
# Compellent API will raise error in case any of these is missing
Assume cluster object and server object are already created.
Compellent API will raise error in case any of these is missing
Assume cluster object and server object are already created . Compellent API will raise error in case any of these is missing
def exists?
    cluster_server_name = @resource[:cluster_server_name]
    server_name = @resource[:server_name]
    server_folder = @resource[:folder]
    @cluster_server_index = ""
    libpath = CommonLib.get_path(1)
    server_show_exit_code_xml = "#{CommonLib.get_log_path(1)}/serverShowExitCode_#{CommonLib.get_unique_refid}.xml"
    server_show_response_xml = "#{CommonLib.get_log_path(1)}/serverShowResponse_#{CommonLib.get_unique_refid}.xml"
    connection.command_exec("#{libpath}",
                            "#{server_show_exit_code_xml}",
                            "\"#{show_server_commandline(cluster_server_name)} -xml #{server_show_response_xml}\"")
    parser_obj = ResponseParser.new("_")
    if server_folder.empty?
      self.server_information = parser_obj.retrieve_empty_folder_server_properties(server_show_response_xml, cluster_server_name)
      @cluster_server_index = self.server_information["Index"].first unless self.server_information["Index"].nil?
    else
      parser_obj.parse_discovery(server_show_exit_code_xml, server_show_response_xml, 0)
      self.server_information = parser_obj.return_response
      @cluster_server_index = self.server_information["server_Index"]
    end
    raise Puppet::Error, "Cluster Server %s do not exists on storage center" % [cluster_server_name] unless @cluster_server_index
    connection.command_exec("#{libpath}","#{server_show_exit_code_xml}","\"#{show_server_commandline} -xml #{server_show_response_xml}\"")
    server_data = JSON.parse(JSON.pretty_generate(XmlSimple.xml_in(server_show_response_xml)))
    mapped_servers = server_data["server"].select {|server| server["ParentIndex"].first == @cluster_server_index  &&
        server["Name"].first == server_name &&
        (server["Folder"].first.is_a?(Hash) ? "" : server["Folder"].first).downcase == server_folder.downcase}
    File.delete(server_show_exit_code_xml, server_show_response_xml)
    server = server_data["server"].select {|server| server["Name"].first == @resource[:server_name] &&
        (server["Folder"].first.is_a?(Hash) ? "" : server["Folder"].first).downcase == server_folder.downcase}
    @server_index = server.first["Index"].first unless server.empty?
    raise Puppet::Error, "Server %s do not exists on storage center" % [server_name] unless @server_index
    return !mapped_servers.empty?
  end
def exists? cluster_server_name = @resource [ :cluster_server_name ] server_name = @resource [ :server_name ] server_folder = @resource [ :folder ] @cluster_server_index = "" libpath = CommonLib . get_path ( 1 ) server_show_exit_code_xml = "#{CommonLib.get_log_path(1)}/serverShowExitCode_#{CommonLib.get_unique_refid}.xml" server_show_response_xml = "#{CommonLib.get_log_path(1)}/serverShowResponse_#{CommonLib.get_unique_refid}.xml" connection . command_exec ( "#{libpath}" , "#{server_show_exit_code_xml}" , "\"#{show_server_commandline(cluster_server_name)} -xml #{server_show_response_xml}\"" ) parser_obj = ResponseParser . new ( "_" ) if server_folder . empty? self . server_information = parser_obj . retrieve_empty_folder_server_properties ( server_show_response_xml , cluster_server_name ) @cluster_server_index = self . server_information [ "Index" ] . first unless self . server_information [ "Index" ] . nil? else parser_obj . parse_discovery ( server_show_exit_code_xml , server_show_response_xml , 0 ) self . server_information = parser_obj . return_response @cluster_server_index = self . server_information [ "server_Index" ] end raise Puppet :: Error , "Cluster Server %s do not exists on storage center" % [ cluster_server_name ] unless @cluster_server_index connection . command_exec ( "#{libpath}" , "#{server_show_exit_code_xml}" , "\"#{show_server_commandline} -xml #{server_show_response_xml}\"" ) server_data = JSON . parse ( JSON . pretty_generate ( XmlSimple . xml_in ( server_show_response_xml ) ) ) mapped_servers = server_data [ "server" ] . select { | server | server [ "ParentIndex" ] . first == @cluster_server_index && server [ "Name" ] . first == server_name && ( server [ "Folder" ] . first . is_a? ( Hash ) ? "" : server [ "Folder" ] . first ) . downcase == server_folder . downcase } File . delete ( server_show_exit_code_xml , server_show_response_xml ) server = server_data [ "server" ] . select { | server | server [ "Name" ] . first == @resource [ :server_name ] && ( server [ "Folder" ] . first . is_a? ( Hash ) ? "" : server [ "Folder" ] . first ) . downcase == server_folder . downcase } @server_index = server . first [ "Index" ] . first unless server . empty? raise Puppet :: Error , "Server %s do not exists on storage center" % [ server_name ] unless @server_index return ! mapped_servers . empty? end
Assume cluster object and server object are already created.
Assume cluster object and server object are already created .
# Cannot find cluster server object # get all server information