Class: Morpheus::Cli::Roles
- Inherits:
-
Object
- Object
- Morpheus::Cli::Roles
- Includes:
- AccountsHelper, CliCommand
- Defined in:
- lib/morpheus/cli/roles.rb
Instance Attribute Summary
Attributes included from CliCommand
Instance Method Summary collapse
- #add(args) ⇒ Object
- #connect(opts) ⇒ Object
- #get(args) ⇒ Object
- #handle(args) ⇒ Object
- #list(args) ⇒ Object
- #remove(args) ⇒ Object
- #update(args) ⇒ Object
- #update_cloud_access(args) ⇒ Object
- #update_feature_access(args) ⇒ Object
- #update_global_cloud_access(args) ⇒ Object
- #update_global_group_access(args) ⇒ Object
- #update_global_instance_type_access(args) ⇒ Object
- #update_group_access(args) ⇒ Object
- #update_instance_type_access(args) ⇒ Object
Methods included from AccountsHelper
#accounts_interface, #find_account_by_id, #find_account_by_name, #find_account_by_name_or_id, #find_account_from_options, #find_role_by_id, #find_role_by_name, #find_role_by_name_or_id, #find_user_by_id, #find_user_by_username, #find_user_by_username_or_id, #format_role_type, #format_user_role_names, #get_access_string, included, #print_accounts_table, #print_roles_table, #print_users_table, #roles_interface, #users_interface
Methods included from CliCommand
#build_common_options, #build_option_type_options, #command_name, #default_subcommand, #establish_remote_appliance_connection, #handle_subcommand, included, #interactive?, #noninteractive, #print_usage, #subcommand_aliases, #subcommand_usage, #subcommands, #usage, #verify_access_token!
Instance Method Details
#add(args) ⇒ Object
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 272 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 |
# File 'lib/morpheus/cli/roles.rb', line 222 def add(args) usage = "Usage: morpheus roles add [options]" = {} optparse = OptionParser.new do|opts| opts. = subcommand_usage("[options]") (opts, , add_role_option_types) (opts, , [:options, :json, :dry_run]) end optparse.parse!(args) connect() begin load_whoami() account = () account_id = account ? account['id'] : nil # argh, some options depend on others here...eg. multitenant is only available when roleType == 'user' #prompt_option_types = update_role_option_types() role_payload = {} v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'authority', 'fieldLabel' => 'Name', 'type' => 'text', 'required' => true, 'displayOrder' => 1}], [:options]) role_payload['authority'] = v_prompt['authority'] v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'description', 'fieldLabel' => 'Description', 'type' => 'text', 'displayOrder' => 2}], [:options]) role_payload['description'] = v_prompt['description'] if @is_master_account v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'roleType', 'fieldLabel' => 'Type', 'type' => 'select', 'selectOptions' => , 'defaultValue' => 'user', 'displayOrder' => 3}], [:options]) role_payload['roleType'] = v_prompt['roleType'] else role_payload['roleType'] = 'user' end v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'baseRole', 'fieldLabel' => 'Copy From Role', 'type' => 'text', 'displayOrder' => 4}], [:options]) if v_prompt['baseRole'].to_s != '' base_role = find_role_by_name_or_id(account_id, v_prompt['baseRole']) exit 1 if base_role.nil? role_payload['baseRoleId'] = base_role['id'] end if @is_master_account if role_payload['roleType'] == 'user' v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'multitenant', 'fieldLabel' => 'Multitenant', 'type' => 'checkbox', 'defaultValue' => 'off', 'description' => 'A Multitenant role is automatically copied into all existing subaccounts as well as placed into a subaccount when created. Useful for providing a set of predefined roles a Customer can use', 'displayOrder' => 5}], [:options]) role_payload['multitenant'] = ['on','true'].include?(v_prompt['multitenant'].to_s) end end role_payload['instanceLimits'] = {} v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'instanceLimits.maxStorage', 'fieldLabel' => 'Max Storage (bytes)', 'type' => 'text', 'displayOrder' => 8}], [:options]) if v_prompt['instanceLimits.maxStorage'].to_s.strip != '' role_payload['instanceLimits']['maxStorage'] = v_prompt['instanceLimits.maxStorage'].to_i end v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'instanceLimits.maxMemory', 'fieldLabel' => 'Max Memory (bytes)', 'type' => 'text', 'displayOrder' => 9}], [:options]) if v_prompt['instanceLimits.maxMemory'].to_s.strip != '' role_payload['instanceLimits']['maxMemory'] = v_prompt['instanceLimits.maxMemory'].to_i end v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'instanceLimits.maxCpu', 'fieldLabel' => 'CPU Count', 'type' => 'text', 'displayOrder' => 10}], [:options]) if v_prompt['instanceLimits.maxCpu'].to_s.strip != '' role_payload['instanceLimits']['maxCpu'] = v_prompt['instanceLimits.maxCpu'].to_i end payload = {role: role_payload} if [:dry_run] print_dry_run @roles_interface.dry.create(account_id, payload) return end json_response = @roles_interface.create(account_id, payload) if [:json] print JSON.pretty_generate(json_response) print "\n" return end if account print_green_success "Added role #{role_payload['authority']} to account #{account['name']}" else print_green_success "Added role #{role_payload['authority']}" end = [role_payload["authority"]] if account .push "--account-id", account['id'].to_s end get() rescue RestClient::Exception => e print_rest_exception(e, ) exit 1 end end |
#connect(opts) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/morpheus/cli/roles.rb', line 17 def connect(opts) @api_client = establish_remote_appliance_connection(opts) @whoami_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).whoami @users_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).users @accounts_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).accounts @roles_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).roles @groups_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).groups @options_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url). #@clouds_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).instance_types @instance_types_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).instance_types @active_group_id = Morpheus::Cli::Groups.active_group end |
#get(args) ⇒ Object
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 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 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 |
# File 'lib/morpheus/cli/roles.rb', line 78 def get(args) = {} optparse = OptionParser.new do|opts| opts. = subcommand_usage("[name]") opts.on(nil,'--feature-access', "Display Feature Access") do |val| [:include_feature_access] = true end opts.on(nil,'--group-access', "Display Group Access") do [:include_group_access] = true end opts.on(nil,'--cloud-access', "Display Cloud Access") do [:include_cloud_access] = true end opts.on(nil,'--instance-type-access', "Display Instance Type Access") do [:include_instance_type_access] = true end opts.on(nil,'--all-access', "Display All Access Lists") do [:include_feature_access] = true [:include_group_access] = true [:include_cloud_access] = true [:include_instance_type_access] = true end (opts, , [:json, :dry_run]) end optparse.parse!(args) if args.count < 1 puts optparse exit 1 end name = args[0] connect() begin account = () account_id = account ? account['id'] : nil if [:dry_run] print_dry_run @roles_interface.dry.list(account_id, {name: name}) return end role = find_role_by_name_or_id(account_id, name) exit 1 if role.nil? json_response = @roles_interface.get(account_id, role['id']) role = json_response['role'] if [:json] print JSON.pretty_generate(json_response) print "\n" else print "\n" ,cyan, bold, "Role Details\n","==================", reset, "\n\n" print cyan puts "ID: #{role['id']}" puts "Name: #{role['authority']}" puts "Description: #{role['description']}" puts "Scope: #{role['scope']}" puts "Type: #{format_role_type(role)}" puts "Multitenant: #{role['multitenant'] ? 'Yes' : 'No'}" puts "Owner: #{role['owner'] ? role['owner']['name'] : nil}" puts "Date Created: #{format_local_dt(role['dateCreated'])}" puts "Last Updated: #{format_local_dt(role['lastUpdated'])}" print "\n" ,cyan, bold, "Role Instance Limits\n","==================", reset, "\n\n" print cyan puts "Max Storage (bytes): #{role['instanceLimits'] ? role['instanceLimits']['maxStorage'] : 0}" puts "Max Memory (bytes): #{role['instanceLimits'] ? role['instanceLimits']['maxMemory'] : 0}" puts "CPU Count: #{role['instanceLimits'] ? role['instanceLimits']['maxCpu'] : 0}" print "\n" ,cyan, bold, "Feature Access\n","==================", reset, "\n\n" print cyan if [:include_feature_access] rows = json_response['featurePermissions'].collect do |it| { code: it['code'], name: it['name'], access: get_access_string(it['access']), } end tp rows, [:code, :name, :access] else puts "Use --feature-access to list feature access" end print "\n" ,cyan, bold, "Group Access\n","==================", reset, "\n\n" print cyan puts "Global Group Access: #{get_access_string(json_response['globalSiteAccess'])}\n\n" if json_response['globalSiteAccess'] == 'custom' if [:include_group_access] rows = json_response['sites'].collect do |it| { name: it['name'], access: get_access_string(it['access']), } end tp rows, [:name, :access] else puts "Use --group-access to list custom access" end end print "\n" ,cyan, bold, "Cloud Access\n","==================", reset, "\n\n" print cyan puts "Global Cloud Access: #{get_access_string(json_response['globalZoneAccess'])}\n\n" if json_response['globalZoneAccess'] == 'custom' if [:include_cloud_access] rows = json_response['zones'].collect do |it| { name: it['name'], access: get_access_string(it['access']), } end tp rows, [:name, :access] else puts "Use --cloud-access to list custom access" end end print "\n" ,cyan, bold, "Instance Type Access\n","==================", reset, "\n\n" print cyan puts "Global Instance Type Access: #{get_access_string(json_response['globalInstanceTypeAccess'])}\n\n" if json_response['globalInstanceTypeAccess'] == 'custom' if [:include_instance_type_access] rows = json_response['instanceTypePermissions'].collect do |it| { name: it['name'], access: get_access_string(it['access']), } end tp rows, [:name, :access] else puts "Use --instance-type-access to list custom access" end end print reset,"\n" end rescue RestClient::Exception => e print_rest_exception(e, ) exit 1 end end |
#handle(args) ⇒ Object
30 31 32 |
# File 'lib/morpheus/cli/roles.rb', line 30 def handle(args) handle_subcommand(args) end |
#list(args) ⇒ Object
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 |
# File 'lib/morpheus/cli/roles.rb', line 34 def list(args) = {} optparse = OptionParser.new do|opts| opts. = subcommand_usage() (opts, , [:list, :json, :dry_run]) end optparse.parse!(args) connect() begin load_whoami() account = () account_id = account ? account['id'] : nil params = {} [:phrase, :offset, :max, :sort, :direction].each do |k| params[k] = [k] unless [k].nil? end if [:dry_run] print_dry_run @roles_interface.dry.list(account_id, params) return end json_response = @roles_interface.list(account_id, params) roles = json_response['roles'] if [:json] print JSON.pretty_generate(json_response) print "\n" else print "\n" ,cyan, bold, "Morpheus Roles\n","==================", reset, "\n\n" if roles.empty? puts yellow,"No roles found.",reset else print_roles_table(roles, {is_master_account: @is_master_account}) print_results_pagination(json_response) end print reset,"\n" end rescue RestClient::Exception => e print_rest_exception(e, ) exit 1 end end |
#remove(args) ⇒ Object
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 430 431 432 433 434 435 436 |
# File 'lib/morpheus/cli/roles.rb', line 397 def remove(args) usage = "Usage: morpheus roles remove [name]" = {} optparse = OptionParser.new do|opts| opts. = subcommand_usage("[name]") (opts, , [:auto_confirm, :json, :dry_run]) end optparse.parse!(args) if args.count < 1 puts optparse exit 1 end name = args[0] connect() begin account = () account_id = account ? account['id'] : nil role = find_role_by_name_or_id(account_id, name) exit 1 if role.nil? unless [:yes] || Morpheus::Cli::OptionTypes.confirm("Are you sure you want to delete the role #{role['authority']}?") exit end if [:dry_run] print_dry_run @roles_interface.dry.destroy(account_id, role['id']) return end json_response = @roles_interface.destroy(account_id, role['id']) if [:json] print JSON.pretty_generate(json_response) print "\n" else print_green_success "Role #{role['authority']} removed" end rescue RestClient::Exception => e print_rest_exception(e, ) exit 1 end end |
#update(args) ⇒ Object
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 |
# File 'lib/morpheus/cli/roles.rb', line 315 def update(args) usage = "Usage: morpheus roles update [name] [options]" = {} optparse = OptionParser.new do|opts| opts. = subcommand_usage("[name] [options]") (opts, , update_role_option_types) (opts, , [:options, :json, :dry_run]) end optparse.parse!(args) if args.count < 1 puts optparse exit 1 end name = args[0] connect() begin load_whoami() account = () account_id = account ? account['id'] : nil role = find_role_by_name_or_id(account_id, name) exit 1 if role.nil? prompt_option_types = update_role_option_types() if !@is_master_account prompt_option_types = prompt_option_types.reject {|it| ['roleType', 'multitenant'].include?(it['fieldName']) } end if role['roleType'] != 'user' prompt_option_types = prompt_option_types.reject {|it| ['multitenant'].include?(it['fieldName']) } end #params = Morpheus::Cli::OptionTypes.prompt(prompt_option_types, options[:options], @api_client, options[:params]) params = [:options] || {} if params.empty? puts optparse option_lines = prompt_option_types.collect {|it| "\t-O #{it['fieldName']}=\"value\"" }.join("\n") puts "\nAvailable Options:\n#{option_lines}\n\n" exit 1 end #puts "parsed params is : #{params.inspect}" role_keys = ['authority', 'description', 'instanceLimits'] role_payload = params.select {|k,v| role_keys.include?(k) } if !role_payload['instanceLimits'] role_payload['instanceLimits'] = {} role_payload['instanceLimits']['maxStorage'] = params['instanceLimits.maxStorage'].to_i if params['instanceLimits.maxStorage'].to_s.strip != '' role_payload['instanceLimits']['maxMemory'] = params['instanceLimits.maxMemory'].to_i if params['instanceLimits.maxMemory'].to_s.strip != '' role_payload['instanceLimits']['maxCpu'] = params['instanceLimits.maxCpu'].to_i if params['instanceLimits.maxCpu'].to_s.strip != '' end if params['multitenant'].to_s != '' role_payload['multitenant'] = ['on','true'].include?(v_prompt['multitenant'].to_s) end payload = {role: role_payload} if [:dry_run] print_dry_run @roles_interface.dry.update(account_id, role['id'], payload) return end json_response = @roles_interface.update(account_id, role['id'], payload) if [:json] print JSON.pretty_generate(json_response) print "\n" return end print_green_success "Updated role #{role_payload['authority']}" = [role_payload["authority"] || role['authority']] if account .push "--account-id", account['id'].to_s end get() rescue RestClient::Exception => e print_rest_exception(e, ) exit 1 end end |
#update_cloud_access(args) ⇒ Object
638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 |
# File 'lib/morpheus/cli/roles.rb', line 638 def update_cloud_access(args) usage = "Usage: morpheus roles update-cloud-access [name] [cloud_name] [full|none]" = {} optparse = OptionParser.new do|opts| opts. = subcommand_usage("[name] [cloud] [full|none]") opts.on( '-g', '--group GROUP', "Group to find cloud in" ) do |val| [:group] = val end (opts, , [:json, :dry_run]) end optparse.parse!(args) if args.count < 2 puts optparse exit 1 end name = args[0] cloud_name = args[1] access_value = args[2].to_s.downcase if !['full', 'none'].include?(access_value) puts optparse exit 1 end connect() begin account = () account_id = account ? account['id'] : nil role = find_role_by_name_or_id(account_id, name) exit 1 if role.nil? role_json = @roles_interface.get(account_id, role['id']) if role_json['globalZoneAccess'] != 'custom' print "\n", red, "Global Cloud Access is currently: #{role_json['globalZoneAccess'].capitalize}" print "\n", "You must first set it to Custom via `morpheus roles update-global-cloud-access \"#{name}\" custom`" print "\n\n", reset exit 1 end group_id = nil if ![:group].nil? group_id = find_group_id_by_name([:group]) else group_id = @active_group_id end if group_id.nil? print_red_alert "Group not found or specified!" exit 1 end cloud_id = find_cloud_id_by_name(group_id, cloud_name) exit 1 if cloud_id.nil? params = {cloudId: cloud_id, access: access_value} if [:dry_run] print_dry_run @roles_interface.dry.update_cloud(account_id, role['id'], params) return end json_response = @roles_interface.update_cloud(account_id, role['id'], params) if [:json] print JSON.pretty_generate(json_response) print "\n" else print_green_success "Role #{role['authority']} global cloud access updated" end rescue RestClient::Exception => e print_rest_exception(e, ) exit 1 end end |
#update_feature_access(args) ⇒ Object
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 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 |
# File 'lib/morpheus/cli/roles.rb', line 438 def update_feature_access(args) usage = "Usage: morpheus roles update-feature-access [name] [code] [full|read|none]" = {} optparse = OptionParser.new do|opts| opts. = subcommand_usage("[name] [code] [full|read|none]") (opts, , [:json, :dry_run]) end optparse.parse!(args) if args.count < 3 puts optparse exit 1 end name = args[0] = args[1] access_value = args[2].to_s.downcase if !['full', 'read', 'custom', 'none'].include?(access_value) puts optparse exit 1 end connect() begin account = () account_id = account ? account['id'] : nil role = find_role_by_name_or_id(account_id, name) exit 1 if role.nil? params = {permissionCode: , access: access_value} if [:dry_run] print_dry_run @roles_interface.dry.(account_id, role['id'], params) return end json_response = @roles_interface.(account_id, role['id'], params) if [:json] print JSON.pretty_generate(json_response) print "\n" else print_green_success "Role #{role['authority']} feature access updated" end rescue RestClient::Exception => e print_rest_exception(e, ) exit 1 end end |
#update_global_cloud_access(args) ⇒ Object
592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 |
# File 'lib/morpheus/cli/roles.rb', line 592 def update_global_cloud_access(args) usage = "Usage: morpheus roles update-global-cloud-access [name] [full|custom|none]" = {} optparse = OptionParser.new do|opts| opts. = subcommand_usage("[name] [full|custom|none]") (opts, , [:json, :dry_run]) end optparse.parse!(args) if args.count < 2 puts optparse exit 1 end name = args[0] access_value = args[1].to_s.downcase if !['full', 'custom', 'none'].include?(access_value) puts optparse exit 1 end connect() begin account = () account_id = account ? account['id'] : nil role = find_role_by_name_or_id(account_id, name) exit 1 if role.nil? params = {permissionCode: 'ComputeZone', access: access_value} if [:dry_run] print_dry_run @roles_interface.dry.(account_id, role['id'], params) return end json_response = @roles_interface.(account_id, role['id'], params) if [:json] print JSON.pretty_generate(json_response) print "\n" else print_green_success "Role #{role['authority']} global cloud access updated" end rescue RestClient::Exception => e print_rest_exception(e, ) exit 1 end end |
#update_global_group_access(args) ⇒ Object
485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 |
# File 'lib/morpheus/cli/roles.rb', line 485 def update_global_group_access(args) usage = "Usage: morpheus roles update-global-group-access [name] [full|read|custom|none]" = {} optparse = OptionParser.new do|opts| opts. = subcommand_usage("[name] [code] [full|read|custom|none]") (opts, , [:json, :dry_run]) end optparse.parse!(args) if args.count < 2 puts optparse exit 1 end name = args[0] access_value = args[1].to_s.downcase if !['full', 'read', 'custom', 'none'].include?(access_value) puts optparse exit 1 end connect() begin account = () account_id = account ? account['id'] : nil role = find_role_by_name_or_id(account_id, name) exit 1 if role.nil? params = {permissionCode: 'ComputeSite', access: access_value} if [:dry_run] print_dry_run @roles_interface.dry.(account_id, role['id'], params) return end json_response = @roles_interface.(account_id, role['id'], params) if [:json] print JSON.pretty_generate(json_response) print "\n" else print_green_success "Role #{role['authority']} global group access updated" end rescue RestClient::Exception => e print_rest_exception(e, ) exit 1 end end |
#update_global_instance_type_access(args) ⇒ Object
710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 |
# File 'lib/morpheus/cli/roles.rb', line 710 def update_global_instance_type_access(args) usage = "Usage: morpheus roles update-global-instance-type-access [name] [full|custom|none]" = {} optparse = OptionParser.new do|opts| opts. = subcommand_usage("[name] [full|custom|none]") (opts, , [:json, :dry_run]) end optparse.parse!(args) if args.count < 2 puts optparse exit 1 end name = args[0] access_value = args[1].to_s.downcase if !['full', 'custom', 'none'].include?(access_value) puts optparse exit 1 end connect() begin account = () account_id = account ? account['id'] : nil role = find_role_by_name_or_id(account_id, name) exit 1 if role.nil? params = {permissionCode: 'InstanceType', access: access_value} if [:dry_run] print_dry_run @roles_interface.dry.(account_id, role['id'], params) return end json_response = @roles_interface.(account_id, role['id'], params) if [:json] print JSON.pretty_generate(json_response) print "\n" else print_green_success "Role #{role['authority']} global instance type access updated" end rescue RestClient::Exception => e print_rest_exception(e, ) exit 1 end end |
#update_group_access(args) ⇒ Object
531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 |
# File 'lib/morpheus/cli/roles.rb', line 531 def update_group_access(args) usage = "Usage: morpheus roles update-group-access [name] [group_name] [full|read|none]" = {} optparse = OptionParser.new do|opts| opts. = subcommand_usage("[name] [group] [full|read|none]") (opts, , [:json, :dry_run]) end optparse.parse!(args) if args.count < 2 puts optparse exit 1 end name = args[0] group_name = args[1] access_value = args[2].to_s.downcase if !['full', 'read', 'none'].include?(access_value) puts optparse exit 1 end connect() begin account = () account_id = account ? account['id'] : nil role = find_role_by_name_or_id(account_id, name) exit 1 if role.nil? role_json = @roles_interface.get(account_id, role['id']) if role_json['globalSiteAccess'] != 'custom' print "\n", red, "Global Group Access is currently: #{role_json['globalSiteAccess'].capitalize}" print "\n", "You must first set it to Custom via `morpheus roles update-global-group-access \"#{name}\" custom`" print "\n\n", reset exit 1 end # group_id = find_group_id_by_name(group_name) # exit 1 if group_id.nil? group = find_group_by_name(group_name) exit 1 if group.nil? group_id = group['id'] params = {groupId: group_id, access: access_value} if [:dry_run] print_dry_run @roles_interface.dry.update_group(account_id, role['id'], params) return end json_response = @roles_interface.update_group(account_id, role['id'], params) if [:json] print JSON.pretty_generate(json_response) print "\n" else print_green_success "Role #{role['authority']} global group access updated" end rescue RestClient::Exception => e print_rest_exception(e, ) exit 1 end end |
#update_instance_type_access(args) ⇒ Object
757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 |
# File 'lib/morpheus/cli/roles.rb', line 757 def update_instance_type_access(args) usage = "Usage: morpheus roles update-instance-type-access [name] [instance_type_name] [full|none]" = {} optparse = OptionParser.new do|opts| opts. = subcommand_usage("[name] [instance-type] [full|none]") (opts, , [:json, :dry_run]) end optparse.parse!(args) if args.count < 2 puts optparse exit 1 end name = args[0] instance_type_name = args[1] access_value = args[2].to_s.downcase if !['full', 'none'].include?(access_value) puts optparse exit 1 end connect() begin account = () account_id = account ? account['id'] : nil role = find_role_by_name_or_id(account_id, name) exit 1 if role.nil? role_json = @roles_interface.get(account_id, role['id']) if role_json['globalInstanceTypeAccess'] != 'custom' print "\n", red, "Global Instance Type Access is currently: #{role_json['globalInstanceTypeAccess'].capitalize}" print "\n", "You must first set it to Custom via `morpheus roles update-global-instance-type-access \"#{name}\" custom`" print "\n\n", reset exit 1 end instance_type = find_instance_type_by_name(instance_type_name) exit 1 if instance_type.nil? params = {instanceTypeId: instance_type['id'], access: access_value} if [:dry_run] print_dry_run @roles_interface.dry.update_instance_type(account_id, role['id'], params) return end json_response = @roles_interface.update_instance_type(account_id, role['id'], params) if [:json] print JSON.pretty_generate(json_response) print "\n" else print_green_success "Role #{role['authority']} global instance type access updated" end rescue RestClient::Exception => e print_rest_exception(e, ) exit 1 end end |