delphix_rb 0.3.2 → 0.4.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: 56a1affce06b12e415543aaa7b97c44d3b8a4bc1
4
- data.tar.gz: 4420c8394370da8ba0d030b347599c7cce34c022
3
+ metadata.gz: bff1174801b4cb91c827a180e9ce73a1bcf57078
4
+ data.tar.gz: 032d486d0422ed1c71c909eb5132984e0ad9c00e
5
5
  SHA512:
6
- metadata.gz: 7a2f0139d60cdf37cb59b60840d39b4017de8db558fc584677016faf2a8eab218be0484c83f44c3552f226933be93229ea93bf8af63379e5b5145ccbe6567cf5
7
- data.tar.gz: e87c8c86b30f4aa608b6c56d07d8217226e8d8354b2218d81b053a294ad4296bce752fa485bc78d80cdf58936b32514675a0540caf826f0d27c6c0c7b33fca6f
6
+ metadata.gz: 4263da09eaa0b0cfed3940917e39b836771727f595911b0f62c244d6e3ecc4953aab6bd4ff13e48b58529d267e435e4717d58d04c37bc58afd9742ccb206e410
7
+ data.tar.gz: 3f043a207f09e457abede59b09d7c7cebdbaf808571a567c2491d9c752f381df022b092269b8370a9802605df09df6a3d00f313a947e847a3a97748826c98006
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.2
1
+ 0.4.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 0.3.2 ruby lib
5
+ # stub: delphix_rb 0.4.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "delphix_rb"
9
- s.version = "0.3.2"
9
+ s.version = "0.4.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-01-22"
14
+ s.date = "2016-02-04"
15
15
  s.description = "Delphix Engine REST API"
16
16
  s.email = "michael.kuehl@delphix.com"
17
17
  s.extra_rdoc_files = [
@@ -32,11 +32,13 @@ Gem::Specification.new do |s|
32
32
  "lib/delphix/base.rb",
33
33
  "lib/delphix/base_array.rb",
34
34
  "lib/delphix/connection.rb",
35
+ "lib/delphix/database.rb",
35
36
  "lib/delphix/environment.rb",
36
37
  "lib/delphix/error.rb",
37
38
  "lib/delphix/group.rb",
38
39
  "lib/delphix/repository.rb",
39
- "lib/delphix/util.rb"
40
+ "lib/delphix/util.rb",
41
+ "lib/delphix/vdb.rb"
40
42
  ]
41
43
  s.homepage = "http://github.com/mickuehl/delphix_rb"
42
44
  s.licenses = ["MIT"]
data/lib/delphix.rb CHANGED
@@ -1,9 +1,9 @@
1
-
1
+
2
2
  require 'json'
3
3
  require 'excon'
4
4
 
5
5
  module Delphix
6
-
6
+
7
7
  require 'delphix/error'
8
8
  require 'delphix/util'
9
9
  require 'delphix/connection'
@@ -12,20 +12,22 @@ module Delphix
12
12
  require 'delphix/environment'
13
13
  require 'delphix/group'
14
14
  require 'delphix/repository'
15
-
15
+ require 'delphix/vdb'
16
+ require 'delphix/database'
17
+
16
18
  def authenticate!(username,password)
17
-
19
+
18
20
  case
19
21
  when !username.is_a?(String)
20
22
  raise ArgumentError, "Expected a String, got: '#{username}'"
21
23
  when !password.is_a?(String)
22
24
  raise ArgumentError, "Expected a String, got: '#{password}'"
23
25
  end
24
-
26
+
25
27
  reset_connection!
26
-
28
+
27
29
  # create a session
28
- session = {
30
+ session = {
29
31
  :type => 'APISession',
30
32
  :version => {
31
33
  :type => 'APIVersion', # Delphix Engine 4.3.1.x and above
@@ -35,7 +37,7 @@ module Delphix
35
37
  }
36
38
  }
37
39
  post('/resources/json/delphix/session', session.to_json)
38
-
40
+
39
41
  # authenticate the session
40
42
  auth = {
41
43
  :type => 'LoginRequest',
@@ -43,9 +45,9 @@ module Delphix
43
45
  :password => password
44
46
  }
45
47
  post('/resources/json/delphix/login', auth.to_json)
46
-
48
+
47
49
  end
48
-
50
+
49
51
  def environments
50
52
  envs = BaseArray.new
51
53
  result = get('/resources/json/delphix/environment', nil)['result']
@@ -54,7 +56,7 @@ module Delphix
54
56
  end
55
57
  envs
56
58
  end
57
-
59
+
58
60
  def groups
59
61
  groups = BaseArray.new
60
62
  result = get('/resources/json/delphix/group', nil)['result']
@@ -63,7 +65,7 @@ module Delphix
63
65
  end
64
66
  groups
65
67
  end
66
-
68
+
67
69
  def repositories
68
70
  repos = BaseArray.new
69
71
  result = get('/resources/json/delphix/repository', nil)['result']
@@ -72,33 +74,27 @@ module Delphix
72
74
  end
73
75
  repos
74
76
  end
75
-
76
- def targets
77
- end
78
-
79
- def sources
80
- end
81
-
77
+
82
78
  # a generic get method, used when there is not specialized method to invoke an API call
83
79
  def get(endpoint, payload)
84
80
  connection.get( endpoint, {}, :body => payload)
85
81
  end
86
-
82
+
87
83
  # a generic post method, used when there is not specialized method to invoke an API call
88
84
  def post(endpoint, payload)
89
85
  connection.post( endpoint, {}, :body => payload)
90
86
  end
91
-
87
+
92
88
  # a generic put method, used when there is not specialized method to invoke an API call
93
89
  def put(endpoint, payload)
94
90
  connection.put( endpoint, {}, :body => payload)
95
91
  end
96
-
92
+
97
93
  # a generic delete method, used when there is not specialized method to invoke an API call
98
94
  def delete(endpoint, payload)
99
95
  connection.delete( endpoint, {}, :body => payload)
100
96
  end
101
-
97
+
102
98
  def url
103
99
  @url ||= env_url
104
100
  @url
@@ -112,7 +108,7 @@ module Delphix
112
108
  def options
113
109
  @options ||= env_options
114
110
  end
115
-
111
+
116
112
  def options=(new_options)
117
113
  @options = env_options.merge(new_options || {})
118
114
  reset_connection!
@@ -121,13 +117,13 @@ module Delphix
121
117
  def debug
122
118
  @debug || false
123
119
  end
124
-
125
- def debug=(new_value)
120
+
121
+ def debug=(new_value)
126
122
  @debug = new_value
127
123
  end
128
-
124
+
129
125
  private
130
-
126
+
131
127
  def connection
132
128
  @connection ||= Connection.new(url, options)
133
129
  end
@@ -135,22 +131,22 @@ private
135
131
  def reset_connection!
136
132
  @connection = nil
137
133
  end
138
-
134
+
139
135
  def env_url
140
136
  ENV['DELPHIX_URL'] || default_url
141
137
  end
142
-
138
+
143
139
  def default_url
144
140
  'http://localhost'
145
141
  end
146
-
142
+
147
143
  def env_options
148
144
  {}
149
145
  end
150
-
146
+
151
147
  module_function :get, :post, :put, :delete,
152
148
  :environments, :groups, :repositories,
153
149
  :authenticate!, :url, :url=, :options, :options=, :connection, :reset_connection!, :debug, :debug=,
154
150
  :env_url, :default_url, :env_options
155
-
156
- end
151
+
152
+ end
@@ -0,0 +1,36 @@
1
+
2
+ class Delphix::Database
3
+ include Delphix::Base
4
+
5
+ def initialize(reference, details=nil)
6
+ super(reference, details)
7
+ end
8
+
9
+ # basic operations
10
+
11
+ def delete
12
+ delphix_delete("#{base_endpoint}/#{reference}", nil)['result']
13
+ end
14
+
15
+ # inherited operations
16
+
17
+ def refresh_details
18
+ @details = delphix_get("#{base_endpoint}/#{reference}", nil)['result']
19
+ end
20
+
21
+ def base_endpoint
22
+ '/resources/json/delphix/database'
23
+ end
24
+
25
+ # class methods
26
+
27
+ def self.list
28
+ databases = Delphix::BaseArray.new
29
+ result = Delphix.get('/resources/json/delphix/database', nil)['result']
30
+ result.each do |db|
31
+ databases << Delphix::Database.new(db['reference'],db)
32
+ end
33
+ databases
34
+ end
35
+
36
+ end
@@ -4,47 +4,37 @@ require 'delphix/repository'
4
4
 
5
5
  class Delphix::Environment
6
6
  include Delphix::Base
7
-
7
+
8
8
  def initialize(reference, details=nil)
9
9
  super(reference, details)
10
10
  end
11
-
11
+
12
12
  # basic operations
13
-
13
+
14
14
  def enable
15
15
  delphix_post("#{base_endpoint}/#{reference}/enable", nil)['result']
16
16
  end
17
-
17
+
18
18
  def disable
19
19
  delphix_post("#{base_endpoint}/#{reference}/disable", nil)['result']
20
20
  end
21
-
21
+
22
22
  def delete
23
23
  delphix_delete("#{base_endpoint}/#{reference}", nil)['result']
24
24
  end
25
-
25
+
26
26
  # inherited operations
27
-
27
+
28
28
  def refresh_details
29
29
  @details = delphix_get("#{base_endpoint}/#{reference}", nil)['result']
30
30
  end
31
-
31
+
32
32
  def base_endpoint
33
33
  '/resources/json/delphix/environment'
34
34
  end
35
-
36
- # additional operations
37
- def repositories
38
- repos = Delphix::BaseArray.new
39
- result = get('/resources/json/delphix/repository', nil)['result']
40
- result.each do |o|
41
- repos << Delphix::Repository.new(connection, o) if o['environment'] == reference
42
- end
43
- repos
44
- end
45
-
46
- # instance methods
47
-
35
+
36
+ # class methods
37
+
48
38
  def self.create(name, address, port, toolkit_path, username, password)
49
39
  body = {
50
40
  :type => 'HostEnvironmentCreateParameters',
@@ -71,17 +61,26 @@ class Delphix::Environment
71
61
  }
72
62
  }
73
63
  response = Delphix.post('/resources/json/delphix/environment', body.to_json)
74
-
64
+
75
65
  ref = response['result']
76
66
  job = response['job']
77
-
67
+
78
68
  # create a new skeleton group object
79
69
  env = Delphix::Environment.new ref
80
-
70
+
81
71
  # refresh the object from the DE
82
72
  env.refresh_details
83
-
73
+
84
74
  env
85
75
  end
86
-
76
+
77
+ def self.list
78
+ envs = Delphix::BaseArray.new
79
+ result = Delphix.get('/resources/json/delphix/environment', nil)['result']
80
+ result.each do |env|
81
+ envs << Delphix::Environment.new(env['reference'],env)
82
+ end
83
+ envs
84
+ end
85
+
87
86
  end
data/lib/delphix/group.rb CHANGED
@@ -1,29 +1,52 @@
1
1
 
2
2
  class Delphix::Group
3
3
  include Delphix::Base
4
-
4
+
5
5
  def initialize(reference, details=nil)
6
6
  super(reference, details)
7
7
  end
8
-
8
+
9
+ # basic operations
10
+
11
+ def delete
12
+ delphix_delete("#{base_endpoint}/#{reference}", nil)['result']
13
+ end
14
+
15
+ # inherited operations
16
+
9
17
  def refresh_details
10
- @details = delphix_get("/resources/json/delphix/group/#{reference}", nil)['result']
18
+ @details = delphix_get("#{base_endpoint}/#{reference}", nil)['result']
19
+ end
20
+
21
+ def base_endpoint
22
+ '/resources/json/delphix/group'
11
23
  end
12
-
24
+
25
+ # class methods
26
+
13
27
  def self.create(name)
14
28
  body = {
15
29
  :type => 'Group',
16
30
  :name => name
17
31
  }
18
32
  ref = Delphix.post('/resources/json/delphix/group', body.to_json)['result']
19
-
33
+
20
34
  # create a new skeleton group object
21
35
  group = Delphix::Group.new ref
22
-
23
- # refresh the object from the DE
36
+
37
+ # refresh the object from DE
24
38
  group.refresh_details
25
-
39
+
26
40
  group
27
41
  end
28
-
42
+
43
+ def self.list
44
+ groups = Delphix::BaseArray.new
45
+ result = Delphix.get('/resources/json/delphix/group', nil)['result']
46
+ result.each do |group|
47
+ groups << Delphix::Group.new(group['reference'],group)
48
+ end
49
+ groups
50
+ end
51
+
29
52
  end
