delphix_rb 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: daed234fef34458e823c0fa19808a74d14aff98d
4
- data.tar.gz: 1f43e1635971445dcb06d5d181edfbce4835be6b
3
+ metadata.gz: b610f70f46c2543a921ad3cdfbf9b0ca02ec27ff
4
+ data.tar.gz: 3bd756ab20fdcb7a4bd9ec15801e9815972e2901
5
5
  SHA512:
6
- metadata.gz: ea8cc1edad7624064f4401b9358134906cf05d8011a4f7ea1353fa6975acca55708764495e2153c1d43b3560c745e2c2f9ca6a11343372bef761817fbb664e1d
7
- data.tar.gz: 73c326f83c72d0d4800206db8793b563ef8e8ef4535a80d545110e01bbe58e9a4d0f53454ef93deb7ac407b5c88cce1e3d88ba88faccc4e27d2a7a845b829834
6
+ metadata.gz: 5c16f33eb586f3be717ecebd85ad1c4bf3202976d75ac33c6e25dfcac162b542926aea08a43e613b375f60a4f6f4d66b7414970f8120f3574f6f9f17f00bed8d
7
+ data.tar.gz: 897fceae8b65006b2db1463ab4b567c410b7cd205a15f721aaf8adb424459f51c103ff83517258b897e967e67796e9274043030b9f17a77ebed30e2e1e0595ba
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.1.0
data/delphix_rb.gemspec CHANGED
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: delphix_rb 1.0.0 ruby lib
5
+ # stub: delphix_rb 1.1.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "delphix_rb"
9
- s.version = "1.0.0"
9
+ s.version = "1.1.0"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Michael Kuehl"]
14
- s.date = "2016-02-04"
14
+ s.date = "2016-02-16"
15
15
  s.description = "Delphix Engine REST API"
16
16
  s.email = "michael.kuehl@delphix.com"
17
17
  s.extra_rdoc_files = [
@@ -36,7 +36,11 @@ Gem::Specification.new do |s|
36
36
  "lib/delphix/environment.rb",
37
37
  "lib/delphix/error.rb",
38
38
  "lib/delphix/group.rb",
39
+ "lib/delphix/job.rb",
39
40
  "lib/delphix/repository.rb",
41
+ "lib/delphix/response.rb",
42
+ "lib/delphix/source.rb",
43
+ "lib/delphix/sourceconfig.rb",
40
44
  "lib/delphix/util.rb"
41
45
  ]
42
46
  s.homepage = "http://github.com/mickuehl/delphix_rb"
data/lib/delphix.rb CHANGED
@@ -9,11 +9,16 @@ module Delphix
9
9
  require 'delphix/connection'
10
10
  require 'delphix/base'
11
11
  require 'delphix/base_array'
12
+ require 'delphix/response'
13
+
12
14
  require 'delphix/environment'
13
15
  require 'delphix/group'
14
16
  require 'delphix/repository'
15
17
  require 'delphix/database'
16
-
18
+ require 'delphix/source'
19
+ require 'delphix/sourceconfig'
20
+ require 'delphix/job'
21
+
17
22
  def authenticate!(username,password)
18
23
 
19
24
  case
data/lib/delphix/base.rb CHANGED
@@ -4,8 +4,9 @@ module Delphix::Base
4
4
 
5
5
  attr_accessor :details
6
6
 
7
- # The private new method accepts a connection and a hash
7
+ # The private new method accepts a reference string and a hash
8
8
  def initialize(reference=nil, details=nil)
9
+ # FIXME change this, passing the reference does not make sense !!!
9
10
  if details == nil
10
11
  @details = { 'reference' => reference }
11
12
  else
@@ -31,7 +32,8 @@ module Delphix::Base
31
32
  end
32
33
 
33
34
  def refresh_details
34
- # Placeholder. Subclasses need to implement this
35
+ # TODO Subclasses should override this if needed
36
+ @details = Delphix.get("#{base_endpoint}/#{reference}")['result']
35
37
  end
36
38
 
37
39
  def base_endpoint
@@ -41,5 +43,5 @@ module Delphix::Base
41
43
  def to_s
42
44
  "#{self.class.name}[#{type}, #{name}, #{reference}]"
43
45
  end
44
-
46
+
45
47
  end
@@ -9,17 +9,21 @@ class Delphix::Database
9
9
  # basic operations
10
10
 
11
11
  def delete
12
- Delphix.delete("#{base_endpoint}/#{reference}")['result']
12
+ Delphix::Response.new( Delphix.delete("#{base_endpoint}/#{reference}"))
13
13
  end
14
14
 
15
15
  # specific operations
16
16
 
17
- # inherited operations
17
+ def start
18
+ Delphix::Response.new( Delphix.post("/resources/json/delphix/source/#{lookup_source_ref}/start"))
19
+ end
18
20
 
19
- def refresh_details
20
- @details = Delphix.get("#{base_endpoint}/#{reference}")['result']
21
+ def stop
22
+ Delphix::Response.new( Delphix.post("/resources/json/delphix/source/#{lookup_source_ref}/stop"))
21
23
  end
22
24
 
25
+ # inherited operations
26
+
23
27
  def base_endpoint
24
28
  '/resources/json/delphix/database'
25
29
  end
@@ -63,8 +67,16 @@ class Delphix::Database
63
67
  }
64
68
  }
65
69
 
66
- response = Delphix.post('/resources/json/delphix/database/provision', body.to_json)
67
- response
70
+ Delphix::Response.new( Delphix.post('/resources/json/delphix/database/provision', body.to_json))
71
+
72
+ end
73
+
74
+ private
75
+
76
+ def lookup_source_ref
77
+ sources = Delphix::Source.list
78
+ source = sources.filter_by 'container', reference
79
+ source[0].reference # FIXME assumes there is only one ...
68
80
  end
69
81
 
70
82
  end
@@ -12,25 +12,53 @@ class Delphix::Environment
12
12
  # basic operations
13
13
 
14
14
  def delete
15
- Delphix.delete("#{base_endpoint}/#{reference}")['result']
15
+ Delphix::Response.new( Delphix.delete("#{base_endpoint}/#{reference}"))
16
16
  end
17
17
 
18
18
  # specific operations
19
19
 
20
- def enable
21
- Delphix.post("#{base_endpoint}/#{reference}/enable")['result']
22
- end
20
+ def enable(enable_all_sources=false)
21
+ resp = Delphix::Response.new( Delphix.post("#{base_endpoint}/#{reference}/enable"))
22
+ return resp if !enable_all_sources
23
+
24
+ resp.wait_for_completion
23
25
 
24
- def disable
25
- Delphix.post("#{base_endpoint}/#{reference}/disable")['result']
26
+ # enable all sources on this environment
27
+ sources = lookup_sources
28
+ if sources != nil
29
+ sources.each do |src|
30
+ src.enable.wait_for_completion
31
+ end
32
+ end
33
+
34
+ resp
26
35
  end
27
36
 
28
- # inherited operations
37
+ def disable(disable_all_sources=true)
38
+
39
+ if disable_all_sources
40
+ # stop and disable all sources on this environment
41
+ sources = lookup_sources
42
+ if sources != nil
43
+ sources.each do |src|
44
+ if src.virtual?
45
+ src.stop.wait_for_completion
46
+ end
47
+ src.disable.wait_for_completion
48
+ end
49
+ end
50
+ end
51
+
52
+ # now disable the environment itself
53
+ Delphix::Response.new( Delphix.post("#{base_endpoint}/#{reference}/disable"))
54
+ end
29
55
 
30
- def refresh_details
31
- @details = Delphix.get("#{base_endpoint}/#{reference}")['result']
56
+ def refresh
57
+ Delphix::Response.new( Delphix.post("#{base_endpoint}/#{reference}/refresh"))
32
58
  end
33
59
 
60
+ # inherited operations
61
+
34
62
  def base_endpoint
35
63
  '/resources/json/delphix/environment'
36
64
  end
@@ -62,15 +90,17 @@ class Delphix::Environment
62
90
  }
63
91
  }
64
92
  }
65
- response = Delphix.post('/resources/json/delphix/environment', body.to_json)
66
93
 
67
- ref = response['result']
68
- job = response['job']
94
+ # create the environment
95
+ resp = Delphix::Response.new( Delphix.post('/resources/json/delphix/environment', body.to_json))
96
+ return nil if resp.is_error?
69
97
 
70
- # create a new skeleton group object
71
- env = Delphix::Environment.new ref
98
+ # wait until the environment has been created
99
+ resp.job.wait_for_completion
72
100
 
73
- # refresh the object from the DE
101
+ # create a new skeleton environment object
102
+ env = Delphix::Environment.new resp.details
103
+ # and refresh the object from the engine
74
104
  env.refresh_details
75
105
 
76
106
  env
@@ -85,4 +115,41 @@ class Delphix::Environment
85
115
  envs
86
116
  end
87
117
 
118
+ private
119
+
120
+ def lookup_sources
121
+ repos = Delphix::Repository.list
122
+ repos = repos.filter_by 'environment', reference
123
+
124
+ # lookup sourceconfigs that are related to this environment
125
+ configs = Delphix::SourceConfig.list
126
+ sourceconfigs = Delphix::BaseArray.new
127
+ repos.each do |repo|
128
+ result = configs.filter_by 'repository', repo.reference
129
+ if result != nil
130
+ result.each do |i|
131
+ sourceconfigs << i
132
+ end
133
+ end
134
+ end
135
+
136
+ # find the matching sources
137
+ sources = Delphix::Source.list
138
+
139
+ # filter to match sourceconfigs
140
+ vdb_sources = Delphix::BaseArray.new
141
+ sourceconfigs.each do |conf|
142
+ result = sources.filter_by 'config', conf.reference
143
+ if result != nil
144
+ result.each do |i|
145
+ vdb_sources << i
146
+ end
147
+ end
148
+ end
149
+
150
+ return nil if vdb_sources.size == 0
151
+ vdb_sources
152
+
153
+ end
154
+
88
155
  end
data/lib/delphix/group.rb CHANGED
@@ -9,17 +9,13 @@ class Delphix::Group
9
9
  # basic operations
10
10
 
11
11
  def delete
12
- Delphix.delete("#{base_endpoint}/#{reference}")['result']
12
+ Delphix::Response.new( Delphix.delete("#{base_endpoint}/#{reference}"))
13
13
  end
14
14
 
15
15
  # specific operations
16
16
 
17
17
  # inherited operations
18
18
 
19
- def refresh_details
20
- @details = Delphix.get("#{base_endpoint}/#{reference}")['result']
21
- end
22
-
23
19
  def base_endpoint
24
20
  '/resources/json/delphix/group'
25
21
  end
@@ -0,0 +1,61 @@
1
+
2
+ class Delphix::Job
3
+ include Delphix::Base
4
+
5
+ def initialize(reference, details=nil)
6
+ super(reference, details)
7
+ end
8
+
9
+ # basic operations
10
+
11
+ # specific operations
12
+
13
+ def state
14
+ @details['jobState'] # RUNNING, SUSPENDED, CANCELED, COMPLETED, FAILED
15
+ end
16
+
17
+ def state?
18
+ refresh_details
19
+ state
20
+ end
21
+
22
+ def cancel!
23
+ Delphix.post("#{base_endpoint}/#{reference}/cancel")['result']
24
+ end
25
+
26
+ def suspend!
27
+ Delphix.post("#{base_endpoint}/#{reference}/suspend")['result']
28
+ end
29
+
30
+ def resume!
31
+ Delphix.post("#{base_endpoint}/#{reference}/resume")['result']
32
+ end
33
+
34
+ def wait_for_completion
35
+ begin
36
+ sleep 1
37
+ end while state? == 'RUNNING'
38
+ end
39
+
40
+ # inherited operations
41
+
42
+ def to_s
43
+ "#{self.class.name}[#{@details['actionType']}, #{reference}, #{@details['jobState']}]"
44
+ end
45
+
46
+ def base_endpoint
47
+ '/resources/json/delphix/job'
48
+ end
49
+
50
+ # class methods
51
+
52
+ def self.list
53
+ jobs = Delphix::BaseArray.new
54
+ result = Delphix.get('/resources/json/delphix/job')['result']
55
+ result.each do |job|
56
+ jobs << Delphix::Job.new(job['reference'],job)
57
+ end
58
+ jobs
59
+ end
60
+
61
+ end
@@ -41,10 +41,6 @@ class Delphix::Repository
41
41
 
42
42
  # inherited operations
43
43
 
44
- def refresh_details
45
- @details = Delphix.get("#{base_endpoint}/#{reference}")['result']
46
- end
47
-
48
44
  def base_endpoint
49
45
  '/resources/json/delphix/repository'
50
46
  end
@@ -0,0 +1,42 @@
1
+
2
+ class Delphix::Response
3
+ include Delphix::Error
4
+
5
+ attr_accessor :details
6
+
7
+ # The private new method accepts a reference string and a hash
8
+ def initialize(details={})
9
+ @details = details
10
+ end
11
+
12
+ def type
13
+ @details['type'] || 'unknown'
14
+ end
15
+
16
+ def status
17
+ @details['status'] || 'unknown'
18
+ end
19
+
20
+ def details
21
+ @details['result'] || nil
22
+ end
23
+
24
+ def is_error?
25
+ @details['type'] == 'ErrorResult'
26
+ end
27
+
28
+ def job
29
+ return nil if @details['job'] == nil
30
+ Delphix::Job.new( @details['job'])
31
+ end
32
+
33
+ def wait_for_completion
34
+ return if is_error?
35
+ job.wait_for_completion if job
36
+ end
37
+
38
+ def to_s
39
+ "#{self.class.name}[#{type}, #{status}]"
40
+ end
41
+
42
+ end
@@ -0,0 +1,49 @@
1
+
2
+ class Delphix::Source
3
+ include Delphix::Base
4
+
5
+ def initialize(reference, details=nil)
6
+ super(reference, details)
7
+ end
8
+
9
+ # basic operations
10
+
11
+ # specific operations
12
+ def start
13
+ Delphix::Response.new( Delphix.post("#{base_endpoint}/#{reference}/start"))
14
+ end
15
+
16
+ def stop
17
+ Delphix::Response.new( Delphix.post("#{base_endpoint}/#{reference}/stop"))
18
+ end
19
+
20
+ def enable
21
+ Delphix::Response.new( Delphix.post("#{base_endpoint}/#{reference}/enable"))
22
+ end
23
+
24
+ def disable
25
+ Delphix::Response.new( Delphix.post("#{base_endpoint}/#{reference}/disable"))
26
+ end
27
+
28
+ def virtual?
29
+ @details['virtual'] == true
30
+ end
31
+
32
+ # inherited operations
33
+
34
+ def base_endpoint
35
+ '/resources/json/delphix/source'
36
+ end
37
+
38
+ # class methods
39
+
40
+ def self.list
41
+ sources = Delphix::BaseArray.new
42
+ result = Delphix.get('/resources/json/delphix/source')['result']
43
+ result.each do |src|
44
+ sources << Delphix::Source.new(src['reference'],src)
45
+ end
46
+ sources
47
+ end
48
+
49
+ end
@@ -0,0 +1,30 @@
1
+
2
+ class Delphix::SourceConfig
3
+ include Delphix::Base
4
+
5
+ def initialize(reference, details=nil)
6
+ super(reference, details)
7
+ end
8
+
9
+ # basic operations
10
+
11
+ # specific operations
12
+
13
+ # inherited operations
14
+
15
+ def base_endpoint
16
+ '/resources/json/delphix/sourceconfig'
17
+ end
18
+
19
+ # class methods
20
+
21
+ def self.list
22
+ sources = Delphix::BaseArray.new
23
+ result = Delphix.get('/resources/json/delphix/sourceconfig')['result']
24
+ result.each do |src|
25
+ sources << Delphix::SourceConfig.new(src['reference'],src)
26
+ end
27
+ sources
28
+ end
29
+
30
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: delphix_rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Kuehl
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-04 00:00:00.000000000 Z
11
+ date: 2016-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: shoulda
@@ -119,7 +119,11 @@ files:
119
119
  - lib/delphix/environment.rb
120
120
  - lib/delphix/error.rb
121
121
  - lib/delphix/group.rb
122
+ - lib/delphix/job.rb
122
123
  - lib/delphix/repository.rb
124
+ - lib/delphix/response.rb
125
+ - lib/delphix/source.rb
126
+ - lib/delphix/sourceconfig.rb
123
127
  - lib/delphix/util.rb
124
128
  homepage: http://github.com/mickuehl/delphix_rb
125
129
  licenses: