ey-core 3.0.1 → 3.0.2

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: 1735145773a7daa8e7451c0ed1afb9df56331650
4
- data.tar.gz: b15e7b305b51ee772b4705a417a7bba24a5fd80e
3
+ metadata.gz: 269d550338f16307307e6d1bbcf9c515c63fdd0f
4
+ data.tar.gz: 8629dc4f02afc87b6d1787038c7af137f08b5b07
5
5
  SHA512:
6
- metadata.gz: d93a039a423036941c0e80c0db46fdbef6e6fdfdddc2d55545b5fca94a8d55a3420b515c55ab2a099c719e628b3138c420f06e08df019b5b1670ff05de69db45
7
- data.tar.gz: 42fd085d88c44d9e70b036aeea5ad89988a9bdc098d83468b8a1ad3a028f537b9f7e8f3fdf44d41fc2baa30c68cbd8573c38b8d53d44d6e07bb4a1efd4305f9d
6
+ metadata.gz: a7deba35785bcbf0e54472e455f0a0617c8c199af99c55a4b51c1d00fb0b4948bb386e3798752991939d194ad3794dec8c15e7cdffcab6c1dd2c4982bc9e629d
7
+ data.tar.gz: 314171d0e20483463062e695a1f45abe1688658d67979d821bcd827d4b35fdf98ec0792371abe9ef08e06e6e43611845c3ac7c22b1e5ccc8563e0f4375eabcb6
@@ -141,6 +141,7 @@ class Ey::Core::Client < Cistern::Service
141
141
  request :create_message
142
142
  request :create_password_reset
143
143
  request :create_provider
144
+ request :create_server
144
145
  request :create_ssl_certificate
145
146
  request :create_storage
146
147
  request :create_storage_user
@@ -4,11 +4,17 @@ class Ey::Core::Client::Environment < Ey::Core::Model
4
4
  identity :id
5
5
 
6
6
  attribute :classic, type: :boolean
7
- attribute :name
8
7
  attribute :created_at, type: :time
8
+ attribute :database_stack
9
9
  attribute :deleted_at, type: :time
10
+ attribute :deploy_method
11
+ attribute :framework_env
12
+ attribute :language
10
13
  attribute :monitor_url
14
+ attribute :name
11
15
  attribute :region
16
+ attribute :release_label
17
+ attribute :stack_name
12
18
 
13
19
  has_one :account
14
20
  has_one :database_service
@@ -32,6 +32,8 @@ class Ey::Core::Client::Server < Ey::Core::Model
32
32
  has_many :events, key: :server_events
33
33
  has_many :firewalls
34
34
 
35
+ attr_accessor :mnt_volume_size, :volume_size, :iops, :snapshot_id
36
+
35
37
  def reboot
36
38
  requires :identity
37
39
 
@@ -42,15 +44,22 @@ class Ey::Core::Client::Server < Ey::Core::Model
42
44
 
43
45
  def save!
44
46
  if new_record?
45
- raise "adding servers is not yet implemented"
46
47
  requires :flavor_id, :role, :environment
47
48
 
48
49
  server_attributes = {
49
- "flavor" => self.flavor_id,
50
- "role" => self.role,
50
+ "environment" => environment.id,
51
+ "snapshot" => self.snapshot_id,
52
+ "server" => {
53
+ "flavor" => self.flavor_id,
54
+ "iops" => self.iops,
55
+ "location" => self.location || environment.region,
56
+ "mnt_volume_size" => self.mnt_volume_size,
57
+ "name" => self.name,
58
+ "role" => self.role,
59
+ "volume_size" => self.volume_size,
60
+ }
51
61
  }
52
- server_attributes.merge!("location" => self.location)
53
- connection.create_server(server_attributes)
62
+ connection.requests.new(connection.create_server(server_attributes).body["request"])
54
63
  else
55
64
  requires :identity
56
65
  server_attributes = Cistern::Hash.slice(Cistern::Hash.stringify_keys(self.attributes), "provisioned_at", "deprovisioned_at", "disappeared_at")
@@ -11,7 +11,7 @@ class Ey::Core::Client::Volume < Ey::Core::Model
11
11
  attribute :mount
12
12
  attribute :mount_options
13
13
  attribute :name
14
- attribute :provisioned_id, type: :integer
14
+ attribute :provisioned_id, type: :string
15
15
  attribute :size, type: :integer
16
16
 
17
17
  has_one :provider
@@ -95,7 +95,7 @@ class Ey::Core::Client
95
95
  "token" => SecureRandom.hex(16),
96
96
  "updated_at" => Time.now.to_s,
97
97
  "volumes" => url_for("/servers/#{id}/volumes"),
98
- "role" => role,
98
+ "role" => role || "solo",
99
99
  }
