cf_factory 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. data/bin/cf_factory +9 -9
  2. data/examples/base_vpc.rb +40 -40
  3. data/examples/cloudfront_private.rb +23 -23
  4. data/examples/cloudinit_script_for_one_instance.rb +77 -77
  5. data/examples/cloudinit_script_with_autoscaling.rb +85 -85
  6. data/examples/dynamodb_table.rb +24 -24
  7. data/examples/elastic_beanstalk_example.rb +23 -23
  8. data/examples/elb_with_cloudfront.rb +100 -100
  9. data/examples/instance_with_eip.rb +40 -40
  10. data/examples/instance_with_yum.rb +40 -40
  11. data/examples/just_an_instance.rb +31 -31
  12. data/examples/nat_mutual_monitoring.rb +69 -69
  13. data/examples/play_with_region_and_zones.rb +28 -28
  14. data/examples/ra_web_hosting.rb +148 -148
  15. data/examples/s3_with_cloudfront.rb +35 -35
  16. data/examples/test_vpc.rb +61 -61
  17. data/lib/cf_factory/as/cf_as_group.rb +80 -77
  18. data/lib/cf_factory/as/cf_as_launch_config.rb +55 -55
  19. data/lib/cf_factory/as/cf_as_scaling_policy.rb +35 -35
  20. data/lib/cf_factory/as/cf_as_update_policy.rb +23 -0
  21. data/lib/cf_factory/base/cf_base.rb +112 -102
  22. data/lib/cf_factory/base/cf_ec2_tag.rb +34 -34
  23. data/lib/cf_factory/base/cf_generator.rb +20 -20
  24. data/lib/cf_factory/base/cf_helper.rb +93 -93
  25. data/lib/cf_factory/base/cf_inner.rb +74 -74
  26. data/lib/cf_factory/base/cf_main.rb +103 -103
  27. data/lib/cf_factory/base/cf_mapping.rb +28 -28
  28. data/lib/cf_factory/base/cf_named_inner.rb +70 -1
  29. data/lib/cf_factory/base/cf_output.rb +26 -26
  30. data/lib/cf_factory/base/cf_parameter.rb +27 -27
  31. data/lib/cf_factory/base/cf_script_reader.rb +34 -34
  32. data/lib/cf_factory/cloudformation/cf_cloud_formation_init.rb +27 -27
  33. data/lib/cf_factory/cloudformation/cf_cloudformation_command.rb +39 -39
  34. data/lib/cf_factory/cloudformation/cf_cloudformation_commands.rb +27 -27
  35. data/lib/cf_factory/cloudformation/cf_cloudformation_config.rb +35 -35
  36. data/lib/cf_factory/cloudformation/cf_cloudformation_file.rb +40 -40
  37. data/lib/cf_factory/cloudformation/cf_cloudformation_files.rb +27 -27
  38. data/lib/cf_factory/cloudformation/cf_cloudformation_inner.rb +30 -30
  39. data/lib/cf_factory/cloudformation/cf_cloudformation_package.rb +36 -36
  40. data/lib/cf_factory/cloudformation/cf_cloudformation_packages.rb +44 -44
  41. data/lib/cf_factory/cloudformation/cf_cloudformation_sources.rb +32 -32
  42. data/lib/cf_factory/cloudformation/cf_init_script.rb +80 -80
  43. data/lib/cf_factory/cloudfront/cf_cache_behavior.rb +39 -39
  44. data/lib/cf_factory/cloudfront/cf_cache_behaviors.rb +30 -30
  45. data/lib/cf_factory/cloudfront/cf_cloudfront_distribution.rb +66 -66
  46. data/lib/cf_factory/cloudfront/cf_custom_origin_config.rb +39 -39
  47. data/lib/cf_factory/cloudfront/cf_default_cache_behavior.rb +34 -34
  48. data/lib/cf_factory/cloudfront/cf_distribution_config.rb +33 -33
  49. data/lib/cf_factory/cloudfront/cf_forwarded_values.rb +27 -27
  50. data/lib/cf_factory/cloudfront/cf_logging.rb +26 -26
  51. data/lib/cf_factory/cloudfront/cf_origin.rb +42 -42
  52. data/lib/cf_factory/cloudfront/cf_s3_origin_config.rb +27 -27
  53. data/lib/cf_factory/cloudwatch/cf_cloud_watch_alarm.rb +60 -60
  54. data/lib/cf_factory/dynamo/cf_dynamo_table.rb +45 -45
  55. data/lib/cf_factory/eb/cd_eb_solution_stack.rb +27 -28
  56. data/lib/cf_factory/eb/cf_eb_application.rb +41 -41
  57. data/lib/cf_factory/eb/cf_eb_application_version.rb +24 -24
  58. data/lib/cf_factory/eb/cf_eb_configuration_template.rb +36 -36
  59. data/lib/cf_factory/eb/cf_eb_environment.rb +56 -56
  60. data/lib/cf_factory/eb/cf_eb_option_setting.rb +19 -19
  61. data/lib/cf_factory/ec2/cf_ebs_volume.rb +56 -56
  62. data/lib/cf_factory/ec2/cf_ec2_instance.rb +80 -66
  63. data/lib/cf_factory/ec2/cf_ec2_security_group.rb +42 -42
  64. data/lib/cf_factory/ec2/cf_ec2_security_group_egress.rb +30 -30
  65. data/lib/cf_factory/ec2/cf_ec2_security_group_ingress.rb +41 -41
  66. data/lib/cf_factory/ec2/cf_eip.rb +28 -28
  67. data/lib/cf_factory/ec2/cf_eip_association.rb +33 -31
  68. data/lib/cf_factory/ec2/cf_inner_network_interface.rb +26 -0
  69. data/lib/cf_factory/ec2/cf_network_interface.rb +40 -0
  70. data/lib/cf_factory/elb/cf_app_cookie_stickiness_policy.rb +17 -17
  71. data/lib/cf_factory/elb/cf_elb.rb +51 -51
  72. data/lib/cf_factory/elb/cf_health_check.rb +25 -25
  73. data/lib/cf_factory/elb/cf_lb_cookie_stickiness_policy.rb +17 -17
  74. data/lib/cf_factory/elb/cf_listener.rb +28 -28
  75. data/lib/cf_factory/help/fixes.rb +15 -15
  76. data/lib/cf_factory/help/ip_mask.rb +167 -167
  77. data/lib/cf_factory/help/template_validation.rb +30 -30
  78. data/lib/cf_factory/iam/cf_iam_access_key.rb +34 -34
  79. data/lib/cf_factory/iam/cf_iam_group.rb +32 -32
  80. data/lib/cf_factory/iam/cf_iam_instance_profile.rb +32 -32
  81. data/lib/cf_factory/iam/cf_iam_policy.rb +20 -20
  82. data/lib/cf_factory/iam/cf_iam_role.rb +58 -58
  83. data/lib/cf_factory/iam/cf_iam_statement.rb +25 -25
  84. data/lib/cf_factory/iam/cf_iam_user.rb +36 -36
  85. data/lib/cf_factory/iam/cf_policy_document.rb +21 -21
  86. data/lib/cf_factory/modules/base_vpc.rb +63 -63
  87. data/lib/cf_factory/rds/cf_rds_instance.rb +55 -55
  88. data/lib/cf_factory/rds/cf_rds_security_group.rb +35 -35
  89. data/lib/cf_factory/rds/cf_rds_security_group_ingress.rb +31 -31
  90. data/lib/cf_factory/rds/cf_rds_subnet_group.rb +31 -31
  91. data/lib/cf_factory/route53/cf_elb_alias_target.rb +23 -23
  92. data/lib/cf_factory/route53/cf_record_set.rb +63 -63
  93. data/lib/cf_factory/route53/cf_route53_record_set.rb +63 -63
  94. data/lib/cf_factory/route53/cf_route53_record_set_group.rb +44 -44
  95. data/lib/cf_factory/s3/cf_s3_bucket.rb +34 -34
  96. data/lib/cf_factory/s3/cf_web_site_config.rb +26 -26
  97. data/lib/cf_factory/sqs/cf_sqs_queue.rb +28 -28
  98. data/lib/cf_factory/vpc/cf_attach_gateway.rb +30 -30
  99. data/lib/cf_factory/vpc/cf_internet_gateway.rb +32 -32
  100. data/lib/cf_factory/vpc/cf_network_acl.rb +41 -41
  101. data/lib/cf_factory/vpc/cf_network_acl_association.rb +26 -26
  102. data/lib/cf_factory/vpc/cf_network_acl_entry.rb +39 -39
  103. data/lib/cf_factory/vpc/cf_route.rb +45 -45
  104. data/lib/cf_factory/vpc/cf_route_table.rb +43 -43
  105. data/lib/cf_factory/vpc/cf_route_table_association.rb +26 -26
  106. data/lib/cf_factory/vpc/cf_subnet.rb +50 -50
  107. data/lib/cf_factory/vpc/cf_vpc.rb +66 -66
  108. data/lib/cf_factory.rb +12 -12
  109. metadata +120 -91
