knife-cloudstack-fog 0.5.0 → 0.5.1

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,147 +1,147 @@
1
- # Author:: Jeff Moody (<jmoody@datapipe.com>)
2
- # Copyright:: Copyright (c) 2013 Datapipe
3
- # License:: Apache License, Version 2.0
4
- #
5
- # Licensed under the Apache License, Version 2.0 (the "License");
6
- # you may not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS,
13
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- # See the License for the specific language governing permissions and
15
- # limitations under the License.
16
- #
17
-
18
-
19
- require 'chef/knife/cloudstack_base'
20
-
21
- class Chef
22
- class Knife
23
- class CloudstackNetworkCreate < Knife
24
-
25
- include Knife::CloudstackBase
26
-
27
- banner "knife cloudstack network create -n NAME -o NETWORKOFFERINGID -z ZONE (options)"
28
-
29
- option :name,
30
- :short => "-n NAME",
31
- :long => "--name NAME",
32
- :description => "The name of the network to create."
33
-
34
- option :networkoffering,
35
- :short => "-o NETWORKOFFERINGID",
36
- :long => "--networkoffering NETWORKOFFERINGID",
37
- :description => "The network service offering ID to use."
38
-
39
- option :zone,
40
- :short => "-z ZONE",
41
- :long => "--zone ZONE",
42
- :description => "The zone to create the network in."
43
-
44
- option :startip,
45
- :short => "-s STARTIP",
46
- :long => "--startip STARTIP",
47
- :description => "The starting IP for the network."
48
-
49
- option :endip,
50
- :short => "-e ENDIP",
51
- :long => "--endip ENDIP",
52
- :description => "The ending IP for the network."
53
-
54
- option :netmask,
55
- :short => "-m NETMASK",
56
- :long => "--netmask NETMASK",
57
- :description => "The netmask for the network."
58
-
59
- option :gateway,
60
- :short => "-g GATEWAY",
61
- :long => "--gateway GATEWAY",
62
- :description => "The gateway for the network."
63
-
64
- option :vlan,
65
- :short => "-l VLANID",
66
- :long => "--vlan VLANID",
67
- :description => "The VLAN for the network."
68
-
69
- option :displaytext,
70
- :short => "-i DISPLAYTEXT",
71
- :long => "--displaytext DISPLAYTEXT",
72
- :description => "The display name of the network, if different than the name."
73
-
74
-
75
- def run
76
- $stdout.sync = true
77
-
78
- validate!
79
-
80
- netoptions = {}
81
-
82
- if (locate_config_value(:name).nil? || locate_config_value(:networkoffering).nil? || locate_config_value(:zone).nil?)
83
- puts "Name (-n), Service Offering ID (-o), and Zone ID (-z) are required."
84
- else
85
- netoptions['name'] = locate_config_value(:name)
86
- netoptions['networkofferingid'] = locate_config_value(:networkoffering)
87
- netoptions['zoneid'] = locate_config_value(:zone)
88
-
89
- if locate_config_value(:startip) != nil
90
- netoptions['startip'] = locate_config_value(:startip)
91
- end
92
-
93
- if locate_config_value(:endip) != nil
94
- netoptions['endip'] = locate_config_value(:endip)
95
- end
96
-
97
- if locate_config_value(:netmask) != nil
98
- netoptions['netmask'] = locate_config_value(:netmask)
99
- end
100
-
101
- if locate_config_value(:gateway) != nil
102
- netoptions['gateway'] = locate_config_value(:gateway)
103
- end
104
-
105
- if locate_config_value(:vlan) != nil
106
- netoptions['vlan'] = locate_config_value(:vlan)
107
- end
108
-
109
- if locate_config_value(:displaytext) != nil
110
- netoptions['displaytext'] = locate_config_value(:displaytext)
111
- else
112
- netoptions['displaytext'] = locate_config_value(:name)
113
- end
114
-
115
- Chef::Log.debug("Options: #{netoptions}")
116
-
117
- response = connection.create_network(netoptions)
118
-
119
- Chef::Log.debug("API Response: #{response}")
120
-
121
- network_list = [
122
- ui.color('ID', :bold),
123
- ui.color('Name', :bold),
124
- ui.color('Display Text', :bold),
125
- ui.color('Zone ID', :bold),
126
- ui.color('VLAN', :bold),
127
- ui.color('State', :bold)
128
- ]
129
-
130
- newnetwork = response['createnetworkresponse']['network']
131
-
132
- network_list << newnetwork['id'].to_s
133
- network_list << newnetwork['name'].to_s
134
- network_list << newnetwork['displaytext'].to_s
135
- network_list << newnetwork['zoneid'].to_s
136
- network_list << newnetwork['vlan'].to_s
137
- network_list << newnetwork['state'].to_s
138
-
139
- puts ui.list(network_list, :columns_across, 6)
140
-
141
- end
142
-
143
- end
144
-
145
- end
146
- end
147
- end
1
+ # Author:: Jeff Moody (<jmoody@datapipe.com>)
2
+ # Copyright:: Copyright (c) 2013 Datapipe
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+
19
+ require 'chef/knife/cloudstack_base'
20
+
21
+ class Chef
22
+ class Knife
23
+ class CloudstackNetworkCreate < Knife
24
+
25
+ include Knife::CloudstackBase
26
+
27
+ banner "knife cloudstack network create -n NAME -o NETWORKOFFERINGID -z ZONE (options)"
28
+
29
+ option :name,
30
+ :short => "-n NAME",
31
+ :long => "--name NAME",
32
+ :description => "The name of the network to create."
33
+
34
+ option :networkoffering,
35
+ :short => "-o NETWORKOFFERINGID",
36
+ :long => "--networkoffering NETWORKOFFERINGID",
37
+ :description => "The network service offering ID to use."
38
+
39
+ option :zone,
40
+ :short => "-z ZONE",
41
+ :long => "--zone ZONE",
42
+ :description => "The zone to create the network in."
43
+
44
+ option :startip,
45
+ :short => "-s STARTIP",
46
+ :long => "--startip STARTIP",
47
+ :description => "The starting IP for the network."
48
+
49
+ option :endip,
50
+ :short => "-e ENDIP",
51
+ :long => "--endip ENDIP",
52
+ :description => "The ending IP for the network."
53
+
54
+ option :netmask,
55
+ :short => "-m NETMASK",
56
+ :long => "--netmask NETMASK",
57
+ :description => "The netmask for the network."
58
+
59
+ option :gateway,
60
+ :short => "-g GATEWAY",
61
+ :long => "--gateway GATEWAY",
62
+ :description => "The gateway for the network."
63
+
64
+ option :vlan,
65
+ :short => "-l VLANID",
66
+ :long => "--vlan VLANID",
67
+ :description => "The VLAN for the network."
68
+
69
+ option :displaytext,
70
+ :short => "-i DISPLAYTEXT",
71
+ :long => "--displaytext DISPLAYTEXT",
72
+ :description => "The display name of the network, if different than the name."
73
+
74
+
75
+ def run
76
+ $stdout.sync = true
77
+
78
+ validate!
79
+
80
+ netoptions = {}
81
+
82
+ if (locate_config_value(:name).nil? || locate_config_value(:networkoffering).nil? || locate_config_value(:zone).nil?)
83
+ puts "Name (-n), Service Offering ID (-o), and Zone ID (-z) are required."
84
+ else
85
+ netoptions['name'] = locate_config_value(:name)
86
+ netoptions['networkofferingid'] = locate_config_value(:networkoffering)
87
+ netoptions['zoneid'] = locate_config_value(:zone)
88
+
89
+ if locate_config_value(:startip) != nil
90
+ netoptions['startip'] = locate_config_value(:startip)
91
+ end
92
+
93
+ if locate_config_value(:endip) != nil
94
+ netoptions['endip'] = locate_config_value(:endip)
95
+ end
96
+
97
+ if locate_config_value(:netmask) != nil
98
+ netoptions['netmask'] = locate_config_value(:netmask)
99
+ end
100
+
101
+ if locate_config_value(:gateway) != nil
102
+ netoptions['gateway'] = locate_config_value(:gateway)
103
+ end
104
+
105
+ if locate_config_value(:vlan) != nil
106
+ netoptions['vlan'] = locate_config_value(:vlan)
107
+ end
108
+
109
+ if locate_config_value(:displaytext) != nil
110
+ netoptions['displaytext'] = locate_config_value(:displaytext)
111
+ else
112
+ netoptions['displaytext'] = locate_config_value(:name)
113
+ end
114
+
115
+ Chef::Log.debug("Options: #{netoptions}")
116
+
117
+ response = connection.create_network(netoptions)
118
+
119
+ Chef::Log.debug("API Response: #{response}")
120
+
121
+ network_list = [
122
+ ui.color('ID', :bold),
123
+ ui.color('Name', :bold),
124
+ ui.color('Display Text', :bold),
125
+ ui.color('Zone ID', :bold),
126
+ ui.color('VLAN', :bold),
127
+ ui.color('State', :bold)
128
+ ]
129
+
130
+ newnetwork = response['createnetworkresponse']['network']
131
+
132
+ network_list << newnetwork['id'].to_s
133
+ network_list << newnetwork['name'].to_s
134
+ network_list << newnetwork['displaytext'].to_s
135
+ network_list << newnetwork['zoneid'].to_s
136
+ network_list << newnetwork['vlan'].to_s
137
+ network_list << newnetwork['state'].to_s
138
+
139
+ puts ui.list(network_list, :columns_across, 6)
140
+
141
+ end
142
+
143
+ end
144
+
145
+ end
146
+ end
147
+ end
@@ -1,53 +1,53 @@
1
- # Author:: Jeff Moody (<jmoody@datapipe.com>)
2
- # Copyright:: Copyright (c) 2013 Datapipe
3
- # License:: Apache License, Version 2.0
4
- #
5
- # Licensed under the Apache License, Version 2.0 (the "License");
6
- # you may not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS,
13
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- # See the License for the specific language governing permissions and
15
- # limitations under the License.
16
- #
17
-
18
-
19
- require 'chef/knife/cloudstack_base'
20
-
21
- class Chef
22
- class Knife
23
- class CloudstackNetworkDelete < Knife
24
-
25
- include Knife::CloudstackBase
26
-
27
- banner "knife cloudstack network delete ID"
28
-
29
-
30
- def run
31
- if @name_args.nil? || @name_args.empty?
32
- puts "#{ui.color("Please provide a network ID.", :red)}"
33
- end
34
-
35
- @name_args.each do |network_id|
36
- response = connection.list_networks('id' => network_id)
37
-
38
- apiresponse = response['listnetworksresponse']
39
- network = apiresponse['network']
40
- Chef::Log.debug("Network: #{network}")
41
- network_name = network[0]['name'].to_s
42
- network_display = network[0]['displaytext'].to_s
43
- puts "#{ui.color("Name", :red)}: #{network_name}"
44
- puts "#{ui.color("Display Text", :red)}: #{network_display}"
45
- puts "\n"
46
- confirm("#{ui.color("Do you really want to delete this network?", :red)}")
47
- connection.delete_network(network_id)
48
- ui.warn("Deleted network #{network_name}")
49
- end
50
- end
51
- end
52
- end
53
- end
1
+ # Author:: Jeff Moody (<jmoody@datapipe.com>)
2
+ # Copyright:: Copyright (c) 2013 Datapipe
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+
19
+ require 'chef/knife/cloudstack_base'
20
+
21
+ class Chef
22
+ class Knife
23
+ class CloudstackNetworkDelete < Knife
24
+
25
+ include Knife::CloudstackBase
26
+
27
+ banner "knife cloudstack network delete ID"
28
+
29
+
30
+ def run
31
+ if @name_args.nil? || @name_args.empty?
32
+ puts "#{ui.color("Please provide a network ID.", :red)}"
33
+ end
34
+
35
+ @name_args.each do |network_id|
36
+ response = connection.list_networks('id' => network_id)
37
+
38
+ apiresponse = response['listnetworksresponse']
39
+ network = apiresponse['network']
40
+ Chef::Log.debug("Network: #{network}")
41
+ network_name = network[0]['name'].to_s
42
+ network_display = network[0]['displaytext'].to_s
43
+ puts "#{ui.color("Name", :red)}: #{network_name}"
44
+ puts "#{ui.color("Display Text", :red)}: #{network_display}"
45
+ puts "\n"
46
+ confirm("#{ui.color("Do you really want to delete this network?", :red)}")
47
+ connection.delete_network(network_id)
48
+ ui.warn("Deleted network #{network_name}")
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -1,67 +1,67 @@
1
- # Author:: Jeff Moody (<jmoody@datapipe.com>)
2
- # Copyright:: Copyright (c) 2012 Datapipe
3
- # License:: Apache License, Version 2.0
4
- #
5
- # Licensed under the Apache License, Version 2.0 (the "License");
6
- # you may not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS,
13
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- # See the License for the specific language governing permissions and
15
- # limitations under the License.
16
- #
17
-
18
-
19
- require 'chef/knife/cloudstack_base'
20
-
21
- class Chef
22
- class Knife
23
- class CloudstackNetworkList < Knife
24
-
25
- include Knife::CloudstackBase
26
-
27
- banner "knife cloudstack network list"
28
-
29
- def run
30
- $stdout.sync = true
31
-
32
- validate!
33
-
34
- network_list = [
35
- ui.color('ID', :bold),
36
- ui.color('Name', :bold),
37
- ui.color('Zone ID', :bold),
38
- ui.color('VLAN', :bold),
39
- ui.color('State', :bold)
40
- ]
41
- response = connection.list_networks['listnetworksresponse']
42
- if networks = response['network']
43
- networks.each do |network|
44
- network_list << network['id'].to_s
45
- network_list << network['name'].to_s
46
- network_list << network['zoneid'].to_s
47
- network_list << network['vlan'].to_s
48
- network_list << begin
49
- state = network['state'].to_s.downcase
50
- case state
51
- when 'allocated'
52
- ui.color(state, :red)
53
- when 'pending'
54
- ui.color(state, :yellow)
55
- else
56
- ui.color(state, :green)
57
- end
58
- end
59
- end
60
- end
61
- puts ui.list(network_list, :columns_across, 5)
62
-
63
- end
64
-
65
- end
66
- end
67
- end
1
+ # Author:: Jeff Moody (<jmoody@datapipe.com>)
2
+ # Copyright:: Copyright (c) 2012 Datapipe
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+
19
+ require 'chef/knife/cloudstack_base'
20
+
21
+ class Chef
22
+ class Knife
23
+ class CloudstackNetworkList < Knife
24
+
25
+ include Knife::CloudstackBase
26
+
27
+ banner "knife cloudstack network list"
28
+
29
+ def run
30
+ $stdout.sync = true
31
+
32
+ validate!
33
+
34
+ network_list = [
35
+ ui.color('ID', :bold),
36
+ ui.color('Name', :bold),
37
+ ui.color('Zone ID', :bold),
38
+ ui.color('VLAN', :bold),
39
+ ui.color('State', :bold)
40
+ ]
41
+ response = connection.list_networks['listnetworksresponse']
42
+ if networks = response['network']
43
+ networks.each do |network|
44
+ network_list << network['id'].to_s
45
+ network_list << network['name'].to_s
46
+ network_list << network['zoneid'].to_s
47
+ network_list << network['vlan'].to_s
48
+ network_list << begin
49
+ state = network['state'].to_s.downcase
50
+ case state
51
+ when 'allocated'
52
+ ui.color(state, :red)
53
+ when 'pending'
54
+ ui.color(state, :yellow)
55
+ else
56
+ ui.color(state, :green)
57
+ end
58
+ end
59
+ end
60
+ end
61
+ puts ui.list(network_list, :columns_across, 5)
62
+
63
+ end
64
+
65
+ end
66
+ end
67
+ end