100
100
  end
101
101
 
@@ -35,12 +35,15 @@ class Ey::Core::Client
35
35
  "classic" => true,
36
36
  "clusters" => url_for("/environments/#{resource_id}/clusters"),
37
37
  "created_at" => Time.now,
38
+ "database_stack" => "postgres9_4",
38
39
  "id" => resource_id,
39
40
  "internal_private_key" => internal_key[:private_key],
40
41
  "internal_public_key" => internal_key[:public_key],
41
42
  "keypairs" => url_for("/environments/#{resource_id}/keypairs"),
42
43
  "logical_databases_url" => url_for("/environments/#{resource_id}/logical-databases"),
44
+ "release_label" => "stable-v4-2.0.101",
43
45
  "servers" => url_for("/environments/#{resource_id}/servers"),
46
+ "stack_name" => "nginx_passenger4",
44
47
  "updated_at" => Time.now,
45
48
  )
46
49
 
@@ -0,0 +1,119 @@
1
+ class Ey::Core::Client
2
+ class Real
3
+ def create_server(params={})
4
+ request(
5
+ :method => :post,
6
+ :path => "/servers",
7
+ :url => params.delete("url"),
8
+ :body => params,
9
+ )
10
+ end
11
+ end
12
+
13
+ class Mock
14
+ def create_server(params={})
15
+ params = Cistern::Hash.stringify_keys(params)
16
+ server = params["server"]
17
+
18
+ require_parameters(params, "environment")
19
+ require_parameters(params["server"], "role", "location", "flavor")
20
+ if server["role"] == "util"
21
+ require_parameters(params["server"], "name")
22
+ end
23
+
24
+ request_id = self.uuid
25
+ resource_id = self.serial_id
26
+ provisioned_id = "i-#{SecureRandom.hex(4)}"
27
+ environment_id = resource_identity(params["environment"])
28
+ environment = find(:environments, environment_id)
29
+ account = resource_identity(environment["account"])
30
+ provider = self.data[:providers].values.detect { |p| p["account"] == url_for("/accounts/#{account}") }
31
+
32
+ servers = self.data[:servers].values.select { |s| s["environment"] == url_for("/environments/#{environment_id}") }
33
+
34
+ if servers.count == 1 && servers.first["role"] == "solo" && server["role"] == "db_slave"
35
+ response(
36
+ :status => 422,
37
+ :body => {"errors" => ["Cannot add a DB Slave"]},
38
+ )
39
+ end
40
+
41
+ resource = {
42
+ "account" => url_for("/accounts/#{account}"),
43
+ "alerts" => url_for("/servers/#{resource_id}/alerts"),
44
+ "created_at" => Time.now.to_s,
45
+ "deprovisioned_at" => nil,
46
+ "devices" => block_device_map(server),
47
+ "enabled" => true,
48
+ "environment" => url_for("/environments/#{environment["id"]}"),
49
+ "flavor" => { "id" => server["flavor"] },
50
+ "id" => resource_id,
51
+ "location" => environment["region"],
52
+ "logs" => url_for("/servers/#{resource_id}/logs"),
53
+ "name" => server["name"],
54
+ "private_hostname" => "#{provisioned_id}.private.example.org",
55
+ "provider" => url_for("/providers/#{provider["id"]}"),
56
+ "provisioned_at" => Time.now.to_s,
57
+ "provisioned_id" => provisioned_id,
58
+ "public_hostname" => "#{provisioned_id}.public.example.org",
59
+ "public_key" => mock_ssh_key[:fingerprint],
60
+ "ssh_port" => 22,
61
+ "state" => "running",
62
+ "token" => SecureRandom.hex(16),
63
+ "updated_at" => Time.now.to_s,
64
+ "volumes" => url_for("/servers/#{resource_id}/volumes"),
65
+ "role" => server["role"],
66
+ }
67
+
68
+ request = {
69
+ "id" => request_id,
70
+ "type" => "provision_server",
71
+ "successful" => "true",
72
+ "started_at" => Time.now,
73
+ "finished_at" => nil,
74
+ "resource_url" => url_for("/servers/#{resource_id}"),
75
+ "resource" => [:servers, resource_id, resource],
76
+ }
77
+
78
+ self.data[:requests][request_id] = request
79
+
80
+ response_hash = request.dup
81
+ response_hash.delete("resource")
82
+
83
+ response(
84
+ :body => {"request" => response_hash},
85
+ :status => 201,
86
+ )
87
+ end
88
+
89
+ def block_device_map(params={})
90
+ [
91
+ {
92
+ "mount" => "/",
93
+ "file_system" => "ext4",
94
+ "device" => "/dev/sda",
95
+ "size" => 100,
96
+ "delete_on_termination" => true,
97
+ "volume_type" => "gp2",
98
+ },
99
+ {
100
+ "mount" => "/mnt",
101
+ "file_system" => "ext4",
102
+ "device" => "/dev/sdo",
103
+ "delete_on_termination" => true,
104
+ "size" => params["mnt_volume_size"] || 100,
105
+ "volume_type" => "gp2",
106
+ },
107
+ {
108
+ "mount" => nil,
109
+ "file_system" => "swap",
110
+ "device" => "/dev/sdp",
111
+ "delete_on_termination" => true,
112
+ "size" => 8,
113
+ "volume_type" => "gp2",
114
+ },
115
+ { "device" => "/dev/sdb", "name" => "ephemeral0", },
116
+ ]
117
+ end
118
+ end
119
+ end
@@ -1,5 +1,5 @@
1
1
  module Ey
