Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gateway server #27

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
146 changes: 146 additions & 0 deletions bin/discovery.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
#!/opt/puppet/bin/ruby

require "trollop"
require "json"
require "timeout"
require "pathname"

puppet_dir = File.join(Pathname.new(__FILE__).parent.parent,'lib','puppet')
require "%s/scaleio/transport" % [puppet_dir]

@opts = Trollop::options do
opt :server, "ScaleIO gateway", :type => :string, :required => true
opt :port, "ScaleIO gateway port", :default => 443
opt :username, "ScaleIO gateway username", :type => :string, :required => true
opt :password, "ScaleIO gateway password", :type => :string, :default => ENV["PASSWORD"]
opt :timeout, "ScaleIO gateway connection timeout", :type => :integer, :default => 300, :required => false
opt :credential_id, 'dummy value for ASM, not used'
opt :output, "Location of the file where facts file needs to be created", :type => :string, :required => false
end

def collect_scaleio_facts
facts = {}
facts[:facts] = scaleio_systems
scaleio_systems.each do |scaleio_system|
facts[scaleio_system["id"]] = {:statistics => {}, :sds => [], :sdc => [], :protection_domains => []}
facts[scaleio_system["id"]][:statistics] = scaleio_system_statistics(scaleio_system)
facts[scaleio_system["id"]][:sds] = scaleio_sds(scaleio_system)
facts[scaleio_system["id"]][:sdc] = scaleio_sdc(scaleio_system)
facts[scaleio_system["id"]][:protection_domains] = protection_domains(scaleio_system)
facts[scaleio_system["id"]][:volumes] = scaleio_volumes(scaleio_system)
facts[scaleio_system["id"]][:fault_sets] = scaleio_faultsets(scaleio_system)
facts[scaleio_system["id"]][:protection_domains].each do |protection_domain|
facts[scaleio_system["id"]][protection_domain["id"]] ||= {}
facts[scaleio_system["id"]][protection_domain["id"]][:statistics] = scaleio_protection_domain_statistics(protection_domain)
facts[scaleio_system["id"]][protection_domain["id"]][:storage_pools] = storage_pools(scaleio_system, protection_domain)
facts[scaleio_system["id"]][protection_domain["id"]][:storage_pools].each do |storage_pool|
facts[scaleio_system["id"]][protection_domain["id"]][storage_pool["id"]] ||= {}
facts[scaleio_system["id"]][protection_domain["id"]][storage_pool["id"]][:statistics] = scaleio_storage_pool_statistics(storage_pool)
facts[scaleio_system["id"]][protection_domain["id"]][storage_pool["id"]][:disks] = disks(storage_pool)
end
end
end
facts
end

def scaleio_systems
url = transport.get_url("/api/types/System/instances")
transport.post_request(url, {}, "get") || []
end

def scaleio_system_statistics(scaleio_system)
end_point = "/api/instances/System::%s/relationships/Statistics" % [scaleio_system["id"]]
url = transport.get_url(end_point)
transport.post_request(url, {}, "get") || []
end

def scaleio_sds(scaleio_system)
sds_url = "/api/types/Sds/instances?systemId=%s" % [scaleio_system["id"]]
url = transport.get_url(sds_url)
transport.post_request(url, {}, "get") || []
end

def scaleio_sdc(scaleio_system)
sdc_url = "/api/types/Sdc/instances?systemId=%s" % [scaleio_system["id"]]
url = transport.get_url(sdc_url)
transport.post_request(url, {}, "get") || []
end

def protection_domains(scaleio_system)
pd_url = "/api/types/ProtectionDomain/instances?systemId=%s" % [scaleio_system["id"]]
url = transport.get_url(pd_url)
transport.post_request(url, {}, "get") || []
end

def scaleio_protection_domain_statistics(protection_domain)
end_point = "/api/instances/ProtectionDomain::%s/relationships/Statistics" % [protection_domain["id"]]
url = transport.get_url(end_point)
transport.post_request(url, {}, "get") || []
end

def storage_pools(scaleio_system, protection_domain)
sp_url = "/api/types/StoragePool/instances?systemId=%s&protectiondomainId=%s" % [scaleio_system["id"], protection_domain["id"]]
url = transport.get_url(sp_url)
transport.post_request(url, {}, "get") || []
end

def scaleio_storage_pool_statistics(storage_pool)
end_point = "/api/instances/StoragePool::%s/relationships/Statistics" % [storage_pool["id"]]
url = transport.get_url(end_point)
transport.post_request(url, {}, "get") || []
end

