Sha256: fdb5a1e3a11224ddf31cc3f6e3aae68b491389b2c1f98a0999207fc048a82218

Contents?: true

Size: 989 Bytes

Versions: 7

Compression:

Stored size: 989 Bytes

Contents

module KnifeJoyent
  class JoyentSnapshotCreate < Chef::Knife

    include KnifeJoyent::Base

    banner 'knife joyent snapshot create <server> <snapshot_name>'

    def run
      unless name_args.size == 2
        show_usage
        exit 1
      end

      server = name_args[0]
      ssname = name_args[1]

      snapshot = self.connection.snapshots.create(server, ssname)
      puts ui.color("Created snapshot", :cyan)
      puts ui.output({
        :server => snapshot.machine_id,
        :name => snapshot.name,
        :state => snapshot.state,
        :created => snapshot.created
      })
      exit 0
    rescue Excon::Errors::Conflict => e
      if e.response && e.response.body.kind_of?(String)
        error = MultiJson.decode(e.response.body)
        puts ui.error(error['message'])
        exit 1
      else
        puts ui.error(e.message)
        exit 1
      end
    rescue => e
      puts ui.error('Unexpected Error Occured:' + e.message)
      exit 1
    end

  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
knife-joyent-0.0.7 lib/chef/knife/joyent_snapshot_create.rb
knife-joyent-0.0.6 lib/chef/knife/joyent_snapshot_create.rb
knife-joyent-0.0.5 lib/chef/knife/joyent_snapshot_create.rb
knife-joyent-0.0.4 lib/chef/knife/joyent_snapshot_create.rb
knife-joyent-0.0.3 lib/chef/knife/joyent_snapshot_create.rb
knife-joyent-0.0.2 lib/knife-joyent/joyent_snapshot_create.rb
knife-joyent-0.0.1 lib/knife-joyent/joyent_snapshot_create.rb