Class: LdsCfPlugin::ServiceManagerService

Inherits:
CF::CLI
  • Object
show all
Defined in:
lib/lds-cf-plugin/servicemanager_service.rb

Instance Method Summary collapse

Instance Method Details

#create_servicemanager_serviceObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/lds-cf-plugin/servicemanager_service.rb', line 25

def create_servicemanager_service
  offerings = client.services
  offerings.keep_if { |s| s.label == 'servicemanager-service' && s.provider.start_with?('ICS') && s.active }
  service = offerings.first

  if !service
    fail "Cannot find Service Manager service on #{client.target}"
  end
  
  if service.version != "0.1"
    fail "Your lds-cf-plugin version is out of date.  To update execute `gem update lds-cf-plugin`"
  end

  rest_client = CFoundry::RestClient.new(service.url, client.token)
  rest_client.trace = client.trace

  instance_name = input[:name]
  if !instance_name
    instance_name = ask("Name")
  end

  sm_app_name = input[:sm_app_name]
  if !sm_app_name
    sm_app_name = ask("Service Manager App Name")
  end

  plan = service.service_plans.first

  choices = ["Development","Functional Test", "Staging", "Stage Load","User Acceptance","BETA","Production"]
  
  env = input[:env]
  if !env || !choices.include?(env)
    options = {
      :choices => choices,
      :display => proc { |choice|
        if choice == "Development"
          "Development"
        elsif choice == "Functional Test"
          "Functional Test"
        elsif choice == "Staging"
          "Staging"
        elsif choice == "User Acceptance"
          "User Acceptance"
        elsif choice == "Stage Load"
          "Stage Load"
        elsif choice == "Production"
          "Production"
        elsif choice == "BETA"
          "Beta"
        end
      },
      :default => "Development",
      :allow_other => false
    }
    env = ask("Service Manager environment to use", options)
  end

  prexisting = input[:prexisting]
  prexisting = ask("Use existing Service Manager CI for '#{sm_app_name} - #{env}'?", :default => true) if !prexisting

  if prexisting 
  payload = {
      :space_guid => client.current_space.guid,
      :name => instance_name,
      :smApp => sm_app_name,
      :Environment => env,
      :prexisting => true
  }
 
  else 

  dutyPhone = input[:dutyPhone]
  if !dutyPhone
    dutyPhone = ask("Duty Phone (e.g. 1 801 555 5555)")
  end

  primaryContact = input[:primaryContact]
  if !primaryContact
    primaryContact = ask("Primary Contact (LDS Account)")
  end

  solutionManager = input[:solutionManager]
  if !solutionManager
    solutionManager = ask("Solution Manager (LDS Account)")
  end

  supportGroup = input[:supportGroup]
  if !supportGroup
    supportGroup = ask("Support Group (e.g. CHQ-OPS-SOMEGROUP)")
  end


  portfolioId = input[:portfolioId]
  if !portfolioId
    portfolioId = ask("Portfolio ID (e.g. 1234567)")
  end

  payload = {
      :space_guid => client.current_space.guid,
      :name => instance_name,
      :smApp => sm_app_name,
      :PrimaryContact => primaryContact,
      :PrimarySupportGroup => supportGroup,
      :Subtype2 => "CloudFoundryApp",
      :Environment => env,
      :Dept => "ICS Info And Comm Systems Dept [ICS]",
      :DataClassification => "Internal Use",
      :ChangeApprover => solutionManager,
      :CriticalityClassification => "Low",
      :DutyPhone => dutyPhone,
      :SolutionManager => solutionManager,
      :SupportContactName => "Support User",
      :SuuportContactReason => "Primary Contact",
      :PortfolioId => portfolioId,
      :RegStandards => "None",
      :SystemRiskLevel => "Low Risk",
      :prexisting => false
  }
  end 

  options = {
      :payload => JSON.generate(payload)
  }
  with_progress("Registering service ...") do
    request, response = rest_client.request("POST", "/register", options)
    if response[:status].to_i != 200
      fail "Error registering Service Manager app with gateway:\n#{response[:body]}"
      fail "Try creating your service using the web ui instead.  It does a better job of validating parameters: https://ui.cf.lds.org/#/ServiceMarketplace"
    end
  end

  # Create service instance
  instance = client.managed_service_instance
  instance.name = instance_name

  instance.service_plan = plan
  instance.space = client.current_space

  with_progress("Creating service #{c(instance.name, :name)}") do
    instance.create!
  end

  instance
end

#preconditionObject



6
7
8
# File 'lib/lds-cf-plugin/servicemanager_service.rb', line 6

def precondition
  check_target
end