def disks(storage_pool)
sp_url = "/api/types/Device/instances?storagepoolId=%s" % [storage_pool["id"]]
url = transport.get_url(sp_url)
transport.post_request(url, {}, "get") || []
end

def scaleio_volumes(scaleio_system)
volume_url = "/api/types/Volume/instances?systemId=%s" % [scaleio_system["id"]]
url = transport.get_url(volume_url)
transport.post_request(url, {}, "get") || []
end

def scaleio_faultsets(scaleio_system)
faultset_url = "/api/types/FaultSet/instances?systemId=%s" % [scaleio_system["id"]]
url = transport.get_url(faultset_url)
transport.post_request(url, {}, "get") || []
end

def transport
@transport ||= Puppet::ScaleIO::Transport.new(@opts)
end

def scaleio_cookie
@scaleio_cookie ||= transport.get_scaleio_cookie
end

facts = {}
begin
Timeout.timeout(@opts[:timeout]) do
facts = collect_scaleio_facts.to_json
end
rescue Timeout::Error
puts "Timed out trying to gather ScaleIO Inventory"
exit 1
rescue Exception => e
puts "#{e}\n#{e.backtrace.join("\n")}"
exit 1
else
if facts.empty?
puts "Could not get updated facts"
exit 1
else
puts "Successfully gathered inventory."
if @opts[:output]
File.write(@opts[:output], JSON.pretty_generate(JSON.parse(facts)))
else
results ||= {}
scaleio_cache = "/opt/Dell/ASM/cache"
Dir.mkdir(scaleio_cache) unless Dir.exists? scaleio_cache
file_path = File.join(scaleio_cache, "#{opts[:server]}.json")
File.write(file_path, results) unless results.empty?
end
end
end
70 changes: 70 additions & 0 deletions lib/puppet/scaleio/transport.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
require "net/https"
require "rest-client"
require "cgi"
require "json"

require "puppet"

module Puppet
module ScaleIO
class Transport
attr_accessor :host, :port, :user, :password, :scaleio_cookie

def initialize(opts)
self.user = opts[:username]
self.host = opts[:server]
self.password = opts[:password]
self.port = opts[:port] || 443
end

def cgi_escape(value)
CGI.escape(value)
end

def get_scaleio_cookie
return @scaleio_cookie unless @scaleio_cookie.nil?

response = ""
url = "https://%s:%s@%s:%s/api/login" % [cgi_escape(self.user),
cgi_escape(self.password),
self.host,
self.port]

begin
response = RestClient::Request.execute(
:url => url,
:method => :get,
:verify_ssl => false ,
:payload => '{}',
:headers => {:content_type => :json,
:accept => :json })
rescue => ex
Puppet.error "Failed to get cookie from ScaleIO Gateway with error %s" % [ex.message]
end
@scaleio_cookie = response.strip.tr('""', '')
end

def get_url(end_point)
return "https://%s:%s@%s:%s/%s" % [self.user, self.get_scaleio_cookie, self.host, self.port, end_point]
end

def post_request(url, payload, method)
response = RestClient::Request.execute(:url => url,
:method => method.to_sym,
:verify_ssl => false,
:payload => payload,
:headers => headers
)
JSON.parse(response)
end

def headers
{
:content_type => :json,
:accept => :json,
'Cookie' => self.scaleio_cookie || get_scaleio_cookie
}
end
end
end
end
8 changes: 5 additions & 3 deletions manifests/gateway_server.pp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
$port = 4443, # int - Port for gateway
$im_port = 8081, # int - Port for IM
$pkg_ftp = undef, # string - URL where packages are placed (for example: ftp://ftp.emc.com/Ubuntu/2.0.10000.2072)
$pkg_path = undef, # string - location of ScaleIO RPMs on local filesystem
)
{
$provider = "${::osfamily}${::operatingsystemmajrelease}" ? {
Expand All @@ -30,7 +31,8 @@
} ->
scaleio::package { 'gateway':
ensure => installed,
pkg_ftp => $pkg_ftp
pkg_ftp => $pkg_ftp,
pkg_path => $pkg_path
} ->
service { 'scaleio-gateway':
ensure => 'running',
Expand Down Expand Up @@ -69,9 +71,9 @@
}
if $password {
$jar_path = '/opt/emc/scaleio/gateway/webapps/ROOT'
$opts = "--reset_password '${password}' --config_file ${jar_path}/WEB-INF/classes/gatewayUser.properties"
$opts = "--reset_password --password '${password}' --config_file ${jar_path}/WEB-INF/classes/gatewayUser.properties"
exec { 'Set gateway admin password':
command => "java -jar ${jar_path}/resources/install-CLI.jar ${opts}",
command => "java -jar ${jar_path}/resources/SioGWTool.jar ${opts}",
path => '/etc/alternatives',
refreshonly => true,
notify => Service['scaleio-gateway']
Expand Down
87 changes: 55 additions & 32 deletions manifests/mdm_server.pp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Configure ScaleIO Gateway service installation
include firewall

class scaleio::mdm_server (
$ensure = 'present', # present|absent - Install or remove MDM service
Expand All @@ -7,6 +8,8 @@
$mdm_ips = undef, # string - MDM IPs
$mdm_management_ips = undef, # string - MDM management IPs
$pkg_ftp = undef, # string - URL where packages are placed (for example: ftp://ftp.emc.com/Ubuntu/2.0.10000.2072)
$pkg_path = undef, # string - Location of RPMs located on the local server
$scaleio_password = undef, # string - ScaleIO Password
)
{
$provider = "${::osfamily}${::operatingsystemmajrelease}" ? {
Expand All @@ -25,48 +28,68 @@
proto => tcp,
action => accept,
}
scaleio::common_server { 'install common packages for MDM': } ->
scaleio::common_server { 'install common packages for MDM':
ensure_java => 'present'
} ->
package { ['mutt', 'python', 'python-paramiko']:
ensure => installed,
} ->
scaleio::package { 'mdm':
ensure => $ensure,
pkg_ftp => $pkg_ftp,
}
service { 'mdm':
ensure => 'running',
enable => true,
hasstatus => true,
require => Scaleio::Package['mdm'],
provider => $provider
pkg_path => $pkg_path
} ->
scaleio::package { 'lia':
ensure => $ensure,
pkg_ftp => $pkg_ftp,
pkg_path => $pkg_path,
scaleio_password => $scaleio_password
}

if $is_manager != undef {
file_line { 'mdm role':
path => '/opt/emc/scaleio/mdm/cfg/conf.txt',
line => "actor_role_is_manager=${is_manager}",
match => '^actor_role_is_manager',
require => Scaleio::Package['mdm'],
notify => Service['mdm'],
before => [Exec['create_cluster']],
if $package == 'mdm' {
service { 'mdm':
ensure => 'running',
enable => true,
hasstatus => true,
require => Scaleio::Package['mdm'],
provider => $provider
} ->
service { 'lia':
ensure => 'running',
enable => true,
hasstatus => true,
require => Scaleio::Package['mdm'],
provider => $provider
}
}

# Cluster creation is here
$opts = '--approve_certificate --accept_license --create_mdm_cluster --use_nonsecure_communication'
$master_opts = "--master_mdm_name ${master_mdm_name} --master_mdm_ip ${mdm_ips}"
$management_ip_opts = $mdm_management_ips ? {
undef => '',
default => "--master_mdm_management_ip ${mdm_management_ips}"
}
exec { 'create_cluster':
onlyif => "test -n '${master_mdm_name}'",
require => Service['mdm'],
# Sleep is needed here because service in role changing can be still alive and not restarted
command => "sleep 2 ; scli --query_cluster --approve_certificate || scli ${opts} ${master_opts} ${management_ip_opts}",
path => '/bin:/usr/bin',
tries => 5,
try_sleep => 5,
if $is_manager != undef {
file_line { 'mdm role':
path => '/opt/emc/scaleio/mdm/cfg/conf.txt',
provider => ruby,
line => "actor_role_is_manager=${is_manager}",
match => '^actor_role_is_manager',
require => Scaleio::Package['mdm'],
notify => Service['mdm'],
before => [Exec['create_cluster']],
}
}

# Cluster creation is here
$opts = '--approve_certificate --accept_license --create_mdm_cluster --use_nonsecure_communication'
$master_opts = "--master_mdm_name ${master_mdm_name} --master_mdm_ip ${mdm_ips}"
$management_ip_opts = $mdm_management_ips ? {
undef => '',
default => "--master_mdm_management_ip ${mdm_management_ips}"
}
exec { 'create_cluster':
onlyif => "test -n '${master_mdm_name}'",
require => Service['mdm'],
# Sleep is needed here because service in role changing can be still alive and not restarted
command => "sleep 2 ; scli --query_cluster --approve_certificate || scli ${opts} ${master_opts} ${management_ip_opts}",
path => '/bin:/usr/bin',
tries => 5,
try_sleep => 5,
}
}
}

Expand Down
Loading