2
2
  module Core
3
- VERSION = "3.0.1"
3
+ VERSION = "3.0.2"
4
4
  end
5
5
  end
data/spec/servers_spec.rb CHANGED
@@ -34,6 +34,47 @@ describe 'servers' do
34
34
  environment.servers.all(role: "solo").to contain_exactly(server)
35
35
  }
36
36
  end
37
+
38
+ it "adds an app server" do
39
+ expect {
40
+ client.servers.create!(
41
+ :environment => environment,
42
+ :role => "app",
43
+ :flavor_id => "m3.large",
44
+ ).resource!
45
+ }.to change { environment.servers.count }.by(1)
46
+ end
47
+
48
+ it "adds a util server" do
49
+ expect {
50
+ client.servers.create!(
51
+ :environment => environment,
52
+ :role => "util",
53
+ :flavor_id => "m3.large",
54
+ :name => "resque",
55
+ ).resource!
56
+ }.to change { environment.servers.count }.by(1)
57
+ end
58
+
59
+ it "does not add a util server without a name" do
60
+ expect {
61
+ client.servers.create!(
62
+ :environment => environment,
63
+ :role => "util",
64
+ :flavor_id => "m3.large",
65
+ ).resource!
66
+ }.to raise_error(Ey::Core::Response::BadRequest, /value is empty: name/)
67
+ end
68
+
69
+ it "does not add a db slave" do
70
+ expect {
71
+ client.servers.create!(
72
+ :environment => environment,
73
+ :role => "db_slave",
74
+ :flavor_id => "m3.large",
75
+ )
76
+ }.to raise_error(Ey::Core::Response::Unprocessable, /cannot add a db slave/i)
77
+ end
37
78
  end
38
79
 
39
80
  context "with multiple servers" do
@@ -51,5 +92,46 @@ describe 'servers' do
51
92
  expect(environment.servers.first(role: "app")).to be
52
93
  expect(environment.servers.first(role: "db_master")).to be
53
94
  end
95
+
96
+ it "adds an app server" do
97
+ expect {
98
+ client.servers.create!(
99
+ :environment => environment,
100
+ :role => "app",
101
+ :flavor_id => "m3.large",
102
+ ).resource!
103
+ }.to change { environment.servers.count }.by(1)
104
+ end
105
+
106
+ it "adds a util server" do
107
+ expect {
108
+ client.servers.create!(
109
+ :environment => environment,
110
+ :role => "util",
111
+ :flavor_id => "m3.large",
112
+ :name => "resque",
113
+ ).resource!
114
+ }.to change { environment.servers.count }.by(1)
115
+ end
116
+
117
+ it "does not add a util server without a name" do
118
+ expect {
119
+ client.servers.create!(
120
+ :environment => environment,
121
+ :role => "util",
122
+ :flavor_id => "m3.large",
123
+ ).resource!
124
+ }.to raise_error(Ey::Core::Response::BadRequest, /value is empty: name/)
125
+ end
126
+
127
+ it "adds a db slave" do
128
+ expect {
129
+ client.servers.create!(
130
+ :environment => environment,
131
+ :role => "db_slave",
132
+ :flavor_id => "m3.large",
133
+ ).resource!
134
+ }.to change { environment.servers.count }.by(1)
135
+ end
54
136
  end
55
137
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ey-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.1
4
+ version: 3.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Lane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-04 00:00:00.000000000 Z
11
+ date: 2016-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -279,6 +279,7 @@ files:
279
279
  - lib/ey-core/requests/create_message.rb
280
280
  - lib/ey-core/requests/create_password_reset.rb
281
281
  - lib/ey-core/requests/create_provider.rb
282
+ - lib/ey-core/requests/create_server.rb
282
283
  - lib/ey-core/requests/create_ssl_certificate.rb
283
284
  - lib/ey-core/requests/create_storage.rb
284
285
  - lib/ey-core/requests/create_storage_user.rb