vzcdn 0.1.9 → 0.2.0

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.
@@ -1,36 +1,89 @@
1
1
  class ZoneAdd < Command
2
2
  def create_args
3
3
  # for level zone.Records.?
4
- add_arg('name', 'Name of the node to which this record pertains', /[[:alnum:]]+/)
4
+ add_arg('name', 'Name of the node to which this record pertains', /[[:alnum:]]/)
5
+ add_arg('gname', 'Name of load balancing or failover group', /[[:alnum:]]+/)
5
6
  add_arg('rdata', 'Additional resource record data, such as IP Address', /.*/)
6
7
  add_arg('ttl', 'Time to live, in seconds', /\d+/)
8
+ add_arg('weight', 'Load balancing weight assigned to the record', /\d+/)
9
+ add_arg('is-primary', 'Indicates whether record is the primary server/domain to which traffic will be directed.', ["true", "false"])
7
10
  end
8
11
 
9
12
  def create_flows
10
- add_flow_from_usage("<name> <rdata> <ttl>")
13
+ add_flow_from_usage("<gname> [<ttl>='300']", :add_group_cond)
14
+ add_flow_from_usage("<name> <rdata> <ttl>", :add_record_cond)
15
+ add_flow_from_usage("<weight> <rdata>", :add_group_record_cond, 'LoadBalancing')
16
+ add_flow_from_usage("<is-primary> <rdata>", :add_group_record_cond, 'Failover')
11
17
  end
12
18
 
13
- def handle_level(level)
19
+ def add_group_record_cond(group_type='')
20
+ level = @input["level"]
21
+ levels = level.split('.')
22
+ if (levels.length == 4 && levels[1].start_with?(group_type) && levels[2] == 'Group')
23
+ nil
24
+ else
25
+ "invalid drill down level (#{level}) for adding record to a group"
26
+ end
27
+ end
28
+
29
+ def add_record_cond
30
+ level = @input["level"]
14
31
  levels = level.split('.')
15
- if levels.length == 3 && levels[1] == 'Records'
16
- rtype = levels[2]
17
- struct = @input["struct"]
18
- struct << @record
19
- StructurePrint.new("-").structure_print(struct, level)
32
+ if (levels[1] == 'Records' && levels.length == 3)
33
+ nil
20
34
  else
21
- raise "Illegal or unimplemented add location"
35
+ "invalid drill down level (#{level}) for adding record"
22
36
  end
23
37
  end
24
38
 
39
+ def add_group_cond
40
+ level = @input["level"]
41
+ if (level == 'zone.LoadBalancingGroups' || level == 'zone.FailoverGroups')
42
+ nil
43
+ else
44
+ "invalid drill down level (#{level}) for adding load balancing group or failover group"
45
+ end
46
+ end
47
+
48
+ def add_at_level(struct, level, arghash)
49
+ if add_record_cond.nil?
50
+ element = { "Name" => arghash["name"], "Rdata" => arghash["rdata"], "TTL" => arghash["ttl"].to_i }
51
+ elsif add_group_cond.nil?
52
+ element = { "Group" => { "A" => [ ], "AAAA" => [ ], "CNAME" => [ ] }, "GroupTypeId" => 3, "Name" => arghash["gname"], "TTL" => arghash["ttl"] }
53
+ elsif add_group_record_cond.nil?
54
+ puts "level = #{level}"
55
+ key =
56
+ if arghash["weight"]
57
+ "LoadBalancingGroups"
58
+ elsif arghash["is-primary"]
59
+ "FailoverGroups"
60
+ end
61
+ groups = @zone_struct[key]
62
+ re = /(LoadBalancingGroups|FailoverGroups)\[([^\]]+)\]/
63
+ index = re.match(level)[2].to_i
64
+ index -= 1
65
+ element = {
66
+ "HealthCheck" => nil,
67
+ }
68
+ if arghash["weight"]
69
+ element["Weight"] = arghash["weight"].to_i
70
+ elsif arghash["is-primary"]
71
+ element["IsPrimary"] = (arghash["is-primary"] == "true")
72
+ end
73
+ element["Rdata"] = arghash["rdata"]
74
+ else
75
+ raise "should not happen"
76
+ end
77
+ struct << element
78
+ StructurePrint.new("-").structure_print(struct, level)
79
+ end
80
+
25
81
  def execute(arghash, rest)
26
82
  struct = @input["struct"]
27
83
  level = @input["level"]
28
- @zone_struct = @input["toplevel"]
29
84
  zone = @input["zone"]
