Class: Morpheus::Cli::Projects

Inherits:
Object
  • Object
show all
Includes:
CliCommand, OptionSourceHelper, ProvisioningHelper
Defined in:
lib/morpheus/cli/commands/projects_command.rb

Instance Attribute Summary

Attributes included from CliCommand

#no_prompt

Instance Method Summary collapse

Methods included from OptionSourceHelper

#find_available_user_option, #find_cloud_option, #find_group_option, #find_tenant_option, #get_available_user_options, #get_cloud_options, #get_group_options, #get_tenant_options, included, #load_option_source_data, #options_interface, #parse_cloud_id_list, #parse_group_id_list, #parse_option_source_id_list, #parse_project_id_list, #parse_tenant_id_list, #parse_user_id_list

Methods included from ProvisioningHelper

#accounts_interface, #add_perms_options, #api_client, #apps_interface, #cloud_datastores_interface, #clouds_interface, #datastores_interface, #find_app_by_id, #find_app_by_name, #find_app_by_name_or_id, #find_cloud_by_id_for_provisioning, #find_cloud_by_name_for_provisioning, #find_cloud_by_name_or_id_for_provisioning, #find_cloud_resource_pool_by_name_or_id, #find_group_by_id_for_provisioning, #find_group_by_name_for_provisioning, #find_group_by_name_or_id_for_provisioning, #find_host_by_id, #find_host_by_name, #find_host_by_name_or_id, #find_instance_by_id, #find_instance_by_name, #find_instance_by_name_or_id, #find_instance_type_by_code, #find_instance_type_by_id, #find_instance_type_by_name, #find_instance_type_by_name_or_id, #find_instance_type_layout_by_id, #find_server_by_id, #find_server_by_name, #find_server_by_name_or_id, #find_workflow_by_id, #find_workflow_by_name, #find_workflow_by_name_or_id, #format_app_status, #format_blueprint_type, #format_container_connection_string, #format_container_status, #format_instance_connection_string, #format_instance_container_display_name, #format_instance_status, #format_metadata, #format_snapshot_status, #get_available_accounts, #get_available_clouds, #get_available_environments, #get_available_groups, #get_available_plans, #get_provision_type_for_zone_type, #get_static_environments, included, #instance_type_layouts_interface, #instance_types_interface, #instances_interface, #load_balance_protocols_dropdown, #options_interface, #parse_blueprint_type, #parse_host_id_list, #parse_instance_id_list, #parse_metadata, #parse_resource_id_list, #parse_server_id_list, #print_permissions, #prompt_evars, #prompt_exposed_ports, #prompt_instance_load_balancer, #prompt_metadata, #prompt_network_interfaces, #prompt_new_instance, #prompt_permissions, #prompt_permissions_v2, #prompt_resize_volumes, #prompt_security_groups, #prompt_service_plan_options, #prompt_volumes, #provision_types_interface, #reject_service_plan_option_types, #servers_interface

Methods included from CliCommand

#add_query_parameter, #apply_options, #build_common_options, #build_get_options, #build_list_options, #build_option_type_options, #build_standard_add_many_options, #build_standard_add_options, #build_standard_api_options, #build_standard_delete_options, #build_standard_get_options, #build_standard_list_options, #build_standard_post_options, #build_standard_put_options, #build_standard_remove_options, #build_standard_update_options, #command_description, #command_name, #confirm, #confirm!, #default_refresh_interval, #default_sigdig, #default_subcommand, #establish_remote_appliance_connection, #execute_api, #execute_api_payload, #execute_api_request, #find_all, #find_all_json, #find_by_id, #find_by_name, #find_by_name_or_id, #find_record, #find_record_json, #full_command_usage, #get_interface, #get_list_key, #get_object_key, #get_subcommand_description, #handle_each_payload, #handle_subcommand, included, #interactive?, #my_help_command, #my_terminal, #my_terminal=, #parse_array, #parse_bytes_param, #parse_get_options!, #parse_id_list, #parse_labels, #parse_list_options, #parse_list_options!, #parse_list_subtitles, #parse_options, #parse_parameter_as_resource_id!, #parse_passed_options, #parse_payload, #parse_query_options, #print, #print_error, #println, #prog_name, #puts, #puts_error, #raise_args_error, #raise_command_error, #render_response, #run_command_for_each_arg, #subcommand_aliases, #subcommand_description, #subcommand_usage, #subcommands, #usage, #validate_outfile, #verify_args!, #visible_subcommands

Instance Method Details

#_get(id, options) ⇒ Object



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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/morpheus/cli/commands/projects_command.rb', line 120

def _get(id, options)
  @projects_interface.setopts(options)
  if options[:dry_run]
    if id.to_s =~ /\A\d{1,}\Z/
      print_dry_run @projects_interface.dry.get(id.to_i)
    else
      print_dry_run @projects_interface.dry.get({name: id})
    end
    return
  end
  project = options[:find_by_name] ? find_project_by_name(id) : find_project_by_name_or_id(id)
  return 1, "project not found by '#{id}'" if project.nil?
  # refetch it by id
  json_response = {'project' => project}
  unless id.to_s =~ /\A\d{1,}\Z/
    json_response = @projects_interface.get(project['id'])
  end
  project = json_response['project']
  render_response(json_response, options, 'project') do
    print_h1 "Project Details"
    print cyan
    description_cols = {
      "ID" => 'id',
      "Name" => 'name',
      "Description" => 'description',
      "Tags" => lambda {|it| it['tags'] ? it['tags'].collect {|m| "#{m['name']}: #{m['value']}" }.join(', ') : '' },
      "Owner" => lambda {|it| it['owner'] ? it['owner']['username'] : '' },
      "Date Created" => lambda {|it| format_local_dt(it['dateCreated']) },
      "Last Updated" => lambda {|it| format_local_dt(it['lastUpdated']) }
    }
    print_description_list(description_cols, project)
    
    project_instances = project["instances"]
    if project_instances && project_instances.size > 0
      print_h2 "Instances"
      print cyan
      print as_pretty_table(project_instances, [:id, :name], options)
    end

    project_hosts = project["servers"] || project["hosts"]
    if project_hosts && project_hosts.size > 0
      print_h2 "Hosts"
      print cyan
      print as_pretty_table(project_hosts, [:id, :name], options)
    end

    project_clouds = project["clouds"] || project["zones"]
    if project_clouds && project_clouds.size > 0
      print_h2 "Clouds"
      print cyan
      print as_pretty_table(project_clouds, [:id, :name], options)
    end

    project_resources = project["resources"] || project["accountResources"]
    if project_resources && project_resources.size > 0
      print_h2 "Resources"
      print cyan
      print as_pretty_table(project_resources, [:id, :name], options)
    end

    print reset,"\n"
  end
  return 0, nil
end

#add(args) ⇒ Object



185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
# File 'lib/morpheus/cli/commands/projects_command.rb', line 185

def add(args)
  exit_code, err = 0, nil
  params, options, payload = {}, {}, {}
  project_name, description, , instance_ids, server_ids, cloud_ids, resource_ids = nil, nil, nil, nil, nil, nil, nil
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[name]")
    opts.on('--name NAME', String, "Project Name" ) do |val|
      project_name = val
    end
    opts.on('--description NAME', String, "Project Description" ) do |val|
      description = val
    end
    opts.on('--tags TAGS', String, "Tags in the format 'name:value, name:value'") do |val|
       = val
    end
    opts.on('--instances [LIST]', Array, "Instances, comma separated list of instance names or IDs.") do |list|
      instance_ids = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
    end
    opts.on('--servers [LIST]', Array, "Servers, comma separated list of server (host) names or IDs.") do |list|
      server_ids = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
    end
    opts.on('--clouds [LIST]', Array, "Clouds, comma separated list of cloud names or IDs.") do |list|
      cloud_ids = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
    end
    opts.on('--resources [LIST]', Array, "Resources, comma separated list of resource IDs.") do |list|
      resource_ids = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
    end
    build_standard_add_options(opts, options)
    opts.footer = <<-EOT
Create a project.
[name] is required. This is the name of the new project.
EOT
  end
  optparse.parse!(args)
  verify_args!(args:args, optparse:optparse, max:1)
  if args[0]
    project_name = args[0]
  end
  connect(options)
  exit_code, err = 0, nil
  # construct payload
  if options[:payload]
    payload = options[:payload]
    payload.deep_merge!({'project' => parse_passed_options(options)})
  else
    payload['project'] = {}
    payload.deep_merge!({'project' => parse_passed_options(options)})
    payload['project']['name'] = project_name ? project_name : Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'name', 'fieldLabel' => 'Name', 'type' => 'text', 'required' => true, 'description' => 'Project Name'}], options[:options], @api_client)['name']
    payload['project']['description'] = description ? description : Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'description', 'fieldLabel' => 'Description', 'type' => 'text', 'required' => false, 'description' => 'Project Description'}], options[:options], @api_client)['description']
    # metadata tags
    if 
       = ()
      payload['project']['tags'] =  if 
    else
       = (options)
      payload['project']['tags'] =  if 
    end
    # --instances
    if instance_ids
      payload['project']['instances'] = parse_instance_id_list(instance_ids).collect { |it| {'id': it.to_i} }
    end
    # --servers
    if server_ids
      payload['project']['servers'] = parse_server_id_list(server_ids).collect { |it| {'id': it.to_i} }
    end
    # --clouds
    if cloud_ids
      payload['project']['clouds'] = parse_cloud_id_list(cloud_ids).collect { |it| {'id': it.to_i} }
    end
    # --resources
    if resource_ids
      payload['project']['resources'] = parse_resource_id_list(resource_ids).collect { |it| {'id': it.to_i} }
    end
  end
  @projects_interface.setopts(options)
  if options[:dry_run]
    print_dry_run @projects_interface.dry.create(payload)
    return
  end
  json_response = @projects_interface.create(payload)
  project = json_response['project']
  render_response(json_response, options, 'project') do
    print_green_success "Project #{project['name']} created"
    exit_code, err = get([project['id']] + (options[:remote] ? ["-r",options[:remote]] : []))
  end
  return exit_code, err
end

#connect(opts) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/morpheus/cli/commands/projects_command.rb', line 12

def connect(opts)
  @api_client = establish_remote_appliance_connection(opts)
  @projects_interface = @api_client.projects
  @instances_interface = @api_client.instances
  @servers_interface = @api_client.servers
  @clouds_interface = @api_client.clouds
end

#get(args) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/morpheus/cli/commands/projects_command.rb', line 101

def get(args)
  options = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[project]")
    build_standard_get_options(opts, options, [:find_by_name])
    opts.footer = <<-EOT
Get details about a project.
[project] is required. This is the name or id of a project.
EOT
  end
  optparse.parse!(args)
  verify_args!(args:args, optparse:optparse, min:1)
  connect(options)
  id_list = parse_id_list(args)
  return run_command_for_each_arg(id_list) do |arg|
    _get(arg, options)
  end
end

#handle(args) ⇒ Object



20
21
22
# File 'lib/morpheus/cli/commands/projects_command.rb', line 20

def handle(args)
  handle_subcommand(args)
end

#list(args) ⇒ Object



24
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
# File 'lib/morpheus/cli/commands/projects_command.rb', line 24

def list(args)
  params = {}
  options = {}
  instance_ids, server_ids, cloud_ids, resource_ids, owner_ids = nil, nil, nil, nil, nil
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage()
    opts.on('--instances [LIST]', Array, "Filter by Instance, comma separated list of instance names or IDs.") do |list|
      instance_ids = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
    end
    opts.on('--servers [LIST]', Array, "Filter by Server, comma separated list of server (host) names or IDs.") do |list|
      server_ids = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
    end
    opts.on('--clouds [LIST]', Array, "Filter by Cloud, comma separated list of cloud (zone) names or IDs.") do |list|
      cloud_ids = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
    end
    opts.on('--resources [LIST]', Array, "Filter by Resources, comma separated list of resource IDs.") do |list|
      resource_ids = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
    end
    opts.on('--owners [LIST]', Array, "Owner, comma separated list of usernames or IDs.") do |list|
      owner_ids = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
    end
    build_standard_list_options(opts, options)
    opts.footer = <<-EOT
List projects.
EOT
  end
  optparse.parse!(args)
  #verify_args!(args:args, optparse:optparse, count:0)
  connect(options)
  options[:phrase] = args.join(' ') if args.count > 0 && params[:phrase].nil? # pass args as phrase, every list command should do this
  params.merge!(parse_list_options(options))
  params['instanceId'] = parse_instance_id_list(instance_ids) if instance_ids
  # todo server and cloud, missing parse_server_id_list() too
  params['serverId'] = parse_server_id_list(server_ids) if server_ids
  params['cloudId'] = parse_cloud_id_list(cloud_ids) if cloud_ids
  params['resourceId'] = parse_resource_id_list(resource_ids) if resource_ids
  params['ownerId'] = parse_user_id_list(owner_ids) if owner_ids
  @projects_interface.setopts(options)
  if options[:dry_run]
    print_dry_run @projects_interface.dry.list(params)
    return
  end
  json_response = @projects_interface.list(params)
  projects = json_response['projects']
  render_response(json_response, options, 'projects') do
    title = "Morpheus Projects"
    subtitles = []
    subtitles += parse_list_subtitles(options)
    print_h1 title, subtitles
    if projects.empty?
      print yellow,"No projects found.",reset,"\n"
    else
      print cyan
      columns = [
        {"ID" => lambda {|it| it['id'] } },
        {"NAME" => lambda {|it| it['name'] } },
        {"DESCRIPTION" => lambda {|it| it['description'] } },
        {"INSTANCES" => lambda {|it| it['instances'].size rescue '' } },
        {"SERVERS" => lambda {|it| it['servers'].size rescue '' } },
        {"CLOUDS" => lambda {|it| it['clouds'].size rescue '' } },
        {"RESOURCES" => lambda {|it| it['resources'].size rescue '' } },
        {"OWNER" => lambda {|it| it['owner'] ? it['owner']['username'] : '' } },
        {"DATE CREATED" => lambda {|it| format_local_dt(it['dateCreated']) } },
        {"LAST UPDATED" => lambda {|it| format_local_dt(it['lastUpdated']) } },
      ]
      print as_pretty_table(projects, columns, options)
      print_results_pagination(json_response)
    end
    print reset,"\n"
  end
  if projects.empty?
    return 1, "No projects found"
  else
    return 0, nil
  end
end

#remove(args) ⇒ Object



431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
# File 'lib/morpheus/cli/commands/projects_command.rb', line 431

def remove(args)
  params = {}
  options = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[project]")
    build_standard_remove_options(opts, options, [:find_by_name])
    # opts.on( '-f', '--force', "Force Delete" ) do
    #   params[:force] = true
    # end
    opts.footer = <<-EOT
Delete a project.
[project] is required. This is the name or id of a project.
EOT
  end
  optparse.parse!(args)
  verify_args!(args:args, optparse:optparse, count:1)
  connect(options)
  exit_code, err = 0, nil
  project = options[:find_by_name] ? find_project_by_name(args[0]) : find_project_by_name_or_id(args[0])
  return 1, "project not found by '#{args[0]}'" if project.nil?
  unless options[:yes] || Morpheus::Cli::OptionTypes.confirm("Are you sure you want to delete the project #{project['name']}?")
    return 9, "aborted command"
  end
  @projects_interface.setopts(options)
  if options[:dry_run]
    print_dry_run @projects_interface.dry.destroy(project['id'], params)
    return
  end
  json_response = @projects_interface.destroy(project['id'], params)
  render_response(json_response, options) do
    print_green_success "Project #{project['name']} removed"
  end
  return exit_code, err
end

#update(args) ⇒ Object



273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
# File 'lib/morpheus/cli/commands/projects_command.rb', line 273

def update(args)
  exit_code, err = 0, nil
  params, options, payload = {}, {}, {}
  project_name, description, , ,  = nil, nil, nil, nil, nil
  instance_ids, server_ids, cloud_ids, resource_ids = nil, nil, nil, nil
  add_instance_ids, remove_instance_ids = nil, nil
  add_server_ids, remove_server_ids = nil, nil
  add_cloud_ids, remove_cloud_ids = nil, nil
  add_resource_ids, remove_resource_ids = nil, nil
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[project] [options]")
    opts.on('--name NAME', String, "Project Name" ) do |val|
      project_name = val
    end
    opts.on('--description NAME', String, "Project Description" ) do |val|
      description = val
    end
    opts.on('--tags [TAGS]', String, "Project Tags in the format 'name:value, name:value'. This replaces all project tags.") do |val|
       = val ? val : []
    end
    opts.on('--add-tags TAGS', String, "Add Project Tags in the format 'name:value, name:value'. This will add/update project tags.") do |val|
       = val
    end
    opts.on('--remove-tags TAGS', String, "Remove Project Tags in the format 'name, name:value'. This removes project tags, the :value component is optional and must match if passed.") do |val|
       = val
    end
    opts.on('--instances [LIST]', Array, "Instances, comma separated list of instance names or IDs.") do |list|
      instance_ids = list ? list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq : []
    end
    opts.on('--add-instances LIST', Array, "Add Instances, comma separated list of instance names or IDs to add.") do |list|
      add_instance_ids = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
    end
    opts.on('--remove-instances LIST', Array, "Remove Instances, comma separated list of instance names or IDs to remove.") do |list|
      remove_instance_ids = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
    end
    opts.on('--servers [LIST]', Array, "Servers, comma separated list of server (host) names or IDs.") do |list|
      server_ids = list ? list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq : []
    end
    opts.on('--add-servers LIST', Array, "Add Servers, comma separated list of server names or IDs to add.") do |list|
      add_server_ids = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
    end
    opts.on('--remove-servers LIST', Array, "Remove Servers, comma separated list of server names or IDs to remove.") do |list|
      remove_server_ids = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
    end
    opts.on('--clouds [LIST]', Array, "Clouds, comma separated list of cloud names or IDs.") do |list|
      cloud_ids = list ? list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq : []
    end
    opts.on('--add-clouds LIST', Array, "Add Clouds, comma separated list of cloud names or IDs to add.") do |list|
      add_cloud_ids = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
    end
    opts.on('--remove-clouds LIST', Array, "Remove Clouds, comma separated list of cloud names or IDs to remove.") do |list|
      remove_cloud_ids = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
    end
    opts.on('--resources [LIST]', Array, "Resources, comma separated list of resource names or IDs.") do |list|
      resource_ids = list ? list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq : []
    end
    opts.on('--add-resources LIST', Array, "Add Resources, comma separated list of resource names or IDs to add.") do |list|
      add_resource_ids = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
    end
    opts.on('--remove-resources LIST', Array, "Remove Resources, comma separated list of resource names or IDs to remove.") do |list|
      remove_resource_ids = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
    end
    build_standard_update_options(opts, options, [:find_by_name])
    opts.footer = <<-EOT
