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
|
# File 'lib/sunzi/cloud/linode.rb', line 6
def do_setup
@sshkey = File.read(File.expand_path(@config['root_sshkey_path'])).chomp
if @sshkey.match(/\n/)
abort_with "RootSSHKey #{@sshkey.inspect} must not be multi-line! Check inside \"#{@config['root_sshkey_path']}\""
end
choose(:plan, @api.avail.linodeplans)
choose(:datacenter, @api.avail.datacenters, :label_method => :location)
choose(:distribution, @api.avail.distributions, :filter => 'distributions_filter')
choose(:kernel, @api.avail.kernels, :filter => 'kernels_filter')
@swap_size = ask('swap size in MB? (default: 256MB): ', Integer) { |q| q.default = 256 }
proceed?
say "creating a new linode..."
result = @api.linode.create(
:DatacenterID => @attributes[:datacenterid],
:PlanID => @attributes[:planid],
:PaymentTerm => @config['payment_term'])
@linodeid = result.linodeid
say "created a new instance: linodeid = #{@linodeid}"
result = @api.linode.list.select{|i| i.linodeid == @linodeid }.first
@totalhd = result.totalhd
say "Updating settings..."
@group = @config['group'][@env]
settings = { :LinodeID => @linodeid, :Label => @name, :lpm_displayGroup => @group }
settings.update(@config['settings']) if @config['settings']
@api.linode.update(settings)
say "Creating a root disk..."
result = @api.linode.disk.createfromdistribution(
:LinodeID => @linodeid,
:DistributionID => @attributes[:distributionid],
:Label => "#{@attributes[:distribution_label]} Image",
:Size => @totalhd - @swap_size,
:rootPass => @config['root_pass'],
:rootSSHKey => @sshkey
)
@root_diskid = result.diskid
say "Creating a swap disk..."
result = @api.linode.disk.create(
:LinodeID => @linodeid,
:Label => "#{@swap_size}MB Swap Image",
:Type => 'swap',
:Size => @swap_size
)
@swap_diskid = result.diskid
say "Creating a config profile..."
result = @api.linode.config.create(
:LinodeID => @linodeid,
:KernelID => @attributes[:kernelid],
:Label => "#{@attributes[:distribution_label]} Profile",
:DiskList => [ @root_diskid, @swap_diskid ].join(',')
)
@config_id = result.configid
say "Adding a private IP..."
result = @api.linode.ip.list(:LinodeID => @linodeid)
@public_ip = result.first.ipaddress
result = @api.linode.ip.addprivate(:LinodeID => @linodeid)
result = @api.linode.ip.list(:LinodeID => @linodeid).find{|i| i.ispublic == 0 }
@private_ip = result.ipaddress
@instance = {
:linode_id => @linodeid,
:env => @env,
:host => @host,
:fqdn => @fqdn,
:label => @name,
:group => @group,
:plan_id => @attributes[:planid],
:datacenter_id => @attributes[:datacenterid],
:datacenter_location => @attributes[:datacenter_location],
:distribution_id => @attributes[:distributionid],
:distribution_label => @attributes[:distribution_label],
:kernel_id => @attributes[:kernelid],
:kernel_label => @attributes[:kernel_label],
:swap_size => @swap_size,
:totalhd => @totalhd,
:root_diskid => @root_diskid,
:swap_diskid => @swap_diskid,
:config_id => @config_id,
:public_ip => @public_ip,
:private_ip => @private_ip,
}
say 'Done. Booting...'
@api.linode.boot(:LinodeID => @linodeid)
end
|