30
-
31
- @record = { "Name" => arghash["name"], "Rdata" => arghash["rdata"], "TTL" => arghash["ttl"].to_i }
32
- handle_level(level)
33
- zone.write_zone_file(@zone_struct)
34
-
85
+ @zone_struct = @input["toplevel"]
86
+ add_at_level(struct, level, arghash)
87
+ zone.write_zone_file(@zone_struct, false)
35
88
  end
36
89
  end
@@ -0,0 +1,51 @@
1
+ require_relative 'util'
2
+
3
+ class ZoneDelete < Command
4
+ def create_args
5
+ add_arg('index','index of the item to be deleted.', /[[:digit:]]+/)
6
+ end
7
+
8
+ def create_flows
9
+ add_flow_from_usage("[<index>]", :verify_drill_down)
10
+ end
11
+
12
+ def verify_drill_down
13
+ @index = 0
14
+ @level = @input["level"]
15
+ if @input["rest"].class == Array
16
+ @index = @input["rest"][0].to_i
17
+ end
18
+ dputs "in verify_drill_down, level=#{@level}, rest=#{@input["rest"]}"
19
+ if @level.nil? && @index == 0
20
+ return nil
21
+ elsif @level.length > 0 && @index > 0
22
+ return nil
23
+ end
24
+ "invalid argument"
25
+ end
26
+
27
+ def execute(arghash, rest)
28
+ @index = arghash["index"].to_i
29
+ struct = @input["struct"]
30
+ if struct.nil?
31
+ zone = @input["zone"]
32
+ zone.delete
33
+ elsif struct.class == Array
34
+ if struct.length >= @index
35
+ struct.delete_at @index-1
36
+ else
37
+ raise "invalid index"
38
+ end
39
+ zone = @input["zone"]
40
+ zone.write_zone_file(@input["toplevel"], false)
41
+ StructurePrint.new("-").structure_print(struct, "")
42
+ else
43
+ raise "only elements from array can be deleted"
44
+ end
45
+ end
46
+
47
+
48
+
49
+
50
+
51
+ end
@@ -0,0 +1,78 @@
1
+ class ZoneSetHealthCheck < Command
2
+ def create_args
3
+ add_arg('http-type', 'for HTTP or secure HTTP health checks', ['HTTP', 'HTTPs'])
4
+ add_arg('uri', 'URI to which health checks will be directed', /.*/)
5
+ add_arg('ip-version', 'IP version', "ip_versions")
6
+ add_arg('check-interval', 'number of seconds between health checks', /\d+/)
7
+ add_arg('fail-threshold', 'number of consecutive succeeds/fails for status change (1-10)', /([1-9]|10)/)
8
+ add_arg('email-address', 'email address to which notifications will be sent', /.*/)
9
+ add_arg('http-method', 'HTTP method for health check', 'http_methods')
10
+ add_arg('content-verification', 'text that will be used to verify health check', /.*/)
11
+ add_arg('reintegration-method', 'how and unhealthy server/domain will be integrated back', 'hc_rm')
12
+ add_arg('tcp-type', 'for TCP or TCP SSL health checks', ['TCP Open', 'TCP SSL'])
13
+ add_arg('ip-address', 'ip address to which TCP health checks will be directed (IPv4 or IPv6)', /[\d:\.]+/)
14
+ add_arg('port', 'ip port to which TCP health checks will be directed (1-65535)', /\d+/)
15
+ end
16
+
17
+ def create_flows
18
+ add_flow_from_usage("<http-type> <uri> <ip-version> <check-interval> <fail-threshold> <email-address> [<http-method>='GET'] [<content-verification>] [<reintegration-method>='Automatic']", :add_hc_cond)
19
+ add_flow_from_usage("<tcp-type> <ip-address> <port> <check-interval> <fail-threshold> <email-address> [<content-verification>] [<reintegration-method>='Automatic']", :add_hc_cond)
20
+ end
21
+
22
+ def add_hc_cond
23
+ struct = @input['struct']
24
+ if struct.has_key? 'HealthCheck'
25
+ nil
26
+ else
27
+ "invalid drill down level (#{level}) for setting health check"
28
+ end
29
+ end
30
+
31
+ def execute(arghash, rest)
32
+ struct = @input['struct']
33
+ level = @input["level"]
34
+ zone = @input['zone']
35
+ @zone_struct = @input["toplevel"]
36
+ http_type = arghash['http-type']
37
+ if http_type
38
+ content_verification = arghash['content-verification']
39
+ if content_verification.nil?
40
+ content_verification = ''
41
+ end
42
+ hc = {
43
+ 'CheckInterval' => arghash['check-interval'].to_i,
44
+ 'CheckTypeId' => arghash['http-type'],
45
+ 'ContentVerification' => content_verification,
46
+ 'EmailNotificationAddress' => arghash['email-address'],
47
+ 'FailedCheckThreshold' => arghash['fail-threshold'].to_i,
48
+ 'HTTPMethodId' => arghash['http-method'],
49
+ 'IPAddress' => '',
50
+ 'IPVersion' => arghash['ip-version'],
51
+ 'PortNumber' => nil,
52
+ 'ReintegrationMethodId' => arghash['reintegration-method'],
53
+ 'Status' => 0,
54
+ 'StatusName' => '',
55
+ 'Uri' => arghash['uri']
56
+ }
57
+ else
58
+ hc = {
59
+ 'CheckInterval' => arghash['check-interval'].to_i,
60
+ 'CheckTypeId' => arghash['tcp-type'],
61
+ 'ContentVerification' => content_verification,
62
+ 'EmailNotificationAddress' => arghash['email-address'],
63
+ 'FailedCheckThreshold' => arghash['fail-threshold'].to_i,
64
+ 'HTTPMethodId' => nil,
65
+ 'IPAddress' => arghash['ip-address'],
66
+ 'IPVersion' => nil,
67
+ 'PortNumber' => arghash['port'].to_i,
68
+ 'ReintegrationMethodId' => arghash['reintegration-method'],
69
+ 'Status' => 0,
70
+ 'StatusName' => '',
71
+ 'Uri' => ''
72
+ }
73
+ end
74
+ struct['HealthCheck'] = hc
75
+ StructurePrint.new("-").structure_print(struct['HealthCheck'], level+'.HealthCheck')
76
+ zone.write_zone_file(@zone_struct)
77
+ end
78
+ end
@@ -0,0 +1,60 @@
1
+ require_relative 'util'
2
+
3
+ class ZoneUpdate < Command
4
+ def create_args
5
+ add_arg('name-value','of the form name:new-value, where name is the (abbreviated) name of field', /[[:alpha:]]+:.*/)
6
+ end
7
+
8
+ def create_flows
9
+ add_flow_from_usage("<name-value>...")
10
+ end
11
+
12
+ def boolean_value_of(s)
13
+ if s == 'true'
14
+ true
15
+ elsif s == 'false'
16
+ false
17
+ else
18
+ raise "illegal value of boolean:#{s}"
19
+ end
20
+ end
21
+
22
+ def update_struct(struct, key, value)
23
+ name = Util.match_key(key, struct)
24
+ if name.nil?
25
+ raise "no (unique) key matches" + key
26
+ end
27
+ target_type = struct[name].class
28
+ case [target_type]
29
+ when [Fixnum]
30
+ value = value.to_i
31
+ when [TrueClass]
32
+ value = boolean_value_of(value)
33
+ when [FalseClass]
34
+ value = boolean_value_of(value)
35
+ when [String]
36
+ else
37
+ raise "cannot change item of type #{target_type}"
38
+ end
39
+ struct[name] = value
40
+ zone = @input["zone"]
41
+ zone.write_zone_file(@input["toplevel"], false)
42
+ StructurePrint.new("-").structure_print(struct, "")
43
+ end
44
+
45
+ def execute(arghash, rest)
46
+ nvarray = arghash["name-value"]
47
+ struct = @input["struct"]
48
+ if struct.class == Hash
49
+ nvarray.each { | nv |
50
+ name, value = Util.parse_line(nv,':')
51
+ update_struct(struct, name, value)
52
+ }
53
+ elsif struct.class == Array
54
+ raise "can only update single item" if struct.length > 1
55
+ update_struct(struct[0], name, value)
56
+ else
57
+ raise "can't update at this level"
58
+ end
59
+ end
60
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vzcdn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Preston
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-04-22 00:00:00.000000000 Z
13
+ date: 2014-05-02 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rest-client
@@ -79,6 +79,7 @@ files:
79
79
  - lib/common.rb
80
80
  - lib/config_handler.rb
81
81
  - lib/config_reader.rb
82
+ - lib/diff.rb
82
83
  - lib/mediaManagment.rb
83
84
  - lib/method.rb
84
85
  - lib/mkbind.sh
@@ -96,6 +97,9 @@ files:
96
97
  - lib/vzcdn/version.rb
97
98
  - lib/zone.rb
98
99
  - lib/zone_add.rb
100
+ - lib/zone_delete.rb
101
+ - lib/zone_hc.rb
102
+ - lib/zone_update.rb
99
103
  - pkg/vzcdn-0.0.1.gem
100
104
  - test/test_all.rb
101
105
  - test/test_clui.rb