Sha256: 443c6c062f7fc056a3be7e1448e4773f1a01168baadd8903943b303b43ef0f68

Contents?: true

Size: 1.71 KB

Versions: 1

Compression:

Stored size: 1.71 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',
             proc: proc { |name| Chef::Config[:knife][:name] = name }

      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 }#,

      def run
        $stdout.sync = true

        validate_required_params(%i(name location), Chef::Config[:knife])

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

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

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

        @dcid = datacenter.id
        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

1 entries across 1 versions & 1 rubygems

Version Path
knife-profitbricks-2.0.1 lib/chef/knife/profitbricks_datacenter_create.rb