@@ -1,13 +1,28 @@
1
1
 
2
2
  class Delphix::Repository
3
3
  include Delphix::Base
4
-
4
+
5
5
  def initialize(reference, details=nil)
6
6
  super(reference, details)
7
7
  end
8
-
8
+
9
9
  def refresh_details
10
- @details = delphix_get("/resources/json/delphix/repository/#{reference}", nil)['result']
10
+ @details = delphix_get("#{base_endpoint}/#{reference}", nil)['result']
11
+ end
12
+
13
+ def base_endpoint
14
+ '/resources/json/delphix/repository'
11
15
  end
12
-
16
+
17
+ # class methods
18
+
19
+ def self.list
20
+ repos = Delphix::BaseArray.new
21
+ result = Delphix.get('/resources/json/delphix/repository', nil)['result']
22
+ result.each do |repo|
23
+ repos << Delphix::Repository.new(repo['reference'],repo)
24
+ end
25
+ repos
26
+ end
27
+
13
28
  end
data/lib/delphix/util.rb CHANGED
@@ -4,17 +4,17 @@ module Delphix::Util
4
4
  include Delphix::Error
5
5
 
6
6
  module_function
7
-
7
+
8
8
  def parse_json(body)
9
9
  JSON.parse(body) unless body.nil? || body.empty? || (body == 'null')
10
10
  rescue JSON::ParserError => ex
11
11
  raise UnexpectedResponseError, ex.message
12
12
  end
13
-
13
+
14
14
  def pretty_print_json(body)
15
15
  JSON.pretty_generate( JSON.parse( body))
16
16
  end
17
-
17
+
18
18
  module_function :parse_json, :pretty_print_json
19
-
19
+
20
20
  end
@@ -0,0 +1,57 @@
1
+
2
+ class Delphix::VDB
3
+ include Delphix::Base
4
+
5
+ def initialize(reference, details=nil)
6
+ super(reference, details)
7
+ end
8
+
9
+ # basic operations
10
+
11
+ def delete
12
+
13
+ end
14
+
15
+ # inherited operations
16
+
17
+ def refresh_details
18
+ @details = delphix_get("#{base_endpoint}/#{reference}", nil)['result']
19
+ end
20
+
21
+ def base_endpoint
22
+ '/resources/json/delphix/group'
23
+ end
24
+
25
+ def self.create(name, source_ref, group_ref, environment_ref, mount_base, port, params={})
26
+
27
+ body = {
28
+ :type => 'MySQLProvisionParameters',
29
+ :container => {
30
+ :type => 'MySQLDatabaseContainer',
31
+ :name => name,
32
+ :group => group_ref,
33
+ :sourcingPolicy => {
34
+ :type => 'SourcingPolicy'
35
+ }
36
+ },
37
+ :source => {
38
+ :type => 'MySQLVirtualSource',
39
+ :mountBase => mount_base
40
+ },
41
+ :sourceConfig => {
42
+ :type => 'MySQLServerConfig',
43
+ :port => port,
44
+ :repository => environment_ref
45
+ },
46
+ :timeflowPointParameters => {
47
+ :type => 'TimeflowPointSemantic',
48
+ :container => source_ref,
49
+ :location => 'LATEST_SNAPSHOT'
50
+ }
51
+ }
52
+
53
+ response = Delphix.post('/resources/json/delphix/database/provision', body.to_json)
54
+ response
55
+ end
56
+
57
+ 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: 0.3.2
4
+ version: 0.4.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-01-22 00:00:00.000000000 Z
11
+ date: 2016-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: shoulda
@@ -115,11 +115,13 @@ files:
115
115
  - lib/delphix/base.rb
116
116
  - lib/delphix/base_array.rb
117
117
  - lib/delphix/connection.rb
118
+ - lib/delphix/database.rb
118
119
  - lib/delphix/environment.rb
119
120
  - lib/delphix/error.rb
120
121
  - lib/delphix/group.rb
121
122
  - lib/delphix/repository.rb
122
123
  - lib/delphix/util.rb
124
+ - lib/delphix/vdb.rb
123
125
  homepage: http://github.com/mickuehl/delphix_rb
124
126
  licenses:
125
127
  - MIT