Class: Bosh::Director::Api::PropertyManager

Inherits:
Object
  • Object
show all
Defined in:
lib/bosh/director/api/property_manager.rb

Instance Method Summary collapse

Constructor Details

#initializePropertyManager

Returns a new instance of PropertyManager.



7
8
9
# File 'lib/bosh/director/api/property_manager.rb', line 7

def initialize
  @deployment_manager = DeploymentManager.new
end

Instance Method Details

#create_property(deployment_name, property_name, value) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/bosh/director/api/property_manager.rb', line 11

def create_property(deployment_name, property_name, value)
  property = Models::DeploymentProperty.new
  property.deployment = find_deployment(deployment_name)
  property.name = property_name
  property.value = value
  property.save

rescue Sequel::ValidationFailed => e
  if 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_name, property_name) ⇒ Object



36
37
38
# File 'lib/bosh/director/api/property_manager.rb', line 36

def delete_property(deployment_name, property_name)
  get_property(deployment_name, property_name).destroy
end

#get_properties(deployment_name) ⇒ Object



52
53
54
55
# File 'lib/bosh/director/api/property_manager.rb', line 52

def get_properties(deployment_name)
  filters = {:deployment_id => find_deployment(deployment_name).id}
  Models::DeploymentProperty.filter(filters).all
end

#get_property(deployment_name, property_name) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/bosh/director/api/property_manager.rb', line 40

def get_property(deployment_name, property_name)
  deployment = find_deployment(deployment_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_name, property_name, value) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/bosh/director/api/property_manager.rb', line 27

def update_property(deployment_name, property_name, value)
  property = get_property(deployment_name, property_name)
  property.value = value
  property.save

rescue Sequel::ValidationFailed => e
  invalid_property(e.errors)
end