@@ -1,77 +1,80 @@
1
- require 'cf_factory/base/cf_base'
2
- require 'cf_factory/base/cf_helper'
3
-
4
- module CfFactory
5
- class CfAsGroup
6
- include CfBase
7
-
8
- def initialize(name, availability_zones, launch_config, load_balancers, max_size, min_size, options)
9
- @name = name
10
- @availability_zones = availability_zones
11
- @launch_config = launch_config
12
- @load_balancers = load_balancers
13
- @max_size = max_size
14
- @min_size = min_size
15
-
16
- @cooldown = options[:cooldown]
17
- @desired_capacity = options[:desired_capacity]
18
- @health_check_grace_period = options[:health_check_grace_period]
19
- @health_check_type = options[:health_check_type]
20
- #TODO: NotificationConfiguration
21
- @subnets = options[:subnets]
22
- validate()
23
- end
24
-
25
- def set_tags(tag_list)
26
- @tag_list = []
27
- tag_list.each() {|tg|
28
- tg2 = tg.clone
29
- tg2.set_propagate_at_launch(true)
30
- puts ">>>>>>>>>>>>>>>>>>>>> "+tg2.inspect
31
- @tag_list << tg2
32
- }
33
- @tag_list
34
- end
35
-
36
- def validate
37
- if @max_size < @min_size
38
- raise Exception.new("max size (#{@max_size}) must be equal or larger min size (#{@min_size})")
39
- end
40
- if @health_check_type == "ELB" && @health_check_grace_period.nil?
41
- raise Exception.new("HealthCheckGracePeriod must be specified for ElasticLoadBalancer based health checks.")
42
- end
43
- end
44
-
45
- def get_cf_type
46
- "AWS::AutoScaling::AutoScalingGroup"
47
- end
48
-
49
- def get_cf_attributes
50
- {}
51
- end
52
-
53
- def get_cf_properties
54
- result = {"AvailabilityZones" => @availability_zones,
55
- "LaunchConfigurationName" => @launch_config.generate_ref,
56
- "LoadBalancerNames" => CfHelper.generate_ref_array(@load_balancers),
57
- "MaxSize" => @max_size,
58
- "MinSize" => @min_size
59
- }
60
- result["Cooldown"] = @cooldown unless @cooldown.nil?
61
- result["DesiredCapacity"] = @desired_capacity unless @desired_capacity.nil?
62
- result["HealthCheckGracePeriod"] = @health_check_grace_period.to_i unless @health_check_grace_period.nil?
63
- result["HealthCheckType"] = @health_check_type unless @health_check_type.nil?
64
- result["VPCZoneIdentifier"] = CfHelper.generate_ref_array(@subnets) unless @subnets.nil?
65
- result
66
- end
67
-
68
- def add_ingress_rule(ingress_rule)
69
- @ingress_rules << ingress_rule
70
- end
71
-
72
- def add_egress_rule(egress_rule)
73
- @egress_rules << egress_rule
74
- end
75
-
76
- end
77
- end
1
+ require 'cf_factory/base/cf_base'
2
+ require 'cf_factory/base/cf_helper'
3
+
4
+ module CfFactory
5
+ class CfAsGroup
6
+ include CfBase
7
+
8
+ def initialize(name, availability_zones, launch_config, load_balancers, max_size, min_size, options)
9
+ @name = name
10
+ @availability_zones = availability_zones
11
+ @launch_config = launch_config
12
+ @load_balancers = load_balancers
13
+ @max_size = max_size
14
+ @min_size = min_size
15
+
16
+ @cooldown = options[:cooldown]
17
+ @desired_capacity = options[:desired_capacity]
18
+ @health_check_grace_period = options[:health_check_grace_period]
19
+ @health_check_type = options[:health_check_type]
20
+ #TODO: NotificationConfiguration
21
+ @subnets = options[:subnets]
22
+ validate()
23
+ end
24
+
25
+ def set_tags(tag_list)
26
+ @tag_list = []
27
+ tag_list.each() {|tg|
28
+ tg2 = tg.clone
29
+ tg2.set_propagate_at_launch(true)
30
+ @tag_list << tg2
31
+ }
32
+ @tag_list
33
+ end
34
+
35
+ def set_update_policy(update_policy)
36
+ @update_policy = update_policy
37
+ end
38
+
39
+ def validate
40
+ if @max_size < @min_size
41
+ raise Exception.new("max size (#{@max_size}) must be equal or larger min size (#{@min_size})")
42
+ end
43
+ if @health_check_type == "ELB" && @health_check_grace_period.nil?
44
+ raise Exception.new("HealthCheckGracePeriod must be specified for ElasticLoadBalancer based health checks.")
45
+ end
46
+ end
47
+
48
+ def get_cf_type
49
+ "AWS::AutoScaling::AutoScalingGroup"
50
+ end
51
+
52
+ def get_cf_attributes
53
+ {}
54
+ end
55
+
56
+ def get_cf_properties
57
+ result = {"AvailabilityZones" => @availability_zones,
58
+ "LaunchConfigurationName" => @launch_config.generate_ref,
59
+ "LoadBalancerNames" => CfHelper.generate_ref_array(@load_balancers),
60
+ "MaxSize" => @max_size,
61
+ "MinSize" => @min_size
62
+ }
63
+ result["Cooldown"] = @cooldown unless @cooldown.nil?
64
+ result["DesiredCapacity"] = @desired_capacity unless @desired_capacity.nil?
65
+ result["HealthCheckGracePeriod"] = @health_check_grace_period.to_i unless @health_check_grace_period.nil?
66
+ result["HealthCheckType"] = @health_check_type unless @health_check_type.nil?
67
+ result["VPCZoneIdentifier"] = CfHelper.generate_ref_array(@subnets) unless @subnets.nil?
68
+ result
69
+ end
70
+
71
+ def add_ingress_rule(ingress_rule)
72
+ @ingress_rules << ingress_rule
73
+ end
74
+
75
+ def add_egress_rule(egress_rule)
76
+ @egress_rules << egress_rule
77
+ end
78
+
79
+ end
80
+ end
@@ -1,55 +1,55 @@
1
- require 'cf_factory/base/cf_base'
2
- require 'cf_factory/base/cf_helper'
3
-
4
- module CfFactory
5
- class CfAsLaunchConfig
6
- include CfBase
7
-
8
- def initialize(name, image_id, instance_type, options)
9
- @name = name
10
- @image_id = image_id
11
- @instance_type = instance_type
12
-
13
- @user_data = options[:user_data]
14
- @key_name = options[:key_name]
15
- @security_groups = options[:security_groups]
16
- @spot_price = options[:spot_price]
17
- #TODO: a couple of properties missing
18
- validate()
19
- end
20
-
21
- def get_cf_type
22
- "AWS::AutoScaling::LaunchConfiguration"
23
- end
24
-
25
- def get_cf_attributes
26
- super
27
- end
28
-
29
- def get_cf_properties
30
- result = {"ImageId" => @image_id,
31
- "InstanceType" => @instance_type
32
- }
33
- result["UserData"] = CfHelper.base64(@user_data) unless @user_data.nil?
34
- result["KeyName"] = @key_name unless @key_name.nil?
35
- result["SecurityGroups"] = CfHelper.generate_ref_array(@security_groups) unless @security_groups.nil?
36
- result["SpotPrice"] = @spot_price unless @spot_price.nil?
37
- result
38
- end
39
-
40
- def add_ingress_rule(ingress_rule)
41
- @ingress_rules << ingress_rule
42
- end
43
-
44
- def add_egress_rule(egress_rule)
45
- @egress_rules << egress_rule
46
- end
47
-
48
- private
49
-
50
- def validate
51
- raise Exception.new("instance type #{@instance_type} is not supported") unless CfEc2Instance::SUPPORTED_TYPES.include?(@instance_type)
52
- end
53
-
54
- end
55
- end
1
+ require 'cf_factory/base/cf_base'
2
+ require 'cf_factory/base/cf_helper'
3
+
4
+ module CfFactory
5
+ class CfAsLaunchConfig
6
+ include CfBase
7
+
8
+ def initialize(name, image_id, instance_type, options)
9
+ @name = name
10
+ @image_id = image_id
11
+ @instance_type = instance_type
12
+
13
+ @user_data = options[:user_data]
14
+ @key_name = options[:key_name]
15
+ @security_groups = options[:security_groups]
16
+ @spot_price = options[:spot_price]
17
+ #TODO: a couple of properties missing
18
+ validate()
19
+ end
20
+
21
+ def get_cf_type
22
+ "AWS::AutoScaling::LaunchConfiguration"
23
+ end
24
+
25
+ def get_cf_attributes
26
+ super
27
+ end
28
+
29
+ def get_cf_properties
30
+ result = {"ImageId" => @image_id,
31
+ "InstanceType" => @instance_type
32
+ }
33
+ result["UserData"] = CfHelper.base64(@user_data) unless @user_data.nil?
34
+ result["KeyName"] = @key_name unless @key_name.nil?
35
+ result["SecurityGroups"] = CfHelper.generate_ref_array(@security_groups) unless @security_groups.nil?
36
+ result["SpotPrice"] = @spot_price unless @spot_price.nil?
37
+ result
38
+ end
39
+
40
+ def add_ingress_rule(ingress_rule)
41
+ @ingress_rules << ingress_rule
42
+ end
43
+
44
+ def add_egress_rule(egress_rule)
45
+ @egress_rules << egress_rule
46
+ end
47
+
48
+ private
49
+
50
+ def validate
51
+ raise Exception.new("instance type #{@instance_type} is not supported") unless CfEc2Instance::SUPPORTED_TYPES.include?(@instance_type)
52
+ end
53
+
54
+ end
55
+ end
@@ -1,35 +1,35 @@
1
- require 'cf_factory/base/cf_base'
2
- require 'cf_factory/base/cf_helper'
3
-
4
- module CfFactory
5
- class CfAsScalingPolicy
6
- include CfBase
7
-
8
- def initialize(name, auto_scaling_group, adjustment_type, scaling_adjustment, options = {})
9
- @name = name
10
- @auto_scaling_group = auto_scaling_group
11
- @adjustment_type = adjustment_type
12
- @scaling_adjustment = scaling_adjustment
13
- @cooldown = options[:cooldown]
14
- end
15
-
16
- def get_cf_type
17
- "AWS::AutoScaling::ScalingPolicy"
18
- end
19
-
20
- def get_cf_attributes
21
- {}
22
- end
23
-
24
- def get_cf_properties
25
- result = {
26
- "AutoScalingGroupName" => @auto_scaling_group.generate_ref,
27
- "AdjustmentType" => @adjustment_type,
28
- "ScalingAdjustment" => @scaling_adjustment
29
- }
30
- result["Cooldown"] = @cooldown unless @cooldown.nil?
31
- result
32
- end
33
-
34
- end
35
- end
1
+ require 'cf_factory/base/cf_base'
2
+ require 'cf_factory/base/cf_helper'
3
+
4
+ module CfFactory
5
+ class CfAsScalingPolicy
6
+ include CfBase
7
+
8
+ def initialize(name, auto_scaling_group, adjustment_type, scaling_adjustment, options = {})
9
+ @name = name
10
+ @auto_scaling_group = auto_scaling_group
11
+ @adjustment_type = adjustment_type
12
+ @scaling_adjustment = scaling_adjustment
13
+ @cooldown = options[:cooldown]
14
+ end
15
+
16
+ def get_cf_type
17
+ "AWS::AutoScaling::ScalingPolicy"
18
+ end
19
+
20
+ def get_cf_attributes
21
+ {}
22
+ end
23
+
24
+ def get_cf_properties
25
+ result = {
26
+ "AutoScalingGroupName" => @auto_scaling_group.generate_ref,
27
+ "AdjustmentType" => @adjustment_type,
28
+ "ScalingAdjustment" => @scaling_adjustment
29
+ }
30
+ result["Cooldown"] = @cooldown unless @cooldown.nil?
31
+ result
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,23 @@
1
+ require 'cf_factory/base/cf_inner'
2
+
3
+ module CfFactory
4
+ class CfAsUpdatePolicy
5
+ include CfNamedInner
6
+
7
+ def initialize(update_policy_name, max_batch_size, min_instances_in_service, pause_time)
8
+ @name = update_policy_name
9
+ @max_batch_size = max_batch_size
10
+ @min_instances_in_service = min_instances_in_service
11
+ @pause_time = pause_time
12
+ @indent = 8
13
+ end
14
+
15
+ def get_cf_attributes
16
+ result = {}
17
+ result["MaxBatchSize"] = @max_batch_size
18
+ result["MinInstancesInService"] = @min_instances_in_service
19
+ result["PauseTime"] = @pause_time
20
+ result
21
+ end
22
+ end
23
+ end
@@ -1,102 +1,112 @@
1
- require 'cf_factory/base/cf_helper'
2
-
3
- module CfFactory
4
- module CfBase
5
- def get_name
6
- @name
7
- end
8
-
9
- def get_cf_type
10
- raise Exception.new("must be defined")
11
- end
12
-
13
- def get_deletion_policy
14
- @deletion_policy
15
- end
16
-
17
- def get_cf_attributes
18
- result = {}
19
- result["Metadata"] = @meta_data.generate unless @meta_data.nil?
20
- result
21
- end
22
-
23
- def get_cf_properties
24
- raise Exception.new("must be defined")
25
- end
26
-
27
- def generate_ref
28
- CfHelper.generate_ref(self.get_name)
29
- end
30
-
31
- def retrieve_attribute(attribute)
32
- CfHelper.generate_att(@name, attribute)
33
- end
34
-
35
- def set_meta_data(meta_data)
36
- @meta_data = meta_data
37
- end
38
-
39
- def set_tags(tag_list)
40
- #should be overwritten by those resources that support tags
41
- end
42
-
43
- def hash_to_string(hash, indent=0)
44
- output = ""
45
- hash.keys.each() do |key|
46
- value = hash[key]
47
- output += " " * indent
48
- case value.class.to_s
49
- when "Hash"
50
- output += " \"#{key}\" : \n{#{hash_to_string(value,indent+5)}},\n"
51
- when "EmbeddedProperty"
52
- output += " \"#{key}\" : \n{#{hash_to_string(value.generate,indent+5)},\n"
53
- else
54
- output += " \"#{key}\" : #{set_quotes(value)},\n"
55
- end
56
- end
57
- output
58
- output = output.chomp().chomp(",")
59
-
60
- end
61
-
62
- def generate
63
- @result = ""
64
- @result += " \"#{@name}\" : {\n"
65
- unless self.get_cf_type() == nil
66
- @result += " \"Type\" : \"#{self.get_cf_type()}\",\n"
67
- end
68
- unless self.get_deletion_policy() == nil
69
- @result += " \"DeletionPolicy\" : \"#{self.get_deletion_policy()}\",\n"
70
- end
71
- attributes = self.get_cf_attributes
72
- unless attributes.size == 0
73
- @result += "#{hash_to_string(attributes)},\n"
74
- end
75
- #
76
- properties = self.get_cf_properties
77
- properties["Tags"] = CfHelper.generate_inner_array(@tag_list) unless @tag_list.nil?
78
- unless properties.size == 0
79
- @result += " \"Properties\" : {\n"
80
- @result += hash_to_string(properties)
81
- @result += "\n }"
82
- end
83
- @result = @result.chomp.chomp(",")
84
- @result += "\n },\n"
85
- end
86
-
87
- # Sets leading and trailing quotes
88
- def set_quotes(value)
89
- if value.class.to_s == "String"
90
- if value.delete(" ").start_with?("{") || value.delete(" ").start_with?("[")
91
- value
92
- else
93
- "\"#{value}\""
94
- end
95
- else
96
- value
97
- end
98
- end
99
-
100
- end
101
-
102
- end
1
+ require 'cf_factory/base/cf_helper'
2
+
3
+ module CfFactory
4
+ module CfBase
5
+ def get_name
6
+ @name
7
+ end
8
+
9
+ def get_cf_type
10
+ raise Exception.new("must be defined")
11
+ end
12
+
13
+ def get_deletion_policy
14
+ @deletion_policy
15
+ end
16
+
17
+ def get_update_policy
18
+ @update_policy
19
+ end
20
+
21
+ def get_cf_attributes
22
+ result = {}
23
+ result["Metadata"] = @meta_data.generate unless @meta_data.nil?
24
+ result
25
+ end
26
+
27
+ def get_cf_properties
28
+ raise Exception.new("must be defined")
29
+ end
30
+
31
+ def generate_ref
32
+ CfHelper.generate_ref(self.get_name)
33
+ end
34
+
35
+ def retrieve_attribute(attribute)
36
+ CfHelper.generate_att(@name, attribute)
37
+ end
38
+
39
+ def set_meta_data(meta_data)
40
+ @meta_data = meta_data
41
+ end
42
+
43
+ def set_tags(tag_list)
44
+ #should be overwritten by those resources that support tags
45
+ end
46
+
47
+ def hash_to_string(hash, indent=0)
48
+ output = ""
49
+ hash.keys.each() do |key|
50
+ value = hash[key]
51
+ output += " " * indent
52
+ case value.class.to_s
53
+ when "Hash"
54
+ output += " \"#{key}\" : \n{#{hash_to_string(value,indent+5)}},\n"
55
+ when "EmbeddedProperty"
56
+ output += " \"#{key}\" : \n{#{hash_to_string(value.generate,indent+5)},\n"
57
+ else
58
+ output += " \"#{key}\" : #{set_quotes(value)},\n"
59
+ end
60
+ end
61
+ output
62
+ output = output.chomp().chomp(",")
63
+
64
+ end
65
+
66
+ def generate
67
+ @result = ""
68
+ @result += " \"#{@name}\" : {\n"
69
+ unless self.get_cf_type() == nil
70
+ @result += " \"Type\" : \"#{self.get_cf_type()}\",\n"
71
+ end
72
+ unless self.get_deletion_policy() == nil
73
+ @result += " \"DeletionPolicy\" : \"#{self.get_deletion_policy()}\",\n"
74
+ end
75
+ unless self.get_update_policy() == nil
76
+ self.get_update_policy.set_indent(8)
77
+ @result += " \"UpdatePolicy\" : {\n"
78
+ @result += "#{self.get_update_policy.generate()}\n"
79
+ @result += " },\n"
80
+ end
81
+ attributes = self.get_cf_attributes
82
+ unless attributes.size == 0
83
+ @result += "#{hash_to_string(attributes)},\n"
84
+ end
85
+ #
86
+ properties = self.get_cf_properties
87
+ properties["Tags"] = CfHelper.generate_inner_array(@tag_list) unless @tag_list.nil?
88
+ unless properties.size == 0
89
+ @result += " \"Properties\" : {\n"
90
+ @result += hash_to_string(properties)
91
+ @result += "\n }"
92
+ end
93
+ @result = @result.chomp.chomp(",")
94
+ @result += "\n },\n"
95
+ end
96
+
97
+ # Sets leading and trailing quotes
98
+ def set_quotes(value)
99
+ if value.class.to_s == "String"
100
+ if value.delete(" ").start_with?("{") || value.delete(" ").start_with?("[")
101
+ value
102
+ else
103
+ "\"#{value}\""
104
+ end
105
+ else
106
+ value
107
+ end
108
+ end
109
+
110
+ end
111
+
112
+ end
@@ -1,34 +1,34 @@
1
- require 'cf_factory/base/cf_inner'
2
-
3
- module CfFactory
4
- class CfEc2Tag
5
- include CfInner
6
-
7
- def initialize(key, value, options = {})
8
- @key = key
9
- @value = value
10
- @propagate_at_launch = options[:propagate_at_launch]
11
- end
12
-
13
- def set_propagate_at_launch(pal)
14
- @propagate_at_launch = pal
15
- end
16
-
17
- def get_cf_attributes
18
- result = {"Key" => @key,
19
- "Value" => @value
20
- }
21
- result["PropagateAtLaunch"] = @propagate_at_launch unless @propagate_at_launch.nil?
22
- result
23
- end
24
-
25
- def clone
26
- options = {}
27
- if @propagate_at_launch
28
- options[:propagate_at_launch] = @propagate_at_launch
29
- end
30
- CfEc2Tag.new(@key,@value,options)
31
- end
32
-
33
- end
34
- end
1
+ require 'cf_factory/base/cf_inner'
2
+
3
+ module CfFactory
4
+ class CfEc2Tag
5
+ include CfInner
6
+
7
+ def initialize(key, value, options = {})
8
+ @key = key
9
+ @value = value
10
+ @propagate_at_launch = options[:propagate_at_launch]
11
+ end
12
+
13
+ def set_propagate_at_launch(pal)
14
+ @propagate_at_launch = pal
15
+ end
16
+
17
+ def get_cf_attributes
18
+ result = {"Key" => @key,
19
+ "Value" => @value
20
+ }
21
+ result["PropagateAtLaunch"] = @propagate_at_launch unless @propagate_at_launch.nil?
22
+ result
23
+ end
24
+
25
+ def clone
26
+ options = {}
27
+ if @propagate_at_launch
28
+ options[:propagate_at_launch] = @propagate_at_launch
29
+ end
30
+ CfEc2Tag.new(@key,@value,options)
31
+ end
32
+
33
+ end
34
+ end