Skip to content

Instantly share code, notes, and snippets.

@rismoney
Last active December 10, 2015 23:55
Show Gist options
  • Save rismoney/4511729 to your computer and use it in GitHub Desktop.
Save rismoney/4511729 to your computer and use it in GitHub Desktop.
#cluster_name, nodes, ips
cluster_name = 'cc-git.office.iseoptions.com'
nodes = ['cc-git01']
ips = ['30.3.4.45']
version = 0x700
cluster_name = utf8_to_utf16le(cluster_name)
cluster_config = Struct.new(:version, :clustername, :nodecount, :nodes, :ipcount, :ips, :emptycluster)
node_array_ptr=[]
nodes.each {|item| node_array_ptr << utf8_to_utf16le(item)}
nodes_ptr = node_array_ptr.map{|x| [x].pack('p')}.join
nodelist = [nodes_ptr].pack('p').unpack('L').first
cnodes = 1
ip_entry = Struct.new(:ip,:len)
ipentry_array=[]
ips.each {|item| ipentry_array.push(ip_entry.new utf8_to_utf16le(item),24)}
ipentry_array_ptr = ipentry_array.map{|x| x.to_a.pack('pL')}
ipentry_ptr = ipentry_array_ptr.map{|x| [x].pack('p')}.join
iplist = [ipentry_ptr].pack('p').unpack('L').first
cips = ipentry_array.count
cluster_config_struct = cluster_config.new(version, cluster_name, cnodes, nodelist, cips, iplist, 0)
cluster_config_ptr = cluster_config_struct.to_a.pack("LpLLLLL")
address = [cluster_config_ptr].pack('p').unpack('L').first
getlasterror = Win32API.new("Kernel32","GetLastError", "V", "N")
Functions::CreateCluster.call(address,nil,nil)
puts "GetLastError = #{getlasterror.Call}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment