Created
April 24, 2015 16:31
-
-
Save huskercane/968a6f18183fdc6dc77f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'rest-client' | |
| # create a vsys pattern | |
| def create_vsys_pattern | |
| # POST /resources/virtualSystemPatterns/ | |
| # Content-Type - application/zip | |
| # deployer.virtualapplicationpatterns.create('/root/vsys_pattern.zip') | |
| return nil if find_devops_app.size > 0 | |
| uri_vsys = '/resources/virtualApplicationPatterns' | |
| x = @creds[:headers] | |
| x['Content-Type'] = 'application/zip' | |
| y = {}.merge(@creds) | |
| y[:headers] = x | |
| templates_resource = RestClient::Resource.new "https://#{@host}#{uri_vsys}", y | |
| response = templates_resource.post File.open('./scripts/vsys_pattern.zip', 'rb') | |
| @logger.debug response | |
| @logger.debug response.code | |
| response | |
| end | |
| def deploy_vsys_pattern(count) | |
| # http://server/resources/virtualSystemPatterns/a-123/virtualSystemInstances/ | |
| # { | |
| # "deployment_name": "Two nodes_testname", | |
| # "ssh_keys": ["ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCoh/DkvoUoio7rMUtoYFGuqFVF+07igSjxylqhTt/8xM8jjTpBY6qngFBqyjI76ss522Gf8ubqNarqzL6cqLm7ZLI5Fz4FvwQmbux9xK9zicoZ/Hi1QAzN9mcYt0w7zFKrx79HEye7VZMCeR5PzsATb9oI8F3frx2oS/kFTUNRyul8nTSND3Ae98dcxUUYaXCLkNuSdQsZV1rUjxJxQcL0010EiV5TYRtucvznIQ4U5MU2uKP7iLz2/AYojnFafIZi8xD/W/tEj9lCzvKYLiQzsfmsD/2boziE44d+Af0MjX7DRjZDgF1LJpfnoSFS3PEjeN03jQCqq53LkkWkN5Wb iwd-generated-rsa-key-20140522"], | |
| # "environment_profile_id": "1", | |
| # "placement_only": true | |
| # } | |
| # | |
| # POST /resources/applicationPatterns/a-0caf3d7a-8554-4215-a17d-5749f6ab5517/virtualApplications | |
| # "{"cloud_group":"1","ip_group":"2","ssh_keys":[""],"environment_profile_id":"21","placement_only":false,"ip_version":"IPv4","deployment_name":"xxx"}" | |
| devops_vsys = find_devops_app.first | |
| # environment profiles | |
| # /resources/environmentProfiles | |
| uri_env_profile = '/resources/environmentProfiles' | |
| envprofiles_resource = RestClient::Resource.new "https://#{@host}#{uri_env_profile}", @creds | |
| response = envprofiles_resource.get | |
| @logger.debug response | |
| @logger.debug response.code | |
| ep_json = JSON.parse(response) | |
| # uri_cloud = '/resources/clouds' | |
| # cloud_resource = RestClient::Resource.new "https://#{@host}#{uri_cloud}", @creds | |
| # response = cloud_resource.get | |
| # @logger.debug response | |
| # @logger.debug response.code | |
| # cloud_json = JSON.parse(response) | |
| # /resources/ipGroups | |
| uri_ipGroups = '/resources/ipGroups' | |
| ipgroup_resource = RestClient::Resource.new "https://#{@host}#{uri_ipGroups}", @creds | |
| response = ipgroup_resource.get | |
| @logger.debug response | |
| @logger.debug response.code | |
| ipgroup_json = JSON.parse(response) | |
| post_json = { | |
| deployment_name: "dev_ops_test_deploy_#{count}", | |
| environment_profile_id: ep_json[0]['id'].to_s, | |
| ip_version: 'IPv4', | |
| # cloud_group: cloud_json[0]['id'].to_s, | |
| ip_group: ipgroup_json[0]['id'].to_s | |
| # 'placement_only' => false | |
| } | |
| # pp post_json | |
| uri_vsys_deploy = "/resources/virtualApplicationPatterns/#{devops_vsys['app_id']}/virtualApplicationInstances" | |
| templates_resource = RestClient::Resource.new "https://#{@host}#{uri_vsys_deploy}", @creds | |
| response = templates_resource.post post_json.to_json | |
| @logger.debug response | |
| @logger.debug response.code | |
| response | |
| end | |
| def find_devops_app | |
| uri_vsys = '/resources/virtualSystemPatterns?app_name=dev_ops_test' | |
| templates_resource = RestClient::Resource.new "https://#{@host}#{uri_vsys}", @creds | |
| response = templates_resource.get | |
| @logger.debug response | |
| @logger.debug response.code | |
| json = JSON.parse(response) | |
| json.select { |template| template['app_name'].to_s.downcase.include?('dev_ops') || template['app_name'].to_s.downcase.include?('devops') } | |
| end | |
| def count_dev_ops_app_instance | |
| # /resources/virtualApplicationInstances/ | |
| uri_vsys = '/resources/virtualSystemInstances' | |
| templates_resource = RestClient::Resource.new "https://#{@host}#{uri_vsys}", @creds | |
| response = templates_resource.get | |
| @logger.debug response | |
| @logger.debug response.code | |
| json = JSON.parse(response) | |
| selected = json.select { |template| template['deployment_name'].to_s.downcase.include?('dev_ops') || template['deployment_name'].to_s.downcase.include?('devops') } | |
| @logger.debug "Selected #{selected}" | |
| selected.size | |
| end | |
| if __FILE__ == $PROGRAM_NAME | |
| user = 'admin' | |
| passw = 'completepass' | |
| @host = '127.0.0.1' | |
| @creds = { | |
| user: user, | |
| password: passw, | |
| verify_ssl: OpenSSL::SSL::VERIFY_NONE, | |
| headers: { | |
| Accept: 'application/json', | |
| 'X-IBM-Workload-Deployer-API-Version' => '5.0', | |
| 'Content-Type' => 'application/json' | |
| } | |
| } | |
| create_vsys_pattern | |
| accept_license | |
| count = ARGV[0] | |
| # (0..count).each{|c| deploy_vsys_pattern c} | |
| pool = Thread.pool count | |
| running_app_count = count_dev_ops_app_instance | |
| count.times do |page| | |
| # start thread for each page | |
| pool.process do | |
| deploy_vsys_pattern(page + running_app_count) | |
| end # end processs | |
| end # end page | |
| pool.shutdown | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment