lib/providers/hpcloud/security_groups.rb in lorj-0.2.0 vs lib/providers/hpcloud/security_groups.rb in lorj-1.0.0

- old
+ new

@@ -12,56 +12,57 @@ # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +# HPCloud security groups module HPSecurityGroups - def HPSecurityGroups.query_sg(oNetworkConnect, sQuery) - oNetworkConnect.security_groups.all(sQuery) - end + def self.query_sg(oNetworkConnect, sQuery) + oNetworkConnect.security_groups.all(sQuery) + end - def HPSecurityGroups.create_sg(oNetwork, name, description) - params = {:name => name} - params[:description] = description if description - oNetwork.security_groups.create( params ) - end + def self.create_sg(oNetwork, name, description) + params = { :name => name } + params[:description] = description if description + oNetwork.security_groups.create(params) + end - def HPSecurityGroups.create_rule(oNetwork, hData) - oNetwork.security_group_rules.create( hData ) - end + def self.create_rule(oNetwork, hData) + oNetwork.security_group_rules.create(hData) + end - def HPSecurityGroups.query_rule(oNetwork, sQuery) - oNetwork.security_group_rules.all(sQuery) - end + def self.query_rule(oNetwork, sQuery) + oNetwork.security_group_rules.all(sQuery) + end - def HPSecurityGroups.delete_rule(oNetwork, rule_id) - oNetwork.security_group_rules.get(rule_id).destroy - end + def self.delete_rule(oNetwork, rule_id) + oNetwork.security_group_rules.get(rule_id).destroy + end end +# HPCloud keypairs module HPKeyPairs - def HPKeyPairs.query_keypair(oComputeConnect, sQuery) - cKeyPairs = oComputeConnect.key_pairs.all() - aResults = [] - cKeyPairs.each { |sElem| - bSelect = true - attributes = sElem.instance_variable_get(:@attributes) - sQuery.each { | key, value | - if attributes[key] != value - bSelect = false - break - end - } - aResults.push sElem if bSelect - } - aResults - end + def self.query_keypair(oComputeConnect, sQuery) + keypairs = oComputeConnect.key_pairs.all + results = [] + keypairs.each do |sElem| + is_selected = true + attributes = sElem.instance_variable_get(:@attributes) + sQuery.each do | key, value | + if attributes[key] != value + is_selected = false + break + end + end + results.push sElem if is_selected + end + results + end - def HPKeyPairs.get_keypair(oComputeConnect, sId) - #byebug - oComputeConnect.key_pairs.get(sId) - end + def self.get_keypair(oComputeConnect, sId) + oComputeConnect.key_pairs.get(sId) + end - def HPKeyPairs.create_keypair(oComputeConnect, name, pubkey) - oComputeConnect.key_pairs.create( :name => name, :public_key => pubkey) - end + def self.create_keypair(oComputeConnect, name, pubkey) + oComputeConnect.key_pairs.create(:name => name, :public_key => pubkey) + end end