ace-client-ext 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ace-client-ext.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 tily
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Ace::Client::Ext
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'ace-client-ext'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install ace-client-ext
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/ace-client-ext/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'ace-client-ext'
7
+ spec.version = File.read('VERSION').chomp
8
+ spec.authors = ["tily"]
9
+ spec.email = ["tidnlyam@gmail.com"]
10
+ spec.summary = %q{extensions for ace-client}
11
+ spec.description = %q{extensions for ace-client}
12
+ spec.homepage = ""
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.7"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ end
@@ -0,0 +1,141 @@
1
+
2
+ module AceClient
3
+ module Niftycloud
4
+ module Computing
5
+ def instances
6
+ response = self.action('DescribeInstances', {})
7
+ begin
8
+ items = [response['DescribeInstancesResponse']['reservationSet']['item']].flatten
9
+ items.map{|item| item['instancesSet']['item'] }.flatten
10
+ rescue
11
+ []
12
+ end
13
+ end
14
+
15
+ def items(options)
16
+ response = self.action(options[:action], {})
17
+ [response[options[:action] + 'Response'][options[:key]]['item']].flatten rescue []
18
+ end
19
+
20
+ {
21
+ :regions => {:action => 'DescribeRegions', :key => 'regionInfo'},
22
+ :availability_zones => {:action => 'DescribeAvailabilityZones', :key => 'availabilityZoneInfo'},
23
+ :volumes => {:action => 'DescribeVolumes', :key => 'volumeSet'},
24
+ :key_pairs => {:action => 'DescribeKeyPairs', :key => 'keySet'},
25
+ :images => {:action => 'DescribeImages', :key => 'imagesSet'},
26
+ :security_groups => {:action => 'DescribeSecurityGroups', :key => 'securityGroupInfo'},
27
+ :ssl_certificates => {:action => 'DescribeSSLCertificates', :key => 'certsSet'},
28
+ :addresses => {:action => 'DescribeAddresses', :key => 'addressesSet'},
29
+ :uploads => {:action => 'DescribeUploads', :key => 'uploads'},
30
+ }.each do |method, options|
31
+ define_method method do
32
+ items(:action => options[:action], :key => options[:key])
33
+ end
34
+ end
35
+
36
+ def load_balancers
37
+ response = self.action('DescribeLoadBalancers', {})
38
+ [response['DescribeLoadBalancersResult']['LoadBalancerDescriptions']['member']].flatten rescue []
39
+ end
40
+
41
+ def security_group_rules
42
+ end
43
+
44
+ def find_instance_by_id(instance_id)
45
+ response = self.action('DescribeInstances', {'InstanceId.1' => instance_id})
46
+ response['DescribeInstancesResponse']['reservationSet']['item']['instancesSet']['item'] rescue nil
47
+ end
48
+
49
+ def stop_instances
50
+ until instances.all? {|instance| instance['instanceState']['name'] != 'running'} do
51
+ instances.each do |instance|
52
+ if instance['instanceState']['name'] != 'stopped'
53
+ self.action('StopInstances', {'InstanceId.1' => instance['instanceId']})
54
+ end
55
+ end
56
+ sleep 5
57
+ end
58
+ end
59
+
60
+ def delete_instances
61
+ until instances.empty? do
62
+ instances.each do |instance|
63
+ self.action('TerminateInstances', {'InstanceId.1' => instance['instanceId']})
64
+ end
65
+ uploads.each do |upload|
66
+ self.action('CancelUpload', {'ConversionTaskId' => upload['conversionTaskId']})
67
+ end
68
+ sleep 5
69
+ end
70
+ end
71
+
72
+ def delete_key_pairs
73
+ key_pairs.each do |key_pair|
74
+ self.action('DeleteKeyPair', {'KeyName' => key_pair['keyName']})
75
+ end
76
+ end
77
+
78
+ def find_security_group_by_name(name)
79
+ response = self.action('DescribeSecurityGroups', {'GroupName.1' => name})
80
+ response['DescribeSecurityGroupsResponse']['securityGroupInfo']['item'] rescue nil
81
+ end
82
+
83
+ def wait_security_group_status(name, status)
84
+ loop do
85
+ group = find_security_group_by_name(name)
86
+ break if group['groupStatus'] == status
87
+ sleep 1
88
+ end
89
+ end
90
+
91
+ def delete_security_group_rules
92
+ security_groups.each do |group|
93
+ rules = [group['ipPermissions']['item']].flatten rescue []
94
+ next if rules.empty?
95
+ rules.each do |rule|
96
+ hash = {}
97
+ hash["IpPermissions.1.IpProtocol"] = rule['ipProtocol']
98
+ hash["IpPermissions.1.FromPort"] = rule['fromPort'] if rule['fromPort']
99
+ hash["IpPermissions.1.ToPort"] = rule['toPort'] if rule['toPort']
100
+ hash["IpPermissions.1.InOut"] = rule['inOut'] if rule['inOut']
101
+ if rule.key?('ipRanges')
102
+ hash["IpPermissions.1.IpRanges.1.CidrIp"] = rule['ipRanges']['item']['cidrIp'] # TODO: can't delete cidr ip rules
103
+ elsif rule.key?('groups')
104
+ hash["IpPermissions.1.Groups.1.GroupName"] = rule['groups']['item']['groupName']
105
+ end
106
+ hash['GroupName'] = group['groupName']
107
+ self.action('RevokeSecurityGroupIngress', hash)
108
+ wait_security_group_status(group['groupName'], 'applied')
109
+ end
110
+ end
111
+ end
112
+
113
+ def delete_security_groups
114
+ until security_groups.empty? do
115
+ security_groups.each do |group|
116
+ self.action('DeleteSecurityGroup', 'GroupName' => group['groupName'])
117
+ end
118
+ sleep 5
119
+ end
120
+ end
121
+
122
+ def delete_load_balancers
123
+ # not implemented yet
124
+ end
125
+
126
+ def delete_volumes
127
+ # not implemented yet
128
+ end
129
+
130
+ def delete_resources
131
+ stop_instances
132
+ delete_instances
133
+ delete_key_pairs
134
+ delete_security_group_rules
135
+ delete_security_groups
136
+ delete_load_balancers
137
+ delete_volumes
138
+ end
139
+ end
140
+ end
141
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ace-client-ext
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - tily
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-11-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.7'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.7'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '10.0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '10.0'
46
+ description: extensions for ace-client
47
+ email:
48
+ - tidnlyam@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - VERSION
59
+ - ace-client-ext.gemspec
60
+ - lib/ace-client/niftycloud/computing.rb
61
+ homepage: ''
62
+ licenses:
63
+ - MIT
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 1.8.24
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: extensions for ace-client
86
+ test_files: []