-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcseutils.cat
103 lines (93 loc) · 3.76 KB
/
cseutils.cat
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
name "cseutils"
rs_ca_ver 20131202
short_description "Launch a docker host which runs a few containers that'r useful to the CSE team"
parameter "cloud" do
type "string"
label "Cloud"
allowed_values "GCE", "AWS Oregon"
default "GCE"
end
parameter "persistent_storage_lineage_input" do
type "string"
label "Persistent Storage Lineage"
description "The RightScale volume backup lineage to use for backup and restore. If left blank a new lineage will be started. If no existing backups exist for the specified lineage, a blank volume will be created."
end
mapping "cloud_nice_name" do {
"GCE" => {
"cloud_href" => "/api/clouds/2175",
"mci_href" => "/api/multi_cloud_images/377766004",
"datacenter_href" => "/api/clouds/2175/datacenters/B3O1DOO8J2P62", # GCE Requires one, where AWS does not
"volume_device_name" => null
},
"AWS Oregon" => {
"cloud_href" => "/api/clouds/6",
"mci_href" => "/api/multi_cloud_images/377767004",
"datacenter_href" => "/api/clouds/6/datacenters/D8UCBVAE8MODP",
#"datacenter_href" => null, # GCE Requires one, where AWS does not
"volume_device_name" => "/dev/xvdb"
}
}
end
output "persistent_storage_source_output" do
label "Source"
category "Persistent Storage"
description "How the persistent storage was initialized."
end
output "persistent_storage_lineage_output" do
label "Lineage"
category "Persistent Storage"
description "The active lineage name. May be what was provided in the input, or a generated value."
end
resource "cseutils", type: "server" do
name "CSEUtils"
cloud_href map($cloud_nice_name, $cloud, "cloud_href")
server_template find("CSE Utils (Docker)", revision: "HEAD")
multi_cloud_image_href map($cloud_nice_name, $cloud, "mci_href")
datacenter_href map($cloud_nice_name, $cloud, "datacenter_href")
end
operation "enable" do
description "Attaches storage, starts services, get's this party started!"
definition "enable"
output_mappings do {
$persistent_storage_source_output => $source,
$persistent_storage_lineage_output => $lineage
} end
end
define enable(@cseutils,$persistent_storage_lineage_input,$cloud,$cloud_nice_name) return @cseutils,$source,$lineage task_label: "Enabling CSEUtils" do
$source = "initialized"
$lineage = "initialized"
if $persistent_storage_lineage_input == ""
$source = "Blank Volume"
$lineage = join(["cse-lineage", uuid()])
call attach_blank_volume(@cseutils,$lineage,$cloud,$cloud_nice_name) retrieve @volume_attachment
else
$source = "Snapshot to be named later"
$lineage = $persistent_storage_lineage_input
@current_backup = rs.backups.index(filter: [join(["latest_before==",now()])], lineage: $lineage)
if size(@current_backup) >= 1
rs.backups.restore(
backup: {
name: join(["cseutils-data-",$lineage]),
size: "10",
instance_href: @cseutils.current_instance().href
}
)
else
call attach_blank_volume(@cseutils,$lineage,$cloud,$cloud_nice_name) retrieve @volume_attachment
end
end
end
define attach_blank_volume(@cseutils,$lineage,$cloud,$cloud_nice_name) return @volume_attachment task_label: "Attach blank volume to CSEUtils" do
$dc_href = $cloud_nice_name[$cloud]['datacenter_href']
$device = $cloud_nice_name[$cloud]['volume_device_name'] || $lineage
# @extended_instance = @cseutils.current_instance().get(view: "extended")
@volume = @cseutils.current_instance().cloud().volumes().create(
volume: {
#datacenter_href: @extended_instance.datacenter().href,
datacenter_href: $dc_href,
name: join(["cseutils-data-",$lineage]),
size: "10"
}
)
@volume_attachment = @cseutils.current_instance().volume_attachments().create(volume_attachment: {volume_href: @volume.href, device: $device})
end