forked from cloudfoundry/docs-bosh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinks-properties.html.md.erb
118 lines (91 loc) · 2.9 KB
/
links-properties.html.md.erb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
---
title: Link Properties
---
(See [Links](links.html) for an introduction.)
<p class="note">Note: This feature is available with bosh-release v255.5+.</p>
In addition to sharing basic networking information (name, AZ, IP, etc.) links allow to show arbitrary information via properties. Most common example is sharing a port value. From our previous example here is a `web` job that communicates with a database:
```yaml
name: web
templates:
config.erb: config/conf
consumes:
- name: primary_db
type: db
provides:
- name: incoming
type: http
properties: {...}
```
Here is an example Postgres job that provides a `conn` link of type `db`, and now also includes server's port for client connections:
```yaml
name: postgres
templates: {...}
provides:
- name: conn
type: db
properties:
- port
- adapter
- username
- password
- name
properties:
port:
description: "Port for Postgres to listen on"
default: 5432
adapter:
description: "Type of this database"
default: postgres
username:
description: "Username"
default: postgres
password:
description: "Password"
name:
description: "Database name"
default: postgres
```
Note that all properties included in the `conn` link are defined by the job itself in the `properties` section.
And finally `web` job can use the port and a few other properties in its ERB templates when configuring how to connect to the database:
```ruby
<%%=
db = link("primary_db")
result = {
"production" => {
"adapter" => db.p("adapter"),
"username" => db.p("username"),
"password" => db.p("password"),
"host" => db.instances.first.address,
"port" => db.p("port"),
"database" => db.p("name"),
"encoding" => "utf8",
"reconnect" => false,
"pool" => 5
}
}
JSON.dump(result)
%>
```
Similarly to how [`p` template accessor](jobs.html#properties) provides access to the job's top level properties, `link("...").p("...)` and `link("...").if_p("...)` accessors work with properties included in the link.
`if_p` template accessor becomes very useful when trying to provide backwards compatibility around link properties as their interface changes. For example if Postgres job author decides to start including `encoding` property in the link and `web` job's author wants to continue to support older links that don't include that information, they can use `db.if_p("encoding") { ... }`.
And finally in the above example the operator needs to configure database password to deploy these two jobs since password property doesn't have a default:
```yaml
instance_groups:
- name: app
jobs:
- name: web
release: my-app
consumes:
primary_db: {from: data_db}
- name: data_db
jobs:
- name: postgres
release: postgres
provides:
conn: {as: data_db}
properties:
password: some-password
```
---
Next: [Manual linking](links-manual.html)
[Back to Table of Contents](index.html#deployment-config)