Update a project.
[project] is required. This is the name or id of a project.
EOT
  end
  optparse.parse!(args)
  verify_args!(args:args, optparse:optparse, count:1)
  connect(options)
  exit_code, err = 0, nil
  project = options[:find_by_name] ? find_project_by_name(args[0]) : find_project_by_name_or_id(args[0])
  return 1, "project not found by '#{args[0]}'" if project.nil?
  # construct payload
  if options[:payload]
    payload = options[:payload]
    payload.deep_merge!({'project' => parse_passed_options(options)})
  else
    payload['project'] = {}
    payload.deep_merge!({'project' => parse_passed_options(options)})
    payload['project']['name'] = project_name if project_name
    payload['project']['description'] = description if description
    # metadata tags
    if 
      payload['project']['tags'] = ()
    end
    if 
      payload['project']['addTags'] = ()
    end
    if 
      payload['project']['removeTags'] = ()
    end
    # --instances
    if instance_ids
      payload['project']['instances'] = parse_instance_id_list(instance_ids).collect { |it| {'id': it.to_i} }
    end
    if add_instance_ids
      payload['project']['addInstances'] = parse_instance_id_list(add_instance_ids).collect { |it| {'id': it.to_i} }
    end
    if remove_instance_ids
      payload['project']['removeInstances'] = parse_instance_id_list(remove_instance_ids).collect { |it| {'id': it.to_i} }
    end
    # --servers
    if server_ids
      payload['project']['servers'] = parse_server_id_list(server_ids).collect { |it| {'id': it.to_i} }
    end
    if add_server_ids
      payload['project']['addServers'] = parse_server_id_list(add_server_ids).collect { |it| {'id': it.to_i} }
    end
    if remove_server_ids
      payload['project']['removeServers'] = parse_server_id_list(remove_server_ids).collect { |it| {'id': it.to_i} }
    end
    # --clouds
    if cloud_ids
      cloud_ids = parse_cloud_id_list(cloud_ids)
      return 1, "clouds not found" if cloud_ids.nil?
      payload['project']['clouds'] = cloud_ids.collect { |it| {'id': it.to_i} }
    end
    if add_cloud_ids
      add_cloud_ids = parse_cloud_id_list(add_cloud_ids)
      return 1, "clouds not found" if add_cloud_ids.nil?
      payload['project']['addClouds'] = add_cloud_ids.collect { |it| {'id': it.to_i} }
    end
    if remove_cloud_ids
      remove_cloud_ids = parse_cloud_id_list(remove_cloud_ids)
      return 1, "clouds not found" if remove_cloud_ids.nil?
      payload['project']['removeClouds'] = remove_cloud_ids.collect { |it| {'id': it.to_i} }
    end
    # --resources
    if resource_ids
      payload['project']['resources'] = parse_resource_id_list(resource_ids).collect { |it| {'id': it.to_i} }
    end
    if add_resource_ids
      add_resource_ids = parse_resource_id_list(add_resource_ids)
      return 1, "resources not found" if add_resource_ids.nil?
      payload['project']['addResources'] = add_resource_ids.collect { |it| {'id': it.to_i} }
    end
    if remove_resource_ids
      remove_resource_ids = parse_resource_id_list(remove_resource_ids)
      return 1, "resources not found" if remove_resource_ids.nil?
      payload['project']['removeResources'] = remove_resource_ids.collect { |it| {'id': it.to_i} }
    end
  end
  @projects_interface.setopts(options)
  if options[:dry_run]
    print_dry_run @projects_interface.dry.update(project['id'], payload)
    return
  end
  json_response = @projects_interface.update(project['id'], payload)
  project = json_response['project']
  render_response(json_response, options, 'project') do
    print_green_success "Project #{project['name']} updated"
    exit_code, err = get([project['id']] + (options[:remote] ? ["-r",options[:remote]] : []))
  end
  return exit_code, err
end