Class: Bosh::Director::DeploymentPlan::DeploymentRepo

Inherits:
Object
  • Object
show all
Defined in:
lib/bosh/director/deployment_plan/deployment_repo.rb

Instance Method Summary collapse

Instance Method Details

#find_or_create_by_name(name, options = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/bosh/director/deployment_plan/deployment_repo.rb', line 5

def find_or_create_by_name(name, options={})
  attributes = {name: name}
  deployment = Bosh::Director::Models::Deployment.find(attributes)

  if deployment and deployment.name != name
    # mysql database is case-insensitive by default, so we might have a
    # deployment which doesn't exactly match the requested name
    deployment = nil
  end

  return deployment if deployment

  if options['scopes']
    team_scopes = Bosh::Director::Models::Team.transform_admin_team_scope_to_teams(options['scopes'])
    attributes.merge!(teams: team_scopes)
  end

  create_for_attributes(attributes)
end