Class: Bosh::Director::Api::PropertyManager
- Defined in:
- lib/bosh/director/api/property_manager.rb
Instance Method Summary collapse
- #create_property(deployment, property_name, value) ⇒ Object
- #delete_property(deployment, property_name) ⇒ Object
- #get_properties(deployment) ⇒ Object
- #get_property(deployment, property_name) ⇒ Object
- #update_property(deployment, property_name, value) ⇒ Object
Instance Method Details
#create_property(deployment, property_name, value) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/bosh/director/api/property_manager.rb', line 7 def create_property(deployment, property_name, value) property = Models::DeploymentProperty.new property.deployment = deployment property.name = property_name property.value = value property.save rescue Sequel::ValidationFailed => e if e.errors[[:name, :deployment_id]] && e.errors[[:name, :deployment_id]].include?(:unique) raise PropertyAlreadyExists, "Property '#{property_name}' already exists " + "for deployment '#{deployment.name}'" end invalid_property(e.errors) end |
#delete_property(deployment, property_name) ⇒ Object
33 34 35 |
# File 'lib/bosh/director/api/property_manager.rb', line 33 def delete_property(deployment, property_name) get_property(deployment, property_name).destroy end |
#get_properties(deployment) ⇒ Object
48 49 50 51 |
# File 'lib/bosh/director/api/property_manager.rb', line 48 def get_properties(deployment) filters = {:deployment_id => deployment.id} Models::DeploymentProperty.filter(filters).all end |
#get_property(deployment, property_name) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/bosh/director/api/property_manager.rb', line 37 def get_property(deployment, property_name) filters = {:deployment_id => deployment.id, :name => property_name} property = Models::DeploymentProperty.find(filters) if property.nil? raise PropertyNotFound, "Property '#{property_name}' not found " + "for deployment '#{deployment.name}'" end property end |
#update_property(deployment, property_name, value) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/bosh/director/api/property_manager.rb', line 24 def update_property(deployment, property_name, value) property = get_property(deployment, property_name) property.value = value property.save rescue Sequel::ValidationFailed => e invalid_property(e.errors) end |