Class: Chef::Knife::ProfitbricksVolumeCreate

Inherits:
Chef::Knife
  • Object
show all
Includes:
ProfitbricksBase
Defined in:
lib/chef/knife/profitbricks_volume_create.rb

Instance Method Summary collapse

Methods included from ProfitbricksBase

#connection, #error_and_exit, #get_image, included, #msg_pair, #validate_required_params

Instance Method Details

#runObject



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
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/chef/knife/profitbricks_volume_create.rb', line 67

def run
  $stdout.sync = true
  validate_required_params(%i(datacenter_id name type size), Chef::Config[:knife])

  if !Chef::Config[:knife][:image] && !Chef::Config[:knife][:imagealias]
    ui.error("Either '--image' or '--image-alias' parameter must be provided")
    exit(1)
  end

  if !Chef::Config[:knife][:sshkeys] && !Chef::Config[:knife][:imagepassword]
    ui.error("Either '--image-password' or '--ssh-keys' parameter must be provided")
    exit(1)
  end

  print "#{ui.color('Creating volume...', :magenta)}"

  params = {
    name: Chef::Config[:knife][:name],
    size: Chef::Config[:knife][:size],
    bus: Chef::Config[:knife][:bus] || 'VIRTIO',
    type: Chef::Config[:knife][:type],
    licenceType: Chef::Config[:knife][:licencetype],
  }

  if Chef::Config[:knife][:image]
    params[:image] = Chef::Config[:knife][:image]
  end

  if Chef::Config[:knife][:imagealias]
    params[:imageAlias] = Chef::Config[:knife][:imagealias]
  end

  if Chef::Config[:knife][:sshkeys]
    params[:sshKeys] = Chef::Config[:knife][:sshkeys]
  end

  if Chef::Config[:knife][:imagepassword]
    params[:imagePassword] = Chef::Config[:knife][:imagepassword]
  end

  if Chef::Config[:knife][:volume_availability_zone]
    params[:availabilityZone] = Chef::Config[:knife][:volume_availability_zone]
  end

  connection
  volume = ProfitBricks::Volume.create(
    Chef::Config[:knife][:datacenter_id],
    params.compact
  )

  dot = ui.color('.', :magenta)
  volume.wait_for(300) { print dot; ready? }
  volume.reload

  puts "\n"
  puts "#{ui.color('ID', :cyan)}: #{volume.id}"
  puts "#{ui.color('Name', :cyan)}: #{volume.properties['name']}"
  puts "#{ui.color('Size', :cyan)}: #{volume.properties['size']}"
  puts "#{ui.color('Bus', :cyan)}: #{volume.properties['bus']}"
  puts "#{ui.color('Image', :cyan)}: #{volume.properties['image']}"
  puts "#{ui.color('Type', :cyan)}: #{volume.properties['type']}"
  puts "#{ui.color('Licence Type', :cyan)}: #{volume.properties['licenceType']}"
  puts "#{ui.color('Zone', :cyan)}: #{volume.properties['availabilityZone']}"
  puts 'done'
end