Class: Chef::Knife::RdsInstanceRestoreFromDataBag
Constant Summary
Constants included
from RdsBase
Chef::Knife::RdsBase::APPLY_METHODS
Instance Method Summary
collapse
#assert_data_bag_exists!, #assert_data_bag_item_exists!, #assert_data_bag_item_valid!, #assert_required_data_bag_options_present!, #data_bag_exists?, #data_bag_item, #defined_params, included, #required_data_bag_options
Methods included from RdsBase
#assert_name_args_at_least!, #assert_valid_apply_method!, #authenticate!, #connect!, included, #rds
Instance Method Details
#data_bag_item_name ⇒ Object
54
55
56
|
# File 'lib/chef/knife/rds_instance_restore_from_data_bag.rb', line 54
def data_bag_item_name
db_instance_id
end
|
#db_instance ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/chef/knife/rds_instance_restore_from_data_bag.rb', line 66
def db_instance
unless @db_instance
begin
@db_instance = rds.client.describe_db_instances(db_instance_identifier: db_instance_id)
@db_instance = @db_instance[:db_instances].first
rescue AWS::RDS::Errors::DBInstanceNotFound => e
@db_instance = nil
end
end
@db_instance
end
|
#db_instance_id ⇒ Object
58
59
60
|
# File 'lib/chef/knife/rds_instance_restore_from_data_bag.rb', line 58
def db_instance_id
name_args.first
end
|
#db_snapshot_id ⇒ Object
62
63
64
|
# File 'lib/chef/knife/rds_instance_restore_from_data_bag.rb', line 62
def db_snapshot_id
name_args.last
end
|
#restore_instance! ⇒ Object
45
46
47
|
# File 'lib/chef/knife/rds_instance_restore_from_data_bag.rb', line 45
def restore_instance!
rds.client.restore_db_instance_from_db_snapshot(restore_params)
end
|
#restore_params ⇒ Object
49
50
51
52
|
# File 'lib/chef/knife/rds_instance_restore_from_data_bag.rb', line 49
def restore_params
{ db_instance_identifier: db_instance_id, db_snapshot_identifier: db_snapshot_id }
.merge(defined_params)
end
|
#run ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/chef/knife/rds_instance_restore_from_data_bag.rb', line 22
def run
assert_name_args_at_least!(2)
assert_data_bag_item_valid!
authenticate!
ui.info("You are trying to restore snapshot #{db_snapshot_id} into instance #{db_instance_id}")
unless db_instance.nil?
ui.info("Instance #{db_instance_id} already exists!")
exit 1
end
confirm("Restore Instance #{db_instance_id} from #{db_snapshot_id}")
restore_instance!
ui.info("Restore #{db_instance_id} from #{db_snapshot_id}")
end
|