Sha256: e48548b42cb85755f44eb9445e0f312cb658d2d594148812216deea5251a4b22

Contents?: true

Size: 1.58 KB

Versions: 4

Compression:

Stored size: 1.58 KB

Contents

require 'chef/knife/profitbricks_base'

class Chef
  class Knife
    class ProfitbricksDatacenterCreate < Knife
      include Knife::ProfitbricksBase

      banner 'knife profitbricks datacenter create (options)'

      option :name,
             short: '-n NAME',
             long: '--name NAME',
             description: 'Name of the data center',
             required: true

      option :description,
             short: '-D DESCRIPTION',
             long: '--description DESCRIPTION',
             description: 'Description of the data center'

      option :location,
             short: '-l LOCATION',
             long: '--location LOCATION',
             description: 'Location of the data center',
             proc: proc { |location| Chef::Config[:knife][:location] = location },
             required: true

      def run
        $stdout.sync = true

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

        connection
        datacenter = ProfitBricks::Datacenter.create(
          name: config[:name],
          description: config[:description],
          location: config[:location]
        )

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

        puts "\n"
        puts "#{ui.color('ID', :cyan)}: #{datacenter.id}"
        puts "#{ui.color('Name', :cyan)}: #{datacenter.properties['name']}"
        puts "#{ui.color('Description', :cyan)}: #{datacenter.properties['description']}"
        puts "#{ui.color('Location', :cyan)}: #{datacenter.properties['location']}"
        puts 'done'
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
knife-profitbricks-1.2.1 lib/chef/knife/profitbricks_datacenter_create.rb
knife-profitbricks-1.2.0 lib/chef/knife/profitbricks_datacenter_create.rb
knife-profitbricks-1.1.2 lib/chef/knife/profitbricks_datacenter_create.rb
knife-profitbricks-1.1.1 lib/chef/knife/profitbricks_datacenter_create.rb