Class: Ey::Core::Client::Mock
- Inherits:
-
Object
- Object
- Ey::Core::Client::Mock
- Extended by:
- Mock::Util
- Includes:
- Shared, Mock::Helper, Mock::Params, Mock::Resources, Mock::Searching, Mock::Util
- Defined in:
- lib/vendor/core/ey-core/client.rb,
lib/vendor/core/ey-core/requests/signup.rb,
lib/vendor/core/ey-core/requests/get_gem.rb,
lib/vendor/core/ey-core/requests/get_log.rb,
lib/vendor/core/ey-core/requests/get_logs.rb,
lib/vendor/core/ey-core/requests/get_slot.rb,
lib/vendor/core/ey-core/requests/get_task.rb,
lib/vendor/core/ey-core/requests/get_user.rb,
lib/vendor/core/ey-core/requests/get_addon.rb,
lib/vendor/core/ey-core/requests/get_alert.rb,
lib/vendor/core/ey-core/requests/get_costs.rb,
lib/vendor/core/ey-core/requests/get_slots.rb,
lib/vendor/core/ey-core/requests/get_tasks.rb,
lib/vendor/core/ey-core/requests/get_users.rb,
lib/vendor/core/ey-core/requests/create_log.rb,
lib/vendor/core/ey-core/requests/get_addons.rb,
lib/vendor/core/ey-core/requests/get_alerts.rb,
lib/vendor/core/ey-core/requests/get_backup.rb,
lib/vendor/core/ey-core/requests/get_server.rb,
lib/vendor/core/ey-core/requests/get_volume.rb,
lib/vendor/core/ey-core/requests/create_task.rb,
lib/vendor/core/ey-core/requests/create_user.rb,
lib/vendor/core/ey-core/requests/get_account.rb,
lib/vendor/core/ey-core/requests/get_address.rb,
lib/vendor/core/ey-core/requests/get_backups.rb,
lib/vendor/core/ey-core/requests/get_billing.rb,
lib/vendor/core/ey-core/requests/get_cluster.rb,
lib/vendor/core/ey-core/requests/get_feature.rb,
lib/vendor/core/ey-core/requests/get_keypair.rb,
lib/vendor/core/ey-core/requests/get_message.rb,
lib/vendor/core/ey-core/requests/get_request.rb,
lib/vendor/core/ey-core/requests/get_servers.rb,
lib/vendor/core/ey-core/requests/get_storage.rb,
lib/vendor/core/ey-core/requests/get_volumes.rb,
lib/vendor/core/ey-core/requests/update_slot.rb,
lib/vendor/core/ey-core/requests/upload_file.rb,
lib/vendor/core/ey-core/requests/create_addon.rb,
lib/vendor/core/ey-core/requests/create_alert.rb,
lib/vendor/core/ey-core/requests/create_slots.rb,
lib/vendor/core/ey-core/requests/create_token.rb,
lib/vendor/core/ey-core/requests/destroy_user.rb,
lib/vendor/core/ey-core/requests/get_accounts.rb,
lib/vendor/core/ey-core/requests/get_clusters.rb,
lib/vendor/core/ey-core/requests/get_contacts.rb,
lib/vendor/core/ey-core/requests/get_features.rb,
lib/vendor/core/ey-core/requests/get_firewall.rb,
lib/vendor/core/ey-core/requests/get_keypairs.rb,
lib/vendor/core/ey-core/requests/get_messages.rb,
lib/vendor/core/ey-core/requests/get_metadata.rb,
lib/vendor/core/ey-core/requests/get_provider.rb,
lib/vendor/core/ey-core/requests/get_requests.rb,
lib/vendor/core/ey-core/requests/get_storages.rb,
lib/vendor/core/ey-core/requests/update_addon.rb,
lib/vendor/core/ey-core/requests/update_alert.rb,
lib/vendor/core/ey-core/requests/create_backup.rb,
lib/vendor/core/ey-core/requests/destroy_addon.rb,
lib/vendor/core/ey-core/requests/download_file.rb,
lib/vendor/core/ey-core/requests/finish_backup.rb,
lib/vendor/core/ey-core/requests/get_addresses.rb,
lib/vendor/core/ey-core/requests/get_api_token.rb,
lib/vendor/core/ey-core/requests/get_component.rb,
lib/vendor/core/ey-core/requests/get_connector.rb,
lib/vendor/core/ey-core/requests/get_firewalls.rb,
lib/vendor/core/ey-core/requests/get_providers.rb,
lib/vendor/core/ey-core/requests/reboot_server.rb,
lib/vendor/core/ey-core/requests/update_server.rb,
lib/vendor/core/ey-core/requests/attach_address.rb,
lib/vendor/core/ey-core/requests/cancel_account.rb,
lib/vendor/core/ey-core/requests/create_account.rb,
lib/vendor/core/ey-core/requests/create_address.rb,
lib/vendor/core/ey-core/requests/create_cluster.rb,
lib/vendor/core/ey-core/requests/create_keypair.rb,
lib/vendor/core/ey-core/requests/create_message.rb,
lib/vendor/core/ey-core/requests/create_storage.rb,
lib/vendor/core/ey-core/requests/destroy_server.rb,
lib/vendor/core/ey-core/requests/detach_address.rb,
lib/vendor/core/ey-core/requests/enable_feature.rb,
lib/vendor/core/ey-core/requests/get_components.rb,
lib/vendor/core/ey-core/requests/get_connectors.rb,
lib/vendor/core/ey-core/requests/get_membership.rb,
lib/vendor/core/ey-core/requests/update_billing.rb,
lib/vendor/core/ey-core/requests/update_cluster.rb,
lib/vendor/core/ey-core/requests/create_firewall.rb,
lib/vendor/core/ey-core/requests/create_provider.rb,
lib/vendor/core/ey-core/requests/destroy_cluster.rb,
lib/vendor/core/ey-core/requests/destroy_storage.rb,
lib/vendor/core/ey-core/requests/disable_feature.rb,
lib/vendor/core/ey-core/requests/get_application.rb,
lib/vendor/core/ey-core/requests/get_backup_file.rb,
lib/vendor/core/ey-core/requests/get_environment.rb,
lib/vendor/core/ey-core/requests/get_plan_usages.rb,
lib/vendor/core/ey-core/requests/create_connector.rb,
lib/vendor/core/ey-core/requests/destroy_firewall.rb,
lib/vendor/core/ey-core/requests/destroy_provider.rb,
lib/vendor/core/ey-core/requests/get_applications.rb,
lib/vendor/core/ey-core/requests/get_backup_files.rb,
lib/vendor/core/ey-core/requests/get_current_user.rb,
lib/vendor/core/ey-core/requests/get_environments.rb,
lib/vendor/core/ey-core/requests/get_legacy_alert.rb,
lib/vendor/core/ey-core/requests/get_server_event.rb,
lib/vendor/core/ey-core/requests/get_storage_user.rb,
lib/vendor/core/ey-core/requests/request_callback.rb,
lib/vendor/core/ey-core/requests/update_connector.rb,
lib/vendor/core/ey-core/requests/create_membership.rb,
lib/vendor/core/ey-core/requests/get_account_trial.rb,
lib/vendor/core/ey-core/requests/get_firewall_rule.rb,
lib/vendor/core/ey-core/requests/get_legacy_alerts.rb,
lib/vendor/core/ey-core/requests/get_load_balancer.rb,
lib/vendor/core/ey-core/requests/get_server_events.rb,
lib/vendor/core/ey-core/requests/get_server_usages.rb,
lib/vendor/core/ey-core/requests/get_storage_users.rb,
lib/vendor/core/ey-core/requests/update_membership.rb,
lib/vendor/core/ey-core/requests/authorized_channel.rb,
lib/vendor/core/ey-core/requests/create_application.rb,
lib/vendor/core/ey-core/requests/create_backup_file.rb,
lib/vendor/core/ey-core/requests/create_environment.rb,
lib/vendor/core/ey-core/requests/get_cluster_update.rb,
lib/vendor/core/ey-core/requests/get_firewall_rules.rb,
lib/vendor/core/ey-core/requests/get_load_balancers.rb,
lib/vendor/core/ey-core/requests/get_slot_component.rb,
lib/vendor/core/ey-core/requests/create_storage_user.rb,
lib/vendor/core/ey-core/requests/destroy_environment.rb,
lib/vendor/core/ey-core/requests/get_cluster_updates.rb,
lib/vendor/core/ey-core/requests/get_database_server.rb,
lib/vendor/core/ey-core/requests/get_slot_components.rb,
lib/vendor/core/ey-core/requests/get_ssl_certificate.rb,
lib/vendor/core/ey-core/requests/create_firewall_rule.rb,
lib/vendor/core/ey-core/requests/create_load_balancer.rb,
lib/vendor/core/ey-core/requests/destroy_storage_user.rb,
lib/vendor/core/ey-core/requests/get_addon_attachment.rb,
lib/vendor/core/ey-core/requests/get_component_action.rb,
lib/vendor/core/ey-core/requests/get_database_servers.rb,
lib/vendor/core/ey-core/requests/get_database_service.rb,
lib/vendor/core/ey-core/requests/get_logical_database.rb,
lib/vendor/core/ey-core/requests/get_ssl_certificates.rb,
lib/vendor/core/ey-core/requests/get_untracked_server.rb,
lib/vendor/core/ey-core/requests/create_cluster_update.rb,
lib/vendor/core/ey-core/requests/destroy_firewall_rule.rb,
lib/vendor/core/ey-core/requests/destroy_load_balancer.rb,
lib/vendor/core/ey-core/requests/get_account_referrals.rb,
lib/vendor/core/ey-core/requests/get_addon_attachments.rb,
lib/vendor/core/ey-core/requests/get_cluster_component.rb,
lib/vendor/core/ey-core/requests/get_component_actions.rb,
lib/vendor/core/ey-core/requests/get_database_services.rb,
lib/vendor/core/ey-core/requests/get_logical_databases.rb,
lib/vendor/core/ey-core/requests/get_provider_location.rb,
lib/vendor/core/ey-core/requests/get_untracked_servers.rb,
lib/vendor/core/ey-core/requests/update_slot_component.rb,
lib/vendor/core/ey-core/requests/create_database_server.rb,
lib/vendor/core/ey-core/requests/create_ssl_certificate.rb,
lib/vendor/core/ey-core/requests/get_cluster_components.rb,
lib/vendor/core/ey-core/requests/get_keypair_deployment.rb,
lib/vendor/core/ey-core/requests/get_load_balancer_node.rb,
lib/vendor/core/ey-core/requests/get_provider_locations.rb,
lib/vendor/core/ey-core/requests/update_ssl_certificate.rb,
lib/vendor/core/ey-core/requests/create_database_service.rb,
lib/vendor/core/ey-core/requests/create_logical_database.rb,
lib/vendor/core/ey-core/requests/create_untracked_server.rb,
lib/vendor/core/ey-core/requests/destroy_database_server.rb,
lib/vendor/core/ey-core/requests/destroy_ssl_certificate.rb,
lib/vendor/core/ey-core/requests/get_application_archive.rb,
lib/vendor/core/ey-core/requests/get_keypair_deployments.rb,
lib/vendor/core/ey-core/requests/get_load_balancer_nodes.rb,
lib/vendor/core/ey-core/requests/get_operational_contact.rb,
lib/vendor/core/ey-core/requests/update_addon_attachment.rb,
lib/vendor/core/ey-core/requests/update_untracked_server.rb,
lib/vendor/core/ey-core/requests/create_cluster_component.rb,
lib/vendor/core/ey-core/requests/destroy_database_service.rb,
lib/vendor/core/ey-core/requests/destroy_logical_database.rb,
lib/vendor/core/ey-core/requests/discover_database_server.rb,
lib/vendor/core/ey-core/requests/get_account_cancellation.rb,
lib/vendor/core/ey-core/requests/get_application_archives.rb,
lib/vendor/core/ey-core/requests/get_database_plan_usages.rb,
lib/vendor/core/ey-core/requests/get_operational_contacts.rb,
lib/vendor/core/ey-core/requests/update_cluster_component.rb,
lib/vendor/core/ey-core/requests/create_keypair_deployment.rb,
lib/vendor/core/ey-core/requests/get_alerting_environments.rb,
lib/vendor/core/ey-core/requests/get_load_balancer_service.rb,
lib/vendor/core/ey-core/requests/bootstrap_logical_database.rb,
lib/vendor/core/ey-core/requests/create_application_archive.rb,
lib/vendor/core/ey-core/requests/discover_provider_location.rb,
lib/vendor/core/ey-core/requests/get_application_deployment.rb,
lib/vendor/core/ey-core/requests/get_database_server_usages.rb,
lib/vendor/core/ey-core/requests/get_load_balancer_services.rb,
lib/vendor/core/ey-core/requests/update_application_archive.rb,
lib/vendor/core/ey-core/requests/get_application_deployments.rb,
lib/vendor/core/ey-core/requests/get_environment_plan_usages.rb,
lib/vendor/core/ey-core/requests/get_database_server_snapshot.rb,
lib/vendor/core/ey-core/requests/run_cluster_component_action.rb,
lib/vendor/core/ey-core/requests/get_database_server_revisions.rb,
lib/vendor/core/ey-core/requests/get_database_server_snapshots.rb,
lib/vendor/core/ey-core/requests/get_database_servers_firewalls.rb,
lib/vendor/core/ey-core/requests/run_cluster_application_action.rb,
lib/vendor/core/ey-core/requests/get_possible_provider_locations.rb,
lib/vendor/core/ey-core/requests/create_database_service_snapshot.rb,
lib/vendor/core/ey-core/requests/get_environment_database_services.rb,
lib/vendor/core/ey-core/requests/get_environment_logical_databases.rb,
lib/vendor/core/ey-core/requests/discover_database_server_snapshots.rb,
lib/vendor/core/ey-core/requests/run_environment_application_action.rb
Overview
Real
Class Attribute Summary collapse
-
.delay ⇒ Object
Returns the value of attribute delay.
Instance Attribute Summary collapse
-
#current_server ⇒ Object
readonly
Returns the value of attribute current_server.
Attributes included from Shared
Class Method Summary collapse
Instance Method Summary collapse
- #attach_address(params = {}) ⇒ Object
- #authorized_channel(path) ⇒ Object
- #bootstrap_logical_database(_params = {}) ⇒ Object
- #cancel_account(resource_id, requested_by_id) ⇒ Object
- #create_account(params = {}) ⇒ Object
- #create_addon(params = {}) ⇒ Object
- #create_address(params = {}) ⇒ Object
- #create_alert(_params = {}) ⇒ Object
- #create_application(params = {}) ⇒ Object
- #create_application_archive(params = {}) ⇒ Object
- #create_backup(params = {}) ⇒ Object
- #create_backup_file(params = {}) ⇒ Object
- #create_cluster(params = {}) ⇒ Object
- #create_cluster_component(params = {}) ⇒ Object
- #create_cluster_update(params = {}) ⇒ Object
- #create_connector(params = {}) ⇒ Object
- #create_database_server(_params = {}) ⇒ Object
- #create_database_service(_params = {}) ⇒ Object
- #create_database_service_snapshot(_params = {}) ⇒ Object
- #create_environment(params = {}) ⇒ Object
- #create_firewall(params = {}) ⇒ Object
- #create_firewall_rule(params = {}) ⇒ Object
- #create_keypair(params = {}) ⇒ Object
- #create_keypair_deployment(params = {}) ⇒ Object
- #create_load_balancer(params = {}) ⇒ Object
- #create_log(params = {}) ⇒ Object
- #create_logical_database(_params = {}) ⇒ Object
- #create_membership(params = {}) ⇒ Object
- #create_message(_params = {}) ⇒ Object
- #create_provider(params = {}) ⇒ Object
- #create_slots(params = {}) ⇒ Object
- #create_ssl_certificate(params = {}) ⇒ Object
- #create_storage(params = {}) ⇒ Object
- #create_storage_user(params = {}) ⇒ Object
- #create_task(params = {}) ⇒ Object
- #create_token(params = {}) ⇒ Object
- #create_untracked_server(params = {}) ⇒ Object
- #create_user(params = {}) ⇒ Object
-
#current_user ⇒ Hash
Lazily re-seeds data after reset.
- #data ⇒ Object
- #delay ⇒ Object
- #destroy_addon(params = {}) ⇒ Object
- #destroy_cluster(id) ⇒ Object
- #destroy_database_server(params = {}) ⇒ Object
- #destroy_database_service(params = {}) ⇒ Object
- #destroy_environment(params = {}) ⇒ Object
- #destroy_firewall(params = {}) ⇒ Object
- #destroy_firewall_rule(params = {}) ⇒ Object
- #destroy_load_balancer(params = {}) ⇒ Object
- #destroy_logical_database(params = {}) ⇒ Object
- #destroy_provider(id) ⇒ Object
- #destroy_server(id) ⇒ Object
- #destroy_ssl_certificate(params = {}) ⇒ Object
- #destroy_storage(id) ⇒ Object
- #destroy_storage_user(params = {}) ⇒ Object
- #destroy_user(params = {}) ⇒ Object
- #detach_address(params = {}) ⇒ Object
- #disable_feature(params = {}) ⇒ Object
- #discover_database_server(params = {}) ⇒ Object
- #discover_database_server_snapshots(params = {}) ⇒ Object
- #discover_provider_location(url, location_id) ⇒ Object
- #download_file(params = {}) ⇒ Object
- #enable_feature(params = {}) ⇒ Object
- #finish_backup(params = {}) ⇒ Object
- #get_account(params = {}) ⇒ Object
- #get_account_cancellation(params = {}) ⇒ Object
- #get_account_referrals(params = {}) ⇒ Object
- #get_account_trial(params = {}) ⇒ Object
- #get_accounts(params = {}) ⇒ Object
- #get_addon(params = {}) ⇒ Object
- #get_addon_attachment(params = {}) ⇒ Object
- #get_addon_attachments(params = {}) ⇒ Object
- #get_addons(params = {}) ⇒ Object
- #get_address(params = {}) ⇒ Object
- #get_addresses(params = {}) ⇒ Object
- #get_alert(params = {}) ⇒ Object
- #get_alerting_environments(params = {}) ⇒ Object
- #get_alerts(params = {}) ⇒ Object
- #get_api_token(username, password) ⇒ Object
- #get_application(params = {}) ⇒ Object
- #get_application_archive(params = {}) ⇒ Object
- #get_application_archives(params = {}) ⇒ Object
- #get_application_deployment(params = {}) ⇒ Object
- #get_application_deployments(params = {}) ⇒ Object
- #get_applications(params = {}) ⇒ Object
- #get_backup(params = {}) ⇒ Object
- #get_backup_file(params = {}) ⇒ Object
- #get_backup_files(params = {}) ⇒ Object
- #get_backups(params = {}) ⇒ Object
- #get_billing(params = {}) ⇒ Object
- #get_cluster(params = {}) ⇒ Object
- #get_cluster_component(params = {}) ⇒ Object
- #get_cluster_components(params = {}) ⇒ Object
- #get_cluster_update(params = {}) ⇒ Object
- #get_cluster_updates(params = {}) ⇒ Object
- #get_clusters(params = {}) ⇒ Object
- #get_component(params = {}) ⇒ Object
- #get_component_action(params = {}) ⇒ Object
- #get_component_actions(params = {}) ⇒ Object
- #get_components(params = {}) ⇒ Object
- #get_connector(params = {}) ⇒ Object
- #get_connectors(params = {}) ⇒ Object
- #get_contacts(params = {}) ⇒ Object
- #get_costs(params = {}) ⇒ Object
- #get_current_user(params = {}) ⇒ Object
- #get_database_plan_usages(params = {}) ⇒ Object
- #get_database_server(params = {}) ⇒ Object
- #get_database_server_revisions(params = {}) ⇒ Object
- #get_database_server_snapshot(params = {}) ⇒ Object
- #get_database_server_snapshots(params = {}) ⇒ Object
- #get_database_server_usages(params = {}) ⇒ Object
- #get_database_servers(params = {}) ⇒ Object
- #get_database_servers_firewalls(params = {}) ⇒ Object
- #get_database_service(params = {}) ⇒ Object
- #get_database_services(_params = {}) ⇒ Object
- #get_environment(params = {}) ⇒ Object
- #get_environment_database_services(params = {}) ⇒ Object
- #get_environment_logical_databases(params = {}) ⇒ Object
- #get_environment_plan_usages(params = {}) ⇒ Object
- #get_environments(params = {}) ⇒ Object
- #get_feature(params = {}) ⇒ Object
- #get_features(params = {}) ⇒ Object
- #get_firewall(params = {}) ⇒ Object
- #get_firewall_rule(params = {}) ⇒ Object
- #get_firewall_rules(params = {}) ⇒ Object
- #get_firewalls(params = {}) ⇒ Object
- #get_gem(params = {}) ⇒ Object
- #get_keypair(params = {}) ⇒ Object
- #get_keypair_deployment(params = {}) ⇒ Object
- #get_keypair_deployments(params = {}) ⇒ Object
- #get_keypairs(params = {}) ⇒ Object
- #get_legacy_alert(params = {}) ⇒ Object
- #get_legacy_alerts(params = {}) ⇒ Object
- #get_load_balancer(params = {}) ⇒ Object
- #get_load_balancer_nodes(params = {}) ⇒ Object
- #get_load_balancer_service(params = {}) ⇒ Object
- #get_load_balancer_services(params = {}) ⇒ Object
- #get_load_balancers(params = {}) ⇒ Object
- #get_log(params = {}) ⇒ Object
- #get_logical_database(params = {}) ⇒ Object
- #get_logical_databases(_params = {}) ⇒ Object
- #get_logs(params = {}) ⇒ Object
- #get_membership(params = {}) ⇒ Object
- #get_message(params = {}) ⇒ Object
- #get_messages(params = {}) ⇒ Object
- #get_metadata(params = {}) ⇒ Object
- #get_operational_contact(params = {}) ⇒ Object
- #get_operational_contacts(params = {}) ⇒ Object
- #get_plan_usages(params = {}) ⇒ Object
- #get_possible_provider_locations(type) ⇒ Object
- #get_provider(params = {}) ⇒ Object
- #get_provider_location(params = {}) ⇒ Object
- #get_provider_locations(params = {}) ⇒ Object
- #get_providers(params = {}) ⇒ Object
- #get_request(params = {}) ⇒ Object
- #get_requests(params = {}) ⇒ Object
- #get_server(params = {}) ⇒ Object
- #get_server_event(params = {}) ⇒ Object
- #get_server_events(params = {}) ⇒ Object
- #get_server_usages(params = {}) ⇒ Object
- #get_servers(params = {}) ⇒ Object
- #get_slot(params = {}) ⇒ Object
- #get_slot_component(params = {}) ⇒ Object
- #get_slot_components(params = {}) ⇒ Object
- #get_slots(params = {}) ⇒ Object
- #get_ssl_certificate(params = {}) ⇒ Object
- #get_ssl_certificates(params = {}) ⇒ Object
- #get_storage(params = {}) ⇒ Object
- #get_storage_user(params = {}) ⇒ Object
- #get_storage_users(params = {}) ⇒ Object
- #get_storages(params = {}) ⇒ Object
- #get_task(params = {}) ⇒ Object
- #get_tasks(params = {}) ⇒ Object
- #get_untracked_server(params = {}) ⇒ Object
- #get_untracked_servers(params = {}) ⇒ Object
- #get_user(params = {}) ⇒ Object
- #get_users(params = {}) ⇒ Object
- #get_volume(params = {}) ⇒ Object
- #get_volumes(params = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Mock
constructor
A new instance of Mock.
- #reboot_server(params = {}) ⇒ Object
- #request_callback(id) ⇒ Object
- #response(options = {}) ⇒ Object
- #run_cluster_application_action(params = {}) ⇒ Object
- #run_cluster_component_action(params = {}) ⇒ Object
- #run_environment_application_action(params = {}) ⇒ Object
- #serial_id ⇒ Object
- #signup(_params) ⇒ Object
- #update_addon(params = {}) ⇒ Object
- #update_addon_attachment(params = {}) ⇒ Object
- #update_alert(_params = {}) ⇒ Object
- #update_application_archive(params = {}) ⇒ Object
- #update_billing(params = {}) ⇒ Object
- #update_cluster(params = {}) ⇒ Object
- #update_cluster_component(params = {}) ⇒ Object
- #update_connector(params = {}) ⇒ Object
- #update_membership(params = {}) ⇒ Object
- #update_server(params = {}) ⇒ Object
- #update_slot(params = {}) ⇒ Object
- #update_slot_component(params = {}) ⇒ Object
- #update_ssl_certificate(params = {}) ⇒ Object
- #update_untracked_server(params = {}) ⇒ Object
- #upload_file(_params = {}) ⇒ Object
Methods included from Mock::Util
api_token, deep_dup, ip_address, normalize_hash, uuid
Methods included from Mock::Helper
#create_database_service_resource, #create_feature
Methods included from Mock::Searching
#page, #pluralize, #search, #search_and_page, #url_for_page
Methods included from Mock::Resources
#find, #load_addon_attachments, #mock_account_setup, #mock_ssh_key, #resource_identity
Methods included from Mock::Params
#extract_url_params!, #path_params, #url_params
Methods included from Shared
#metadata, #require_argument, #require_argument!, #require_arguments, #require_parameters, #setup, #url_for
Constructor Details
#initialize(options = {}) ⇒ Mock
Returns a new instance of Mock.
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 756 757 758 759 760 |
# File 'lib/vendor/core/ey-core/client.rb', line 723 def initialize(={}) setup() @url = [:url] || "https://api.engineyard.com" if authentication == :token if server = self.data[:servers].values.find { |s| s["token"] == [:token] } @current_server = server else @current_user ||= begin _,found = self.data[:users].detect{|k,v| v["token"] == [:token]} found end # FIXME(rs) get rid of this and the implicit Josh Lane creation entirely @current_user ||= begin _,found = self.data[:users].detect{|k,v| v["email"] == "[email protected]"} found end unless @current_user user = Ey::Core::Client.new({ :url => @url, :auth_id => SecureRandom.hex(8), :auth_key => SecureRandom.hex(16), }).users.create!({ :email => "[email protected]", :name => "Joshua Lane", }) if [:token] self.data[:users][user.id]["token"] = [:token] end @current_user = self.data[:users][user.id] end end end end |
Class Attribute Details
.delay ⇒ Object
Returns the value of attribute delay.
704 705 706 |
# File 'lib/vendor/core/ey-core/client.rb', line 704 def delay @delay end |
Instance Attribute Details
#current_server ⇒ Object (readonly)
Returns the value of attribute current_server.
721 722 723 |
# File 'lib/vendor/core/ey-core/client.rb', line 721 def current_server @current_server end |
Class Method Details
.data ⇒ Object
574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 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 637 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 |
# File 'lib/vendor/core/ey-core/client.rb', line 574 def self.data @data ||= Hash.new do |h,k| h[k] = begin cc_id = self.uuid dc_id = self.uuid app_id = self.uuid deis_id = self.uuid components = { cc_id => { "created_at" => Time.now.to_s, "deleted_at" => nil, "id" => cc_id, "name" => "cluster_cookbooks", "updated_at" => Time.now.to_s, "uri" => "git://github.com/engineyard/cluster_cookbooks.git", }, dc_id => { "created_at" => Time.now.to_s, "deleted_at" => nil, "id" => dc_id, "name" => "default_cookbooks", "updated_at" => Time.now.to_s, "uri" => "git://github.com/engineyard/cloud_cookbooks.git", }, app_id => { "created_at" => Time.now.to_s, "deleted_at" => nil, "id" => app_id, "name" => "default_deployer", "updated_at" => Time.now.to_s, "uri" => "git://github.com/engineyard/engineyard-serverside.git", }, deis_id => { "created_at" => Time.now.to_s, "deleted_at" => nil, "id" => deis_id, "name" => "deis", "updated_at" => Time.now.to_s, "uri" => "git://github.com/deis/deis.git", } } possible_provider_locations = { "azure" => [ { "id" => "East US", "name" => "East US" }, { "id" => "North Europe", "name" => "North Europe" }, { "id" => "West Europe", "name" => "West Europe" }, { "id" => "West US", "name" => "West US" }, { "id" => "Japan East", "name" => "Japan East" } ], "aws" => [ { "id" => "us-east-1", "name" => "Eastern United States" }, { "id" => "us-west-1", "name" => "Western US (Northern CA)" }, { "id" => "us-west-2", "name" => "Western US (Oregon)" }, { "id" => "sa-east-1", "name" => "South America" }, { "id" => "eu-west-1", "name" => "Europe" }, { "id" => "ap-southeast-1", "name" => "Singapore" }, { "id" => "ap-southeast-2", "name" => "Australia" }, { "id" => "ap-northeast-1", "name" => "Japan" } ] } { :accounts => {}, :account_referrals => {}, :addons => {}, :addresses => {}, :alerts => {}, :applications => {}, :application_archives => {}, :application_deployments => {}, :backup_files => {}, :backups => {}, :billing => {}, :cluster_components => {}, :cluster_updates => {}, :clusters => {}, :cluster_firewalls => [], :component_actions => {}, :components => components, :connectors => {}, :contacts => {}, :contact_assignments => [], :costs => [], :database_server_firewalls => [], :database_server_revisions => {}, :database_server_snapshots => {}, :database_servers => {}, :database_services => {}, :database_server_usages => Hash.new { |h1,k1| h1[k1] = {} }, :database_plan_usages => Hash.new { |h1,k1| h1[k1] = {} }, :environment_plan_usages => Hash.new { |h1,k1| h1[k1] = {} }, :deleted => Hash.new {|x,y| x[y] = {}}, :environments => {}, :features => {}, :firewalls => {}, :firewall_rules => {}, :keypairs => {}, :keypair_deployments => {}, :legacy_alerts => {}, :load_balancers => {}, :load_balancer_services => {}, :load_balancer_nodes => {}, :logs => {}, :logical_databases => {}, :memberships => {}, :messages => {}, :plan_usages => Hash.new { |h1,k1| h1[k1] = {} }, :possible_provider_locations => possible_provider_locations, :projects => {}, :providers => {}, :provider_locations => {}, :requests => {}, :servers => {}, :server_events => {}, :server_usages => Hash.new { |h1,k1| h1[k1] = {} }, :slots => {}, :slot_components => {}, :ssl_certificates => {}, :storages => {}, :storage_users => {}, :tasks => {}, :temp_files => {}, :untracked_servers => {}, :users => {}, :volumes => {}, } end end end |
.for(type, options = {}) ⇒ Object
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 |
# File 'lib/vendor/core/ey-core/client.rb', line 542 def self.for(type, ={}) case type when :server client = Ey::Core::Client::Mock.for(:user) = [:server] || {} account_name = .fetch(:account_name, SecureRandom.hex(4)) location = .fetch(:location, "us-west-2") cluster_name = .fetch(:cluster_name, SecureRandom.hex(4)) environment_name = .fetch(:environment_name, SecureRandom.hex(4)) account = client.accounts.create!(name: account_name) provider = account.providers.create!(type: :aws) environment = account.environments.create!(name: environment_name) cluster = client.clusters.create!(environment: environment, location: location, provider: provider, name: cluster_name) cluster.slots.create! cluster.cluster_updates.create!.resource! cluster.slots.first.server when :user user = Ey::Core::Client::Mock.for(:consumer).users.create!( { :name => "#{SecureRandom.hex(3)} #{SecureRandom.hex(3)}", :email => "#{SecureRandom.hex(8)}@example.org", }.merge([:user] || {}) ) Ey::Core::Client.new(token: user.token) when :consumer Ey::Core::Client.new({auth_id: SecureRandom.hex(8), auth_key: SecureRandom.hex(16)}.merge([:consumer] || {})) end end |
.reset! ⇒ Object
707 708 709 710 711 |
# File 'lib/vendor/core/ey-core/client.rb', line 707 def self.reset! @data = nil @serial_id = 1 @delay = 1 end |
Instance Method Details
#attach_address(params = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 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 |
# File 'lib/vendor/core/ey-core/requests/attach_address.rb', line 15 def attach_address(params={}) resource_id = params.delete("id") server_id = params.delete("server").to_i request_id = self.uuid server = self.find(:servers, server_id) server.merge!( "address_url" => "/addresses/#{resource_id}", ) resource = self.data[:addresses][resource_id] resource.merge!( "server_url" => "/servers/#{server_id}", ) request = { "id" => request_id, "type" => "attach_address", "successful" => "true", "started_at" => Time.now, "finished_at" => nil, "resource" => [:addresses, resource_id, resource], } self.data[:requests][request_id] = request response_hash = request.dup response_hash.delete("resource") response( :body => {"request" => response_hash}, :status => 200, :headers => { "Content-Type" => "application/json; charset=utf8" } ) end |
#authorized_channel(path) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/vendor/core/ey-core/requests/authorized_channel.rb', line 12 def (path) if task = self.data[:tasks].values.find { |t| Addressable::URI.parse(t["read_channel"]).query_values["subscription"] == path } response( :body => {"task" => task}, ) else response(status: 404, :body => {"errors" => ["Couldn't find Awsm::Task with [channel_path: #{path}]"]}) end end |
#bootstrap_logical_database(_params = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 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 |
# File 'lib/vendor/core/ey-core/requests/bootstrap_logical_database.rb', line 14 def bootstrap_logical_database(_params={}) params = Cistern::Hash.stringify_keys(_params) provider_id = resource_identity(params["provider"]) find(:providers, provider_id) logical_database_name = require_parameters(params["logical_database"], "name") request_id = self.uuid resource_id = self.uuid database_service = params["database_service"] if database_service.is_a?(Hash) require_parameters(params["database_service"], "name") database_service["id"] = self.uuid else database_service = find(:database_services, database_service) existing_database_service = true end resource = { "username" => "eyuser#{SecureRandom.hex(4)}", "password" => SecureRandom.hex(16), "name" => logical_database_name, "id" => resource_id, "resource_url" => "/logical-databases/#{resource_id}", "service" => url_for("/database-services/#{database_service.fetch("id")}"), "deleted_at" => nil, } request_resource = if existing_database_service { "resource" => [:logical_databases, resource_id, resource] } else { "resource" => [ :logical_databases, request_id, create_database_service_resource( "logical_database" => resource, "database_service" => database_service, "database_server" => params["database_server"].dup, "provider_id" => provider_id, ) ], } end request = { "id" => request_id, "type" => "bootstrap_logical_database", "successful" => "true", "started_at" => Time.now, "finished_at" => nil, "resource_url" => "/logical-databases/#{resource_id}", }.merge(request_resource) self.data[:requests][request_id] = request response_hash = request.dup response_hash.delete("resource") response( :body => {"request" => response_hash}, :status => 201, ) end |
#cancel_account(resource_id, requested_by_id) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/vendor/core/ey-core/requests/cancel_account.rb', line 13 def cancel_account(resource_id, requested_by_id) self.data[:accounts][resource_id]['cancelled_at'] = Time.now account_cancellation_id = self.uuid self.data[:accounts][resource_id]['cancellation'] = url_for("/account_cancellations/#{account_cancellation_id}") cancellation = { "id" => account_cancellation_id, "created_at" => Time.now, "kind" => "self", } self.data[:account_cancellations]||= {} self.data[:account_cancellations][account_cancellation_id] = cancellation response( :body => {"cancellation" => cancellation}, :status => 200, :headers => { "Content-Type" => "application/json; charset=utf8" } ) end |
#create_account(params = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/vendor/core/ey-core/requests/create_account.rb', line 13 def create_account(params={}) resource_id = self.uuid owner_id = params["owner"] || @current_user && @current_user["id"] find(:users, owner_id) if name_prefix = params["account"].delete("name_prefix") params["account"]["name"] = "#{name_prefix}-#{resource_id[0,4]}" end resource = mock_account_setup(resource_id, params["account"].dup) self.data[:accounts][resource_id] = resource.merge(:account_users => [owner_id], :account_owners => [owner_id]) response( :body => {"account" => resource}, :status => 201, ) end |
#create_addon(params = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/vendor/core/ey-core/requests/create_addon.rb', line 14 def create_addon(params={}) url = params.delete("url") or raise "URL needed" account_id = path_params(url)["accounts"] or raise "Need account id, not parsed from #{url}" resource_id = self.serial_id resource = params["addon"].merge( "id" => resource_id, "addon_attachments" => url_for("/accounts/#{account_id}/addons/#{resource_id}/attachments"), "account" => url_for("/accounts/#{account_id}"), "vars" => normalize_hash(params["addon"]["vars"] || {}), ) self.data[:addons][resource_id] = resource response( :body => {"addon" => resource}, :status => 201, ) end |
#create_address(params = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 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 |
# File 'lib/vendor/core/ey-core/requests/create_address.rb', line 13 def create_address(params={}) request_id = self.uuid resource_id = self.serial_id provider_id = params["provider"] self.find(:providers, provider_id) resource = params["address"].dup ip_address = self.ip_address resource.merge!( "id" => resource_id, "provisioned_id" => ip_address, "ip_address" => ip_address, "resource_url" => "/addresses/#{resource_id}", "provider" => url_for("/providers/#{provider_id}") ) request = { "id" => request_id, "type" => "provision_address", "successful" => "true", "started_at" => Time.now, "finished_at" => nil, "resource" => [:addresses, resource_id, resource], } self.data[:requests][request_id] = request response_hash = request.dup response_hash.delete("resource") response( :body => {"request" => response_hash}, :status => 201, :headers => { "Content-Type" => "application/json; charset=utf8" } ) end |
#create_alert(_params = {}) ⇒ Object
16 17 18 19 20 21 22 23 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 |
# File 'lib/vendor/core/ey-core/requests/create_alert.rb', line 16 def create_alert(_params={}) params = Cistern::Hash.stringify_keys(_params) extract_url_params!(params) database_server_id = resource_identity(params["database_server"] || params["database_server_id"]) server_id = resource_identity(params["server"] || params["server_id"]) alert_params = require_parameters(params, "alert") name, external_id, , severity = require_parameters(alert_params, *%w[name external_id message severity]) resource_id = self.uuid alert = { "id" => resource_id, "created_at" => Time.now, "updated_at" => Time.now, "deleted_at" => nil, "severity" => severity, "acknowledged" => alert_params.fetch("acknowledged", false), "ignored" => alert_params.fetch("ignored", false), "message" => , "description" => alert_params["description"], "external_id" => external_id, "name" => name, "finished_at" => alert_params["finished_at"], "started_at" => alert_params["started_at"], } alert.merge!("resource" => if database_server_id url_for("/database-servers/#{database_server_id}") elsif server_id url_for("/servers/#{server_id}") else raise response(status: 422, body: "Requires either server or database_server") end ) self.data[:alerts][resource_id] = alert response( :body => {"alert" => alert}, :status => 201, ) end |
#create_application(params = {}) ⇒ Object
16 17 18 19 20 21 22 23 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 |
# File 'lib/vendor/core/ey-core/requests/create_application.rb', line 16 def create_application(params={}) resource_id = self.serial_id url = params.delete("url") account_id = params["account"] || url && path_params(url)["accounts"] find(:accounts, account_id) resource = params["application"].dup resource.merge!( "account" => url_for("/accounts/#{account_id}"), "archives" => url_for("/applications/#{resource_id}/archives"), "keypairs" => url_for("/applications/#{resource_id}/keypairs"), "created_at" => Time.now, "updated_at" => Time.now, "id" => resource_id, ) key = mock_ssh_key keypair = { "id" => self.serial_id, "application" => url_for("/applications/#{resource_id}"), "user" => nil, "fingerprint" => key[:fingerprint], "public_key" => key[:public_key], "private_key" => key[:private_key], } self.data[:keypairs][keypair['id']] = keypair self.data[:applications][resource_id] = resource response( :body => {"application" => resource}, :status => 201, ) end |
#create_application_archive(params = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/vendor/core/ey-core/requests/create_application_archive.rb', line 17 def create_application_archive(params={}) resource_id = self.uuid url = params.delete("url") application_id = Integer(params["application"] || (url && path_params(url)["applications"])) find(:applications, application_id) resource = params["application_archive"].dup resource.merge!( "id" => resource_id, "application" => url_for("/applications/#{application_id}"), "created_at" => Time.now, "updated_at" => Time.now, "upload_successful" => false, "upload_url" => "http://example.org/#{resource_id}", "url" => "http://example.org/#{resource_id}", ) self.data[:application_archives][resource_id] = resource response( :body => {"application_archive" => resource}, :status => 201, ) end |
#create_backup(params = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/vendor/core/ey-core/requests/create_backup.rb', line 17 def create_backup(params={}) resource_id = self.uuid cluster_id = if params["url"] # provided scope path_params(params["url"])["clusters"] elsif current_server path_params(current_server["cluster"])["clusters"] end find(:clusters, cluster_id) resource = params["backup"].dup resource.merge!( "id" => resource_id, "files" => url_for("/backups/#{resource_id}/files"), "cluster" => url_for("/clusters/#{cluster_id}"), "created_at" => Time.now, "updated_at" => Time.now, ) self.data[:backups][resource_id] = resource response( :body => {"backup" => resource}, :status => 201, ) end |
#create_backup_file(params = {}) ⇒ Object
17 18 19 20 21 22 23 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 |
# File 'lib/vendor/core/ey-core/requests/create_backup_file.rb', line 17 def create_backup_file(params={}) resource_id = self.uuid unless resource = params["backup_file"].dup response(status: 422) end unless filename = resource["filename"] response(status: 422, body: {"error" => ["Missing required attribute: filename"]}) end backup_id = params["url"].split("/")[-2] uuid = self.uuid resource.merge!( "id" => resource_id, "files" => url_for("/backup_files/#{resource_id}/files"), "mime_type" => resource["mime_type"] || MIME::Types.type_for(filename).first.to_s, # these need to be the same for mocking purposes "download_url" => "http://example.org/#{uuid}", "upload_url" => "http://example.org/#{uuid}", "backup" => url_for("/backups/#{backup_id}"), "created_at" => Time.now, "updated_at" => Time.now, ) self.data[:backup_files][resource_id] = resource response( :body => {"backup_file" => resource}, :status => 201, ) end |
#create_cluster(params = {}) ⇒ Object
17 18 19 20 21 22 23 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 |
# File 'lib/vendor/core/ey-core/requests/create_cluster.rb', line 17 def create_cluster(params={}) extract_url_params!(params) environment = find(:environments, params["environment"]) resource_id = self.uuid resource = params["cluster"].dup provider_id = resource["provider"] location = resource.delete("location") provider = find(:providers, provider_id) provider_location = self.data[:provider_locations].values.find do |pl| pl["provider"] == url_for("/providers/#{provider_id}") && pl["location_id"] == location end unless provider_location return response( :status => 422, :body => {"errors" => ["Don't have access to #{location}"]}, ) end resource.merge!( "backups" => url_for("/clusters/#{resource_id}/backups"), "components" => url_for("/clusters/#{resource_id}/components"), "created_at" => Time.now, "environment" => url_for("/environments/#{environment["id"]}"), "firewalls" => url_for("/clusters/#{resource_id}/firewalls"), "id" => resource_id, "location" => {"id" => provider_location["location_id"], "name" => provider_location["name"]}, "provider" => url_for("/providers/#{provider_id}"), "servers" => url_for("/clusters/#{resource_id}/servers"), "slots" => url_for("/clusters/#{resource_id}/slots"), "updated_at" => Time.now, "updates" => url_for("/clusters/#{resource_id}/updates"), ) resource["configuration"] = normalize_hash(resource["configuration"] || {}) resource["configuration"]["version"] ||= 0 resource["configuration"]["ha_strategy"] ||= "noop" case provider["type"] when "azure" resource["configuration"]["hosted_services"] ||= [] unless resource["configuration"]["hosted_services"].first resource["configuration"]["hosted_services"] << { "name" => "#{resource_id[0..6]}-hosted-service", "endpoints" => [] } end else resource["configuration"]["firewalls"] ||= [] if default_firewall = resource["configuration"]["firewalls"].first ssh_rule = { "source" => "0.0.0.0/0", "port_range" => 22 } unless (default_firewall["rules"] || []).include? ssh_rule default_firewall["rules"] << ssh_rule end else resource["configuration"]["firewalls"] << { "name" => "#{resource_id[0..6]}-firewall", "rules" => [ { "source" => "0.0.0.0/0", "port_range" => "22", } ] } end end self.data[:clusters][resource_id] = resource response( :body => {"cluster" => resource}, :status => 201, ) end |
#create_cluster_component(params = {}) ⇒ Object
18 19 20 21 22 23 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 |
# File 'lib/vendor/core/ey-core/requests/create_cluster_component.rb', line 18 def create_cluster_component(params={}) url_params = params["url"] && path_params(params.delete("url")) cluster_id = url_params && url_params["clusters"] cluster_id ||= params.delete("cluster") find(:clusters, cluster_id) component_id = url_params && url_params["components"] component_id ||= params.delete("component") find(:components, component_id) resource_id = self.uuid resource = params["cluster_component"] configuration = resource["configuration"] = normalize_hash(resource["configuration"] || {}) if application_id = configuration["application"] find(:applications, application_id) resource.merge!("application" => url_for("/applications/#{application_id}")) end resource.merge!( "id" => resource_id, "component" => url_for("/components/#{component_id}"), "cluster" => url_for("/clusters/#{cluster_id}"), "connectors" => url_for("/cluster-components/#{resource_id}/connectors"), "tasks" => url_for("/cluster-components/#{resource_id}/tasks"), "keypairs" => url_for("/cluster-components/#{resource_id}/keypairs"), ) self.data[:cluster_components][resource_id] = resource response( :body => {"cluster_component" => resource}, :status => 201, ) end |
#create_cluster_update(params = {}) ⇒ Object
17 18 19 20 21 22 23 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 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 |
# File 'lib/vendor/core/ey-core/requests/create_cluster_update.rb', line 17 def create_cluster_update(params={}) extract_url_params!(params) request_id = self.uuid cluster_id = resource_identity(params["cluster"]) cluster_url = url_for("/clusters/#{cluster_id}") cluster = find(:clusters, cluster_id) provider_url = cluster["provider"] provider = find(:providers, provider_url) location = cluster["location"]["id"] block_device_map = [ { "mount" => "/", "file_system" => "ext4", "device" => "/dev/sda", "size" => 100, "delete_on_termination" => true, "volume_type" => "gp2", }, { "mount" => "/mnt", "file_system" => "ext4", "device" => "/dev/sdo", "delete_on_termination" => true, "size" => 100, "volume_type" => "gp2", }, { "mount" => nil, "file_system" => "swap", "device" => "/dev/sdp", "delete_on_termination" => true, "size" => 8, "volume_type" => "gp2", }, { "device" => "/dev/sdb", "name" => "ephemeral0", }, ] procedure = lambda do |_| # TODO: dependencies? unless provider["type"] == "azure" firewalls = cluster["configuration"]["firewalls"] rescue [] # create new firewalls existing_firewalls = self.data[:cluster_firewalls].inject([]) { |r, (c_id, f_id)| c_id == cluster_id ? r << self.data[:firewalls][f_id] : r } new_firewalls = firewalls.reject { |f| existing_firewalls.find {|ef| ef["name"] == f["name"] } } new_firewalls.each do |firewall| request = create_firewall({ "provider" => provider_url, "cluster" => cluster, "firewall" => { "name" => firewall["name"], }, }) get_request("id" => request.body["request"]["id"]) end # create new firewall rules firewalls.each do |firewall| firewall_id = search(self.data[:firewalls], "name" => firewall["name"]).keys.first existing_rules = search(self.data[:firewalls], "firewall" => url_for("/firewalls/#{firewall_id}")).values new_rules = firewall["rules"].reject {|r| existing_rules.detect {|er| er.port_range == r["port_range"] && er.source == r["source"] } } new_rules.each do |rule| request = create_firewall_rule({ "firewall" => firewall_id, "firewall_rule" => rule, }) get_request("id" => request.body["request"]["id"]) end end end # deprovision servers for retired slots slots = self.data[:slots].values.select{|s| next unless s["cluster"] == cluster_url if s["retired_at"] s["deleted_at"] = Time.now.to_s if server_id = resource_identity(s["server"]) self.data[:servers][server_id]["deleted_at"] = Time.now.to_s end end s["deleted_at"].nil? } # provision new servers for empty slots slots.select{|s| s["server"].nil?}.each do |slot| server_id = self.serial_id provisioned_id = self.uuid[0..6] # create server self.data[:servers][server_id] = { "alerts" => url_for("/servers/#{server_id}/alerts"), "cluster" => url_for("/clusters/#{cluster["id"]}"), "created_at" => Time.now.to_s, "deprovisioned_at" => Time.now.to_s, "devices" => block_device_map, "enabled" => true, "environment" => cluster["environment"], "events" => url_for("/servers/#{server_id}/events"), "firewalls" => url_for("/servers/#{server_id}/firewalls"), "flavor" => { "id" => slot["flavor"] }, "id" => server_id, "location" => location, "logs" => url_for("/servers/#{server_id}/logs"), "name" => slot["name"], "private_hostname" => "#{provisioned_id}.private.example.org", "provider" => provider_url, "provisioned_at" => Time.now.to_s, "provisioned_id" => provisioned_id, "public_hostname" => "#{provisioned_id}.public.example.org", "public_key" => mock_ssh_key[:fingerprint], "slot" => url_for("/slots/#{slot["id"]}"), "ssh_port" => 22, "state" => "running", "token" => SecureRandom.hex(16), "updated_at" => Time.now.to_s, "volumes" => url_for("/servers/#{server_id}/volumes"), } slot["server"] = url_for("/slots/#{slot["id"]}/server") # create volumes if volumes = slot["configuration"] && slot["configuration"]["volumes"] volumes.each do |volume| volume_id = self.serial_id self.data[:volumes][volume_id] = volume.merge({ "id" => volume_id, "location" => location, "provider" => provider_url, "provisioned_id" => "vol-#{SecureRandom.hex(4)}", "server" => url_for("/servers/#{server_id}"), }) end end end # chef log for every server slots.each do |slot| log = create_log("log" => { "filename" => "command.txt", "server" => slot["server"], }).body["log"] # hax to support searching cluster & cluster update logs self.data[:logs][log["id"]].merge!({ "_cluster" => slot["cluster"], "_cluster_update" => url_for("/cluster-updates/#{request_id}"), }) end url_for("/cluster-updates/#{request_id}") end cluster_update = { "finished_at" => nil, "id" => request_id, "started_at" => Time.now.to_s, "successful" => "true", "cluster" => cluster_url, "logs" => url_for("/cluster-updates/#{request_id}/logs"), "stage" => "activate", } request = cluster_update.merge( "resource" => [:cluster_updates, request_id, procedure], "type" => "cluster_update", ) self.data[:requests][request_id] = request self.data[:cluster_updates][request_id] = cluster_update response_hash = request.dup response_hash.delete("resource") response( :body => {"request" => response_hash}, :status => 201, :headers => { "Content-Type" => "application/json; charset=utf8" } ) end |
#create_connector(params = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/vendor/core/ey-core/requests/create_connector.rb', line 16 def create_connector(params={}) resource_id = self.uuid resource = params["connector"].dup destination_id = resource.delete("destination") source_id = resource.delete("source") resource["configuration"] = normalize_hash(resource["configuration"] || {}) key, source = find([:cluster_components, :logical_databases], source_id) dest = find(:cluster_components, destination_id) environment_url = find(:clusters, dest["cluster"])["environment"] if dest.has_key?("cluster") environment_url = find(:clusters, source["cluster"])["environment"] unless environment_url resource.merge!( "source" => url_for("/#{key}/#{source_id}"), "destination" => url_for("/cluster-components/#{destination_id}"), "id" => resource_id, "_environment" => environment_url, ) self.data[:connectors][resource_id] = resource response( :body => {"connector" => resource}, :status => 201, ) end |
#create_database_server(_params = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 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 |
# File 'lib/vendor/core/ey-core/requests/create_database_server.rb', line 14 def create_database_server(_params={}) params = Cistern::Hash.stringify_keys(_params) require_parameters(params, "provider") require_parameters(params["database_server"], "replication_source") request_id = self.uuid resource_id = self.uuid provider_id = resource_identity(params["provider"]) find(:providers, provider_id) replication_source_id = resource_identity(params["database_server"]["replication_source"]) replication_source = find(:database_servers, replication_source_id) resource = { "id" => resource_id, "resource_url" => url_for("/database-servers/#{resource_id}"), "provisioned_id" => "replica-#{SecureRandom.hex(3)}", "engine" => replication_source["engine"], "version" => replication_source["version"], "storage" => replication_source["storage"], "modifiers" => replication_source["modifiers"], "endpoint" => replication_source["endpoint"], "flavor" => replication_source["flavor"], "location" => replication_source["location"], "deleted_at" => nil, "database_service" => replication_source["database_service"], "replication_source" => url_for("/database-servers/#{replication_source_id}"), "alerts" => url_for("/database-servers/#{resource_id}/alerts"), "firewalls" => url_for("/database-servers/#{resource_id}/firewalls"), "provider" => url_for("/providers/#{provider_id}"), "messages" => url_for("/database-servers/#{resource_id}/messages"), "snapshots" => url_for("/database-servers/#{resource_id}/snapshots"), "revisions" => url_for("/database-servers/#{resource_id}/revisions"), } request = { "id" => request_id, "type" => "provision_database_server", "successful" => "true", "started_at" => Time.now, "finished_at" => nil, "resource_url" => url_for("/database-servers/#{resource_id}"), "resource" => [:database_servers, resource_id, resource], } self.data[:requests][request_id] = request response_hash = request.dup response_hash.delete("resource") response( :body => {"request" => response_hash}, :status => 201, ) end |
#create_database_service(_params = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 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 |
# File 'lib/vendor/core/ey-core/requests/create_database_service.rb', line 14 def create_database_service(_params={}) params = Cistern::Hash.stringify_keys(_params) require_parameters(params, "provider") provider_id = resource_identity(params["provider"]) find(:providers, provider_id) require_parameters(params["database_service"], "name") request_id = self.uuid resource_id = self.uuid database_service = params["database_service"].dup database_service["id"] = resource_id database_server = params["database_server"].dup database_server["storage"] ||= 50 request_block = create_database_service_resource( "database_service" => database_service, "database_server" => database_server, "provider_id" => provider_id, ) request = { "id" => request_id, "type" => "provision_database_service", "successful" => "true", "started_at" => Time.now, "finished_at" => nil, "resource_url" => database_service["resource_url"], "resource" => [:database_services, request_id, request_block], } self.data[:requests][request_id] = request response_hash = request.dup response_hash.delete("resource") response( :body => {"request" => response_hash}, :status => 201, ) end |
#create_database_service_snapshot(_params = {}) ⇒ Object
16 17 18 19 20 21 22 23 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 |
# File 'lib/vendor/core/ey-core/requests/create_database_service_snapshot.rb', line 16 def create_database_service_snapshot(_params={}) params = Cistern::Hash.stringify_keys(_params) server_or_service_id = resource_identity(params["url"]) || require_parameters(params, "database_service") database_service = if (database_server = self.data[:database_servers][server_or_service_id]) find(:database_services, resource_identity(database_server["database_service"])) else find(:database_services, database_service_id) end database_server ||= self.data[:database_servers].values.find { |ds| url_for("/database-services/#{database_service["id"]}") == ds["database_service"] } database_service_id = database_service["id"] find(:database_services, database_service_id) request_id = self.uuid resource_id = self.uuid resource = { "id" => resource_id, "created_at" => Time.now.to_s, "updated_at" => Time.now.to_s, "resource_url" => url_for("/database-server-snapshots/#{resource_id}"), "provisioned_id" => params["name"] || "rds:#{database_server["provisioned_id"]}-#{Time.now.strftime("%Y-%M-%D-%H")}", "database_server" => url_for("/database-servers/#{database_server["id"]}"), "database_service" => url_for("/database-services/#{database_service_id}"), "provider" => database_service["provider"], "provisioned_at" => Time.now.to_s, "logical_databases" => url_for("database-server-snapshots/#{resource_id}/logical-databases"), }.merge(Cistern::Hash.slice(database_server, "storage", "engine", "engine_version")) request = { "id" => request_id, "type" => "provision_database_server_snapshot", "successful" => "true", "started_at" => Time.now, "finished_at" => nil, "resource_url" => url_for("/database-server-snapshots/#{resource_id}"), "resource" => [:database_server_snapshots, resource_id, resource], } self.data[:requests][request_id] = request response_hash = request.dup response_hash.delete("resource") response( :body => {"request" => response_hash}, :status => 201, ) end |
#create_environment(params = {}) ⇒ Object
17 18 19 20 21 22 23 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 |
# File 'lib/vendor/core/ey-core/requests/create_environment.rb', line 17 def create_environment(params={}) resource_id = self.serial_id url = params.delete("url") if project_id = params["project"] || url && path_params(url)["projects"] account_id = resource_identity(find(:projects, project_id)["account"]) end account_id ||= params["account"] || url && path_params(url)["accounts"] find(:accounts, account_id) resource = params["environment"].dup internal_key = mock_ssh_key resource.merge!( "account" => url_for("/accounts/#{account_id}"), "applications" => url_for("/environments/#{resource_id}/applications"), "classic" => false, "clusters" => url_for("/environments/#{resource_id}/clusters"), "created_at" => Time.now, "database_services_url" => url_for("/environments/#{resource_id}/database-services"), "id" => resource_id, "internal_private_key" => internal_key[:private_key], "internal_public_key" => internal_key[:public_key], "keypairs" => url_for("/environments/#{resource_id}/keypairs"), "logical_databases_url" => url_for("/environments/#{resource_id}/logical-databases"), "project" => project_id && url_for("/projects/#{project_id}"), "servers" => url_for("/environments/#{resource_id}/servers"), "updated_at" => Time.now, ) self.data[:environments][resource_id] = resource response( :body => {"environment" => resource}, :status => 201, ) end |
#create_firewall(params = {}) ⇒ Object
16 17 18 19 20 21 22 23 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 |
# File 'lib/vendor/core/ey-core/requests/create_firewall.rb', line 16 def create_firewall(params={}) request_id = self.uuid resource_id = self.serial_id provider_id = resource_identity(params["provider"]) cluster_id = resource_identity(params["cluster"]) find(:providers, provider_id) cluster = find(:clusters, cluster_id) if cluster_id resource = params["firewall"].dup resource.merge!( "id" => resource_id, "provisioned_id" => SecureRandom.hex(10), "resource_url" => "/firewalls/#{resource_id}", "provider" => url_for("/providers/#{provider_id}"), "clusters" => url_for("/firewalls/#{resource_id}/clusters"), "location" => resource["location"] || cluster["location"], "rules" => url_for("/firewalls/#{resource_id}/rules"), "deleted_at" => nil, ) self.data[:cluster_firewalls] << [cluster_id, resource_id] if cluster_id request = { "id" => request_id, "type" => "provision_firewall", "successful" => "true", "started_at" => Time.now, "finished_at" => nil, "resource" => [:firewalls, resource_id, resource], } self.data[:requests][request_id] = request response_hash = request.dup response_hash.delete("resource") response( :body => {"request" => response_hash}, :status => 201, ) end |
#create_firewall_rule(params = {}) ⇒ Object
17 18 19 20 21 22 23 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 |
# File 'lib/vendor/core/ey-core/requests/create_firewall_rule.rb', line 17 def create_firewall_rule(params={}) request_id = self.uuid resource_id = self.serial_id firewall_id = resource_identity(params["firewall"]) find(:firewalls, firewall_id) source = params["firewall_rule"]["source"] or return response(status: 422, body: { "errors" => ["missing firewall rule source"] }) range = params["firewall_rule"]["port_range"] or return response(status: 422, body: { "errors" => ["missing firewall rule port_range"] }) resource = { "id" => resource_id, "source" => source.to_s, "port_range" => range.to_s, "firewall" => url_for("/firewalls/#{firewall_id}"), "resource_url" => "/firewall-rules/#{resource_id}", } request = { "id" => request_id, "type" => "provision_firewall_rule", "successful" => "true", "started_at" => Time.now, "finished_at" => nil, "resource" => [:firewall_rules, resource_id, resource], } self.data[:requests][request_id] = request response_hash = request.dup response_hash.delete("resource") response( :body => {"request" => response_hash}, :status => 201, :headers => { "Content-Type" => "application/json; charset=utf8" } ) end |
#create_keypair(params = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/vendor/core/ey-core/requests/create_keypair.rb', line 16 def create_keypair(params={}) unless current_user return response(status: 403) end unless params["keypair"]["public_key"] return response(status: 422) end resource_id = self.serial_id resource = { "id" => resource_id, "application" => nil, "fingerprint" => mock_ssh_key[:fingerprint], "user" => url_for("/users/#{current_user["id"]}"), }.merge!(params["keypair"]) self.data[:keypairs][resource_id] = resource response( :body => {"keypair" => resource}, :status => 201, ) end |
#create_keypair_deployment(params = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/vendor/core/ey-core/requests/create_keypair_deployment.rb', line 17 def create_keypair_deployment(params={}) resource_id = self.serial_id keypair_id = params["keypair"] environment_id = params["environment"] resource = { "id" => resource_id, "keypair" => url_for("/keypairs/#{keypair_id}"), "target" => url_for("/environments/#{environment_id}"), } self.data[:keypair_deployments][resource_id] = resource response( :body => {"keypair_deployment" => resource}, :status => 201, ) end |
#create_load_balancer(params = {}) ⇒ Object
16 17 18 19 20 21 22 23 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 |
# File 'lib/vendor/core/ey-core/requests/create_load_balancer.rb', line 16 def create_load_balancer(params={}) request_id = self.uuid resource_id = self.serial_id provider_id = params.delete("provider") firewall_id = params.delete("firewall") find(:providers, provider_id) find(:firewalls, firewall_id) if firewall_id resource = params["load_balancer"].dup resource.merge!( "id" => resource_id, "provisioned_id" => SecureRandom.hex(10), "resource_url" => "/load_balancers/#{resource_id}", "provider" => url_for("/providers/#{provider_id}"), "location" => resource["location"], "name" => resource["name"], ) resource.merge!("firewall" => url_for("/firewalls/#{firewall_id}")) if firewall_id request = { "id" => request_id, "type" => "provision_load_balancer", "successful" => true, "started_at" => Time.now, "finished_at" => nil, "resource" => [:load_balancers, resource_id, resource], } self.data[:requests][request_id] = request self.data[:load_balancers][resource_id] = resource response_hash = request.dup response_hash.delete("resource") response( :body => {"request" => response_hash}, :status => 201, :headers => { "Content-Type" => "application/json; charset=utf8", } ) end |
#create_log(params = {}) ⇒ Object
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 |
# File 'lib/vendor/core/ey-core/requests/create_log.rb', line 27 def create_log(params={}) log_id = self.uuid log_params = params["log"] filename = log_params["filename"] log = { "id" => log_id, "filename" => filename, "download_url" => "http://s3.amazon.com/#{filename}", "uplaod_url" => nil, "created_at" => Time.now, "updated_at" => Time.now, "deleted_at" => nil, "mime_type" => params[:mime_type] || "application/json", "component_action" => nil, # @fixme support genuine component actions "server" => params["server"], } self.data[:logs][log_id] = log response( :body => {"log" => log}, :status => 201 ) end |
#create_logical_database(_params = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 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 |
# File 'lib/vendor/core/ey-core/requests/create_logical_database.rb', line 14 def create_logical_database(_params={}) params = Cistern::Hash.stringify_keys(_params) database_service_id = resource_identity(params["url"]) || require_parameters(params, "database_service") logical_database_name = require_parameters(params["logical_database"], "name") request_id = self.uuid resource_id = self.serial_id find(:database_services, database_service_id) resource = { "name" => logical_database_name, "username" => "eyuser#{SecureRandom.hex(4)}", "password" => SecureRandom.hex(16), }.merge(params["logical_database"]).merge( "id" => resource_id, "resource_url" => "/logical-databases/#{resource_id}", "service" => url_for("/database-services/#{database_service_id}"), "deleted_at" => nil, ) request = { "id" => request_id, "type" => "provision_logical_database", "successful" => "true", "started_at" => Time.now, "finished_at" => nil, "resource_url" => resource["resource_url"], "resource" => [:logical_databases, resource_id, resource], } self.data[:requests][request_id] = request response_hash = request.dup response_hash.delete("resource") response( :body => {"request" => response_hash}, :status => 201, ) end |
#create_membership(params = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/vendor/core/ey-core/requests/create_membership.rb', line 16 def create_membership(params={}) id = self.uuid membership = { "id" => id, "account" => url_for("/accounts/"+params["membership"]["account"]), "user" => url_for("/users/"+params["membership"]["user"]), "role" => params["membership"]["role"], #NOTE missing attributes: email, created_at, updated_at, deleted_at, requester_url #also "implied" attribute: accepted = false } self.data[:memberships][id] = membership response( :body => {"membership" => membership}, :status => 201 ) end |
#create_message(_params = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/vendor/core/ey-core/requests/create_message.rb', line 15 def (_params={}) params, _ = require_arguments(_params, "url") extract_url_params!(params) = self.uuid params.merge!( "id" => , "created_at" => Time.now, ) self.data[:messages][] = params response( :body => {"message" => params}, :status => 201, ) end |
#create_provider(params = {}) ⇒ Object
23 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 |
# File 'lib/vendor/core/ey-core/requests/create_provider.rb', line 23 def create_provider(params={}) resource_id = self.serial_id request_id = self.uuid account_id = params["account"] url = params.delete("url") account_id ||= url && path_params(url)["accounts"] find(:accounts, account_id) provider_params = params["provider"] provider = { "account" => url_for("/accounts/#{account_id}"), "id" => resource_id, "resource_url" => url_for("/providers/#{resource_id}"), "provider_locations" => url_for("/providers/#{resource_id}/locations"), "storages" => url_for("/providers/#{resource_id}/storages"), "servers" => url_for("/providers/#{resource_id}/servers"), "untracked_servers" => url_for("/providers/#{resource_id}/untracked-servers"), "provisioned_id" => provider_params["provisioned_id"] || SecureRandom.uuid, "created_at" => Time.now, "updated_at" => Time.now, "type" => provider_params["type"].to_s, "credentials" => provider_params["credentials"], "shared" => provider_params.fetch(:shared, false), } unless ["aws", "azure"].include?(provider["type"]) response(status: 422, body: {"errors" => ["Unknown provider type: #{provider["type"]}"]}) end self.data[:possible_provider_locations][provider["type"].to_s].each do |location| provider_location_id = self.uuid provider_location = { "id" => provider_location_id, "location_id" => location["id"], "provider" => url_for("/providers/#{resource_id}"), "name" => location["name"], "data" => {}, } self.data[:provider_locations][provider_location_id] = provider_location end request = provider.merge( "resource" => [:providers, resource_id, provider], "type" => "provider", "started_at" => Time.now, "finished_at" => nil, "successful" => "true", "id" => request_id, ) self.data[:requests][request_id] = request response_hash = request.dup response_hash.delete("resource") response( :body => {"request" => response_hash}, :status => 201, :headers => { "Content-Type" => "application/json; charset=utf8" } ) end |
#create_slots(params = {}) ⇒ Object
17 18 19 20 21 22 23 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 |
# File 'lib/vendor/core/ey-core/requests/create_slots.rb', line 17 def create_slots(params={}) extract_url_params!(params) cluster = find(:clusters, params["cluster"]) cluster_url = url_for("/clusters/#{cluster["id"]}") slots = params["slots"] if slots["names"] && slots["quantity"] return response( status: 422, body: { errors: ["cannot accept both 'names' and 'quantity' params"] } ) end quantity = slots.delete("quantity") || 1 names = slots.delete("names") || quantity.times.map { self.uuid[0..6] } unless names.kind_of?(Array) return response( status: 422, body: { errors: ["slots[names] parameter must be an array"] } ) end resources = names.map do |name| resource_id = self.uuid resource = params["slots"].dup resource["flavor"] ||= "medium_64" resource["volumes"] ||= [] resource["image"] ||= nil resource.merge!( "id" => resource_id, "name" => name, "cluster" => cluster_url, "components" => url_for("/slots/#{resource_id}/components"), "configuration" => { "volumes" => [] }, "disabled" => false, "retired" => false, "deleted_at" => nil, "created_at" => Time.now, "updated_at" => Time.now, ) if volume_config = cluster["configuration"] && cluster["configuration"]["slot"] && cluster["configuration"]["slot"]["volumes"] resource["configuration"]["volumes"] += volume_config resource["configuration"]["volumes"].uniq! end # find all the cluster_components for this cluster cluster_components = self.data[:cluster_components].select do |_,cluster_component| cluster_component["cluster"] == cluster_url end # bootstrap a slot_component for each cluster_component cluster_components.each do |_,cc| slot_component_id = self.uuid self.data[:slot_components][slot_component_id] = { "id" => slot_component_id, "created_at" => Time.now, "updated_at" => Time.now, "deleted_at" => nil, "configuration" => deep_dup(cc["configuration"]), "name" => cc["name"], "slot" => url_for("/slots/#{resource_id}"), "cluster_component" => url_for("/cluster_components/#{cc['id']}"), "component" => cc["component"], "_cluster" => cluster_url, "_environment" => cluster["environment"], } end self.data[:slots][resource_id] = resource end response( :body => {"slots" => resources}, :status => 201, ) end |
#create_ssl_certificate(params = {}) ⇒ Object
17 18 19 20 21 22 23 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 |
# File 'lib/vendor/core/ey-core/requests/create_ssl_certificate.rb', line 17 def create_ssl_certificate(params={}) url = params.delete("url") account_id = params["account"] || url && path_params(url)["accounts"] find(:accounts, account_id) resource_id = self.uuid resource = params["ssl_certificate"].dup if resource.delete("self_sign") key = OpenSSL::PKey::RSA.new(1024) name = OpenSSL::X509::Name.parse("/CN=example.org") # NB: the order in which these attributes are set seems to be # important in making it self-signed and not just a certificate # with a mystery issuer. It's not clear which attributes have # the ordering requirement. cert = OpenSSL::X509::Certificate.new cert.version = 2 cert.serial = Time.now.tv_sec # monotonically increasing cert.not_before = Time.now - (7 * 24 * 60 * 60) # allow for plenty of clock skew cert.not_after = Time.now + (10 * 356 * 24 * 60 * 60) # allow for plenty of clock skew cert.subject = name cert.public_key = key.public_key cert.issuer = name cert.sign(key, OpenSSL::Digest::SHA1.new) resource["public_certificate"] = cert.to_pem resource["private_key"] = key.to_pem resource["self_signed"] = true elsif ! resource['public_certificate'] or ! resource['private_key'] return response(status: 422, body: {"errors" => ["public_certificate and private_key must not be blank."]}) end resource.merge!( "account" => url_for("/accounts/#{account_id}"), "created_at" => Time.now, "id" => resource_id, "updated_at" => Time.now, "resource_url" => url_for("/ssl_certificates/#{resource_id}"), ) request = { "account" => url_for("/accounts/#{account_id}"), "created_at" => Time.now, "finished_at" => nil, "id" => self.uuid, "message" => nil, "read_channel" => nil, "resource" => [:ssl_certificates, resource_id, resource], "started_at" => Time.now, "successful" => true, "type" => "provision_ssl_certificate", "updated_at" => Time.now, } self.data[:requests][request["id"]] = request response( :body => {"request" => request}, :status => 201 ) end |
#create_storage(params = {}) ⇒ Object
17 18 19 20 21 22 23 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 |
# File 'lib/vendor/core/ey-core/requests/create_storage.rb', line 17 def create_storage(params={}) extract_url_params!(params) request_id = self.uuid resource_id = self.uuid provider_id = resource_identity(params["provider"]) provider_url = url_for("/providers/#{provider_id}") provider = find(:providers, provider_id) resource = params["storage"].dup resource.merge!({ "id" => resource_id, "name" => resource["name"], "location" => resource["location"], "provisioned_id" => self.uuid, "provider" => provider_url, "storage_users_url" => url_for("/storages/#{resource_id}"), "resource_url" => "/storages/#{resource_id}" }) request = { "id" => request_id, "type" => "provision_provider_storage", "successful" => true, "started_at" => Time.now, "finished_at" => nil, "resource" => [:storages, resource_id, resource], } self.data[:requests][request_id] = request self.data[:storages][resource_id] = resource response_hash = request.dup response_hash.delete("resource") response( :body => {"request" => response_hash}, :status => 201, :headers => { "Content-Type" => "application/json; charset=utf8", } ) end |
#create_storage_user(params = {}) ⇒ Object
17 18 19 20 21 22 23 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 |
# File 'lib/vendor/core/ey-core/requests/create_storage_user.rb', line 17 def create_storage_user(params={}) extract_url_params!(params) request_id = self.uuid resource_id = self.uuid storage_id = resource_identity(params["storage"]) storage_url = url_for("/storages/#{storage_id}") storage = find(:storages, storage_id) resource = params["storage_user"].dup resource.merge!({ "id" => resource_id, "username" => resource["username"], "provisioned_id" => self.uuid, "access_id" => SecureRandom.hex(16), "secret_key" => SecureRandom.hex(32), "storage" => storage_url, "resource_url" => "/storages/#{storage_id}/storage-users/#{resource_id}" }) request = { "id" => request_id, "type" => "provision_provider_storage_credential", "successful" => true, "started_at" => Time.now, "finished_at" => nil, "resource" => [:storage_users, resource_id, resource], } self.data[:requests][request_id] = request self.data[:storage_users][resource_id] = resource response_hash = request.dup response_hash.delete("resource") response( :body => {"request" => response_hash}, :status => 201, :headers => { "Content-Type" => "application/json; charset=utf8", } ) end |
#create_task(params = {}) ⇒ Object
17 18 19 20 21 22 23 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 |
# File 'lib/vendor/core/ey-core/requests/create_task.rb', line 17 def create_task(params={}) request_id = self.uuid resource_id = self.uuid url = params["url"] cluster_component_id = url && path_params(url)["cluster_components"] cluster_component_id ||= params.delete("cluster_component") self.find(:cluster_components, cluster_component_id) task = { "finished_at" => nil, "id" => request_id, "started_at" => Time.now, "successful" => true, "read_channel" => "https://messages.engineyard.com/stream?subscription=/tasks/#{request_id[0..7]}&token=#{SecureRandom.hex(6)}", "cluster_component" => url_for("/cluster-components/#{cluster_component_id}"), } request = task.merge( "resource" => [:tasks, resource_id, task], "type" => "task", "finished_at" => nil, "successful" => nil, ) self.data[:requests][request_id] = request self.data[:tasks][request_id] = task response_hash = request.dup response_hash.delete("resource") response( :body => {"request" => response_hash}, :status => 201, ) end |
#create_token(params = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/vendor/core/ey-core/requests/create_token.rb', line 14 def create_token(params={}) response( :body => {"token" => {"auth_id" => self.uuid}}, :status => 201, :headers => { "Content-Type" => "application/json; charset=utf8" } ) end |
#create_untracked_server(params = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/vendor/core/ey-core/requests/create_untracked_server.rb', line 14 def create_untracked_server(params={}) resource_id = self.serial_id url = params["url"] provider_id ||= params["provider"] || (url && path_params(url)["providers"]) find(:providers, provider_id) resource = params["untracked_server"].dup require_parameters(resource, "location", "provisioned_id", "provisioner_id") resource.merge!( "provider" => url_for("/providers/#{provider_id}"), "id" => resource_id, ) self.data[:untracked_servers][resource_id] = resource response( :body => { "untracked_server" => resource }, :status => 201, ) end |
#create_user(params = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/vendor/core/ey-core/requests/create_user.rb', line 14 def create_user(params={}) if self.authentication != :hmac response(status: 403) end if self.data[:users].map{ |_, user| user["email"] }.include?(params["user"]["email"]) response( :status => 422, :body => { :errors => ["Email has already been taken"] } ) end resource_id = self.uuid resource = params["user"].dup resource["token"] = SecureRandom.hex(20) resource.merge!({ "id" => resource_id, "accounts" => url_for("/users/#{resource_id}/accounts"), "memberships" => url_for("/users/#{resource_id}/memberships"), "keypairs" => url_for("/users/#{resource_id}/keypairs"), }) self.data[:users][resource_id] = resource response( :body => {"user" => resource}, :status => 201, ) end |
#current_user ⇒ Hash
Lazily re-seeds data after reset
764 765 766 767 768 769 770 |
# File 'lib/vendor/core/ey-core/client.rb', line 764 def current_user if @current_user self.data[:users][@current_user["id"]] ||= @current_user @current_user end end |
#data ⇒ Object
717 718 719 |
# File 'lib/vendor/core/ey-core/client.rb', line 717 def data self.class.data[self.url] end |
#delay ⇒ Object
713 714 715 |
# File 'lib/vendor/core/ey-core/client.rb', line 713 def delay self.class.delay end |
#destroy_addon(params = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/vendor/core/ey-core/requests/destroy_addon.rb', line 13 def destroy_addon(params={}) extract_url_params!(params) find(:accounts, params["account"]) addon = find(:addons, params["addon"]) addon["deleted_at"] = Time.now response(status: 204) end |
#destroy_cluster(id) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/vendor/core/ey-core/requests/destroy_cluster.rb', line 12 def destroy_cluster(id) request_id = self.uuid self.data[:requests][request_id] = { "id" => request_id, "finished_at" => nil, "successful" => "true", "started_at" => Time.now, "resource" => [:clusters, id, self.data[:clusters][id].merge("deleted_at" => Time.now)], "type" => "deprovision_cluster", } response( :body => {"request" => {id: request_id}}, :status => 201, ) end |
#destroy_database_server(params = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/vendor/core/ey-core/requests/destroy_database_server.rb', line 16 def destroy_database_server(params={}) extract_url_params!(params) request_id = self.uuid database_server_id = params["id"] || params["database_server"] database_server = self.find(:database_servers, database_server_id) request = { "resource" => [:database_servers, database_server_id, database_server.merge("deleted_at" => Time.now)], "type" => "deprovision_database_server", "started_at" => Time.now, "finished_at" => nil, "successful" => "true", "id" => request_id, } self.data[:requests][request_id] = request response( :body => {"request" => {id: request_id}}, :status => 201, ) end |
#destroy_database_service(params = {}) ⇒ Object
16 17 18 19 20 21 22 23 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 |
# File 'lib/vendor/core/ey-core/requests/destroy_database_service.rb', line 16 def destroy_database_service(params={}) extract_url_params!(params) request_id = self.uuid database_service_id = params["id"] || params["database_service"] database_service = self.find(:database_services, database_service_id) request = { "finished_at" => nil, "id" => request_id, "started_at" => Time.now, "successful" => "true", "type" => "deprovision_database_service", "resource" => [:database_services, database_service_id, lambda do |r| database_service.merge!("deleted_at" => Time.now) self.data[:database_servers].values. select { |ds| ds["database_service"] == url_for("/database-services/#{database_service["id"]}") }. each { |ds| self.data[:database_server_firewalls].select { |ds_id, _| ds["id"] == ds_id }. each { |_, f_id| self.data[:firewalls][f_id].merge!("deleted_at" => Time.now) } }. each { |ds| ds["deleted_at"] = Time.now } self.data[:logical_databases].values. select { |ds| ds["service"] == url_for("/database-services/#{database_service["id"]}") }. each { |ds| ds["deleted_at"] = Time.now } r.delete("resource_url") end], } self.data[:requests][request_id] = request response( :body => {"request" => {id: request_id}}, :status => 201, ) end |
#destroy_environment(params = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/vendor/core/ey-core/requests/destroy_environment.rb', line 16 def destroy_environment(params={}) request_id = self.uuid url = params.delete("url") environment_id = params["id"] || url && url.split('/').last environment = self.data[:environments][environment_id].dup environment["deleted_at"] = Time.now environment["resource_url"] = url_for("/environments/#{environment_id}") # @todo use a procedure to deprovision clusters as well self.data[:requests][request_id] = { "id" => request_id, "finished_at" => nil, "successful" => "true", "started_at" => Time.now, "resource" => [:environments, environment_id, environment], "type" => "deprovision_environment", } response( :body => {"request" => {id: request_id}}, :status => 201, ) end |
#destroy_firewall(params = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/vendor/core/ey-core/requests/destroy_firewall.rb', line 16 def destroy_firewall(params={}) extract_url_params!(params) request_id = self.uuid firewall_id = params["id"] || params["firewall"] firewall = self.find(:firewalls, firewall_id) request = { "type" => "deprovision_firewall", "started_at" => Time.now, "finished_at" => nil, "successful" => "true", "id" => request_id, } self.data[:requests][request_id] = request.merge( "resource" => [:firewalls, firewall_id, firewall.merge("deleted_at" => Time.now)], ) response( :body => {"request" => request}, ) end |
#destroy_firewall_rule(params = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/vendor/core/ey-core/requests/destroy_firewall_rule.rb', line 16 def destroy_firewall_rule(params={}) extract_url_params!(params) request_id = self.uuid firewall_rule_id = params["id"] || params["firewall_rule"] firewall_rule = self.find(:firewall_rules, firewall_rule_id) request = { "type" => "deprovision_firewall_rule", "started_at" => Time.now, "finished_at" => nil, "successful" => "true", "id" => request_id, } self.data[:requests][request_id] = request.merge( "resource" => [:firewall_rules, firewall_rule_id, firewall_rule.merge("deleted_at" => Time.now)], ) response( :body => {"request" => request}, ) end |
#destroy_load_balancer(params = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/vendor/core/ey-core/requests/destroy_load_balancer.rb', line 16 def destroy_load_balancer(params={}) request_id = self.uuid url = params.delete("url") load_balancer_id = params["id"] || url && url.split('/').last self.data[:load_balancers][load_balancer_id]["deleted_at"] = Time.now response( :body => {"request" => {id: request_id}}, :status => 201, ) end |
#destroy_logical_database(params = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/vendor/core/ey-core/requests/destroy_logical_database.rb', line 16 def destroy_logical_database(params={}) extract_url_params!(params) request_id = self.uuid logical_database_id = params["id"] || params["logical_database"] logical_database = self.find(:logical_databases, logical_database_id) request = { "resource" => [:logical_databases, logical_database_id, logical_database.merge("deleted_at" => Time.now)], "type" => "deprovision_logical_database", "started_at" => Time.now, "finished_at" => nil, "successful" => "true", "id" => request_id, } self.data[:requests][request_id] = request response( :body => {"request" => {id: request_id}}, :status => 201, ) end |
#destroy_provider(id) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/vendor/core/ey-core/requests/destroy_provider.rb', line 12 def destroy_provider(id) provider = self.data[:providers][id].dup request_id = self.uuid provider["cancelled_at"] = Time.now provider["resource_url"] = url_for("/providers/#{id}") self.data[:requests][request_id] = { "id" => request_id, "finished_at" => nil, "successful" => "true", "started_at" => Time.now, "resource" => [:providers, id, provider], "type" => "cancel_provider", } response( :body => {"request" => {id: request_id}}, :status => 201, ) end |
#destroy_server(id) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/vendor/core/ey-core/requests/destroy_server.rb', line 12 def destroy_server(id) deprovision_procedure = lambda do |_| server = self.data[:servers][id] server.merge!("deleted_at" => Time.now, "deprovisioned_at" => Time.now) if slot_id = resource_identity(server["slot"]) self.data[:slots][slot_id]["server"] = nil end self.data[:volumes].values.select {|v| v["server"] == url_for("/servers/#{id}") }.each do |volume| volume.merge!("deleted_at" => Time.now) end nil end request_id = self.uuid self.data[:requests][request_id] = { "id" => request_id, "finished_at" => nil, "successful" => "true", "started_at" => Time.now, "resource" => [:servers, id, deprovision_procedure], "type" => "deprovision_server", } response( :body => {"request" => {id: request_id}}, :status => 201, ) end |
#destroy_ssl_certificate(params = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/vendor/core/ey-core/requests/destroy_ssl_certificate.rb', line 16 def destroy_ssl_certificate(params={}) url = params.delete("url") ssl_certificate_id = params["id"] || url_params(url)["ssl_certificates"] self.data[:ssl_certificates][ssl_certificate_id]["deleted_at"] = Time.now response( :body => nil, :status => 204, ) end |
#destroy_storage(id) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/vendor/core/ey-core/requests/destroy_storage.rb', line 12 def destroy_storage(id) request_id = self.uuid self.data[:requests][request_id] = { "id" => request_id, "type" => "deprovision_provider_storage", "successful" => true, "started_at" => Time.now, "finished_at" => nil, "resource" => [:storages, id, self.data[:storages][id].merge("deleted_at" => Time.now)], } response( :body => {"request" => {id: request_id}}, :status => 201, :headers => { "Content-Type" => "application/json; charset=utf8", } ) end |
#destroy_storage_user(params = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/vendor/core/ey-core/requests/destroy_storage_user.rb', line 14 def destroy_storage_user(params={}) storage_id = params.delete("storage") id = params.delete("id") request_id = self.uuid self.data[:requests][request_id] = { "id" => request_id, "type" => "deprovision_provider_storage_user", "successful" => true, "started_at" => Time.now, "finished_at" => nil, "resource" => [:storage_users, id, self.data[:storage_users][id].merge("deleted_at" => Time.now)], } response( :body => {"request" => {id: request_id}}, :status => 201, :headers => { "Content-Type" => "application/json; charset=utf8", } ) end |
#destroy_user(params = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/vendor/core/ey-core/requests/destroy_user.rb', line 16 def destroy_user(params={}) url = params.delete("url") user_id = params["id"] || url && url.split('/').last self.data[:users][user_id]["deleted_at"] = Time.now response( :body => nil, :status => 204, ) end |
#detach_address(params = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/vendor/core/ey-core/requests/detach_address.rb', line 14 def detach_address(params={}) resource_id = params.delete("id") request_id = self.uuid resource = self.data[:addresses][resource_id] server_id = resource["server_url"].split("/").last.to_i server = self.data[:servers][server_id] server["address_url"] = nil resource["server_url"] = nil request = { "id" => request_id, "type" => "detach_address", "successful" => "true", "started_at" => Time.now, "finished_at" => nil, "resource" => [:addresses, resource_id, resource], } self.data[:requests][request_id] = request response_hash = request.dup response_hash.delete("resource") response( :body => {"request" => response_hash}, :status => 200, :headers => { "Content-Type" => "application/json; charset=utf8" } ) end |
#disable_feature(params = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/vendor/core/ey-core/requests/disable_feature.rb', line 15 def disable_feature(params={}) account_id = params["account"] feature_id = params["feature"]["id"] account = find(:accounts, account_id) feature = find(:features, feature_id) feature["account"] = nil response( :body => nil, :status => 200 ) end |
#discover_database_server(params = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 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 |
# File 'lib/vendor/core/ey-core/requests/discover_database_server.rb', line 14 def discover_database_server(params={}) request_id = self.uuid resource_id = self.uuid id = params["id"] database_server = self.data[:database_servers][id] old_flavor = database_server["flavor"] new_flavor = %w(db.m3.medium db.m3.large db.m3.xlarge db.m3.2xlarge) - [old_flavor] revisions = self.data[:database_server_revisions][id] unless revisions database_server["flavor"] = new_flavor self.data[:database_servers][id] = database_server revision = { "id" => resource_id, "database_server" => url_for("/database-servers/#{id}"), "revision_time" => Time.now, "data" => { "flavor" => { "old" => old_flavor, "new" => new_flavor, }, }, } self.data[:database_server_revisions][id] = revision end request = { "id" => request_id, "type" => "discover_database_server", "successful" => true, "started_at" => Time.now, "finished_at" => nil, "resource" => [:database_servers, id, database_server], } self.data[:requests][request_id] = request response_hash = request.dup response_hash.delete("resource") response( :body => {"request" => response_hash}, :status => 200, :headers => { "Content-Type" => "application/json; charset=utf8" } ) end |
#discover_database_server_snapshots(params = {}) ⇒ Object
17 18 19 20 21 22 23 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 |
# File 'lib/vendor/core/ey-core/requests/discover_database_server_snapshots.rb', line 17 def discover_database_server_snapshots(params={}) extract_url_params!(params) provider = params.delete('provider') resource_id = self.uuid request_id = self.uuid provider_url = url_for("/providers/#{provider}") existing_snapshots = self.data[:database_server_snapshots].values.select { |dss| dss["provider"] == provider_url } database_server = self.data[:database_servers].values.detect { |ds| ds["provider"] == provider_url } resources = if existing_snapshots.empty? if database_server [{ "id" => resource_id, "location" => database_server["location"], "engine" => database_server["engine"], "engine_version" => database_server["version"], "storage" => database_server["storage"], "provisioned_id" => resource_id, "provisioned_at" => Time.now - 3600, "provider" => provider_url, "database_server" => url_for("/database-servers/#{database_server["id"]}") }] else [] end else existing_snapshots end request = { "id" => request_id, "type" => "discover_database_server_snapshots", "successful" => true, "started_at" => Time.now, "finished_at" => nil, "resource" => [:database_server_snapshots, resource_id, resources, "providers/#{provider}/database-server-snapshots"] } self.data[:requests][request_id] = request response_hash = request.dup response_hash.delete("resource") response( :body => {"request" => response_hash}, :status => 200, :headers => { "Content-Type" => "application/json; charset=utf8" } ) end |
#discover_provider_location(url, location_id) ⇒ Object
15 16 17 18 19 20 21 22 23 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 |
# File 'lib/vendor/core/ey-core/requests/discover_provider_location.rb', line 15 def discover_provider_location(url, location_id) resource_id = self.uuid request_id = self.uuid provider_id = url.split("/")[-2] provider = self.data[:providers][provider_id.to_i] type = provider["type"] possible_location = self.data[:possible_provider_locations][type].detect { |l| l["id"] == location_id } resource = { "id" => resource_id, "provider" => url_for("/providers/#{provider_id}"), "location_id" => location_id, "location_name" => possible_location["name"], "resource_url" => "/provider_locations/#{resource_id}" } self.data[:provider_locations][resource_id] = resource request = { "id" => request_id, "type" => "discover_provider_location", "successful" => "true", "started_at" => Time.now, "finished_at" => nil, "resource" => [:provider_locations, resource_id, resource], } self.data[:requests][request_id] = request response_hash = request.dup response_hash.delete("resource") response( :body => {"request" => response_hash}, :status => 200, :headers => { "Content-Type" => "application/json; charset=utf8" } ) end |
#download_file(params = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/vendor/core/ey-core/requests/download_file.rb', line 14 def download_file(params={}) url = params["url"] body = File.read(self.data[:temp_files][url]) response( :body => body, :status => 200, ) end |
#enable_feature(params = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/vendor/core/ey-core/requests/enable_feature.rb', line 15 def enable_feature(params={}) account_id = params["account"] resource_id = params["feature"]["id"] account = self.data[:accounts][account_id] feature = self.data[:features][resource_id] account_url = url_for("/accounts/#{account_id}") feature["account"] = account_url response( :body => {"feature" => { "id" => feature[:id], "name" => feature[:name], "description" => feature[:description]} }, :status => 200 ) end |
#finish_backup(params = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/vendor/core/ey-core/requests/finish_backup.rb', line 14 def finish_backup(params={}) backup = find(:backups, resource_identity(params)) backup["finished_at"] ||= Time.now backup["finished"] = true response( :body => {"backup" => backup}, :status => 200, ) end |
#get_account(params = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/vendor/core/ey-core/requests/get_account.rb', line 15 def get_account(params={}) identity = resource_identity(params) account = self.find(:accounts, identity) resource = account.dup resource.delete(:users) resource.delete(:owners) response( :body => {"account" => resource}, ) end |
#get_account_cancellation(params = {}) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/vendor/core/ey-core/requests/get_account_cancellation.rb', line 12 def get_account_cancellation(params={}) identity = resource_identity(params) cancellation = self.find(:account_cancellations, identity) response( :body => {"cancellation" => cancellation}, ) end |
#get_account_referrals(params = {}) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/vendor/core/ey-core/requests/get_account_referrals.rb', line 12 def get_account_referrals(params={}) extract_url_params!(params) if params["account"] params["referrer"] = params.delete("account") end headers, account_referrals_page = search_and_page(params, :account_referrals, search_keys: %w[referrer]) response( :body => {"account_referrals" => account_referrals_page}, :status => 200, :headers => headers ) end |
#get_account_trial(params = {}) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/vendor/core/ey-core/requests/get_account_trial.rb', line 12 def get_account_trial(params={}) account_id = resource_identity(params) find(:accounts, account_id) resource = { "id" => Cistern::Mock.random_numbers(4), "duration" => 500, "used" => 30, "created_at" => Time.now.to_s, "account" => url_for("/accounts/#{account_id}") } response( :body => {"account_trial" => resource}, :status => 200, ) end |
#get_accounts(params = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/vendor/core/ey-core/requests/get_accounts.rb', line 16 def get_accounts(params={}) extract_url_params!(params) user_id = if user_url = params.delete("user") user_url.split('/').last end resources = if user_id find(:users, user_id) self.data[:accounts].select{|k,v| v[:account_users] && v[:account_users].include?(user_id)} else self.data[:accounts] end #No need for mock to try and replicate the behavior of active_in_month, but does need to allow it and not get in the way params.delete("active_in_month") headers, accounts_page = search_and_page(params, :accounts, search_keys: %w[name id legacy_id], resources: resources) response( :body => {"accounts" => accounts_page}, :status => 200, :headers => headers ) end |
#get_addon(params = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/vendor/core/ey-core/requests/get_addon.rb', line 13 def get_addon(params={}) extract_url_params!(params) self.find(:accounts, params["account"]) addon = self.find(:addons, params["addon"]) response( :body => {"addon" => addon}, ) end |
#get_addon_attachment(params = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/vendor/core/ey-core/requests/get_addon_attachment.rb', line 13 def (params={}) extract_url_params!(params) account = find(:accounts, params["account"]) addon = find(:addons, params["addon"]) = resource_identity(params["attachment"]) = (account["id"], addon["name"]) if = .find{|| ['id'] == } response( :body => {"addon_attachment" => }, :status => 200, ) else response(status: 400) end end |
#get_addon_attachments(params = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/vendor/core/ey-core/requests/get_addon_attachments.rb', line 17 def (params={}) if account_id = params.delete("account_id") params["url"] = "/accounts/#{account_id}/attachments" end extract_url_params!(params) account = find(:accounts, params["account"]) addon = find(:addons, params["addon"]) rescue nil = (account["id"], addon && addon["name"]) if addon .select! {|a| a["key"] } end response( :body => {"addon_attachments" => }, :status => 201, :headers => { "Content-Type" => "application/json; charset=utf8" } ) end |
#get_addons(params = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/vendor/core/ey-core/requests/get_addons.rb', line 13 def get_addons(params={}) extract_url_params!(params) headers, addons_page = search_and_page(params, :addons, search_keys: %w[account id name]) response( :body => {"addons" => addons_page}, :headers => headers ) end |
#get_address(params = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/vendor/core/ey-core/requests/get_address.rb', line 15 def get_address(params={}) identity = resource_identity(params) address = self.data[:addresses][identity] response( :body => {"address" => address}, ) end |
#get_addresses(params = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/vendor/core/ey-core/requests/get_addresses.rb', line 16 def get_addresses(params={}) extract_url_params!(params) headers, addresses_page = search_and_page(params, :addresses, search_keys: %w[provisioned_id ip_address server location]) response( :body => {"addresses" => addresses_page}, :headers => headers ) end |
#get_alert(params = {}) ⇒ Object
15 16 17 18 19 |
# File 'lib/vendor/core/ey-core/requests/get_alert.rb', line 15 def get_alert(params={}) response( :body => { "alert" => self.find(:alerts, resource_identity(params)) } ) end |
#get_alerting_environments(params = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/vendor/core/ey-core/requests/get_alerting_environments.rb', line 17 def get_alerting_environments(params={}) extract_url_params!(params) resources = self.data[:legacy_alerts].map do |id, alert| server_id = resource_identity(alert["server"]) self.data[:servers][server_id] end.compact.map do |server| environment_id = resource_identity(server["environment"]) self.data[:environments][environment_id] end.compact.uniq.inject({}) {|hash, env| hash[env["id"]] = env; hash} headers, environments_page = search_and_page(params, :environments, search_keys: %w[account project name], resources: resources) response( :body => {"environments" => environments_page}, :status => 200, :headers => headers ) end |
#get_alerts(params = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/vendor/core/ey-core/requests/get_alerts.rb', line 17 def get_alerts(params={}) extract_url_params!(params) if params["server"] && params["database_server"] return response(status: 422, body: "Cannot search for both server & database_server") end if database_server_id = resource_identity(params.delete("database_server")) params["resource"] = url_for("/database-servers/#{database_server_id}") end if server_id = resource_identity(params.delete("server")) params["resource"] = url_for("/servers/#{server_id}") end headers, alerts_page = search_and_page(params, :alerts, search_keys: %w[resource external_id name severity finished_at started_at], deleted_key: "finished_at") response( :body => {"alerts" => alerts_page}, :headers => headers ) end |
#get_api_token(username, password) ⇒ Object
13 14 15 16 17 |
# File 'lib/vendor/core/ey-core/requests/get_api_token.rb', line 13 def get_api_token(username, password) response( :body => {"api_token" => self.api_token} ) end |
#get_application(params = {}) ⇒ Object
15 16 17 18 19 |
# File 'lib/vendor/core/ey-core/requests/get_application.rb', line 15 def get_application(params={}) response( :body => {"application" => self.find(:applications, resource_identity(params))}, ) end |
#get_application_archive(params = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/vendor/core/ey-core/requests/get_application_archive.rb', line 15 def get_application_archive(params={}) if params.is_a? String params = {"url" => params} end url = params.delete("url") application_id = params["application"] || (url && path_params(url)["applications"]) resource_id = params["id"] || (url && path_params(url)["archives"]) find(:applications, application_id) response( :body => {"application_archive" => find(:application_archives, resource_id)}, :status => 200, ) end |
#get_application_archives(params = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/vendor/core/ey-core/requests/get_application_archives.rb', line 18 def get_application_archives(params={}) extract_url_params!(params) headers, archives_pages = search_and_page(params, :application_archives, search_keys: %w[application]) response( :body => {"application_archives" => archives_pages}, :headers => headers ) end |
#get_application_deployment(params = {}) ⇒ Object
15 16 17 18 19 |
# File 'lib/vendor/core/ey-core/requests/get_application_deployment.rb', line 15 def get_application_deployment(params={}) response( :body => {"application_deployment" => self.find(:application_deployments, resource_identity(params))}, ) end |
#get_application_deployments(params = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/vendor/core/ey-core/requests/get_application_deployments.rb', line 17 def get_application_deployments(params={}) extract_url_params!(params) headers, application_deployments_page = search_and_page(params, :application_deployments, search_keys: %w[application cluster environment]) response( :body => {"application_deployments" => application_deployments_page}, :headers => headers ) end |
#get_applications(params = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/vendor/core/ey-core/requests/get_applications.rb', line 17 def get_applications(params={}) extract_url_params!(params) headers, applications_page = search_and_page(params, :applications, search_keys: %w[type repository account name environment]) response( :body => {"applications" => applications_page}, :headers => headers ) end |
#get_backup(params = {}) ⇒ Object
15 16 17 18 19 |
# File 'lib/vendor/core/ey-core/requests/get_backup.rb', line 15 def get_backup(params={}) response( :body => {"backup" => self.find(:backups, resource_identity(params))}, ) end |
#get_backup_file(params = {}) ⇒ Object
15 16 17 18 19 |
# File 'lib/vendor/core/ey-core/requests/get_backup_file.rb', line 15 def get_backup_file(params={}) response( :body => {"backup_file" => self.find(:backup_files, resource_identity(params))}, ) end |
#get_backup_files(params = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/vendor/core/ey-core/requests/get_backup_files.rb', line 16 def get_backup_files(params={}) extract_url_params!(params) headers, backup_files_page = search_and_page(params, :backup_files, search_keys: %w[backup]) response( :body => {"backup_files" => backup_files_page}, :status => 200, :headers => headers ) end |
#get_backups(params = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/vendor/core/ey-core/requests/get_backups.rb', line 15 def get_backups(params={}) extract_url_params!(params) headers, backups_page = search_and_page(params, :backups, search_keys: %w[cluster finished]) response( :body => {"backups" => backups_page}, :status => 200, :headers => headers ) end |
#get_billing(params = {}) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/vendor/core/ey-core/requests/get_billing.rb', line 12 def get_billing(params={}) identity = resource_identity(params) self.find(:accounts, identity) state = self.data[:billing][identity] || "requested" response( :body => {"billing" => {"id" => identity, "state" => state}}, :status => 200, ) end |
#get_cluster(params = {}) ⇒ Object
15 16 17 18 19 |
# File 'lib/vendor/core/ey-core/requests/get_cluster.rb', line 15 def get_cluster(params={}) response( :body => {"cluster" => self.find(:clusters, resource_identity(params))}, ) end |
#get_cluster_component(params = {}) ⇒ Object
15 16 17 18 19 |
# File 'lib/vendor/core/ey-core/requests/get_cluster_component.rb', line 15 def get_cluster_component(params={}) response( :body => {"cluster_component" => self.find(:cluster_components, resource_identity(params))}, ) end |
#get_cluster_components(params = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/vendor/core/ey-core/requests/get_cluster_components.rb', line 16 def get_cluster_components(params={}) extract_url_params!(params) headers, cluster_components_page = search_and_page(params, :cluster_components, search_keys: %w[cluster component]) response( :body => {"cluster_components" => cluster_components_page}, :status => 200, :headers => headers ) end |
#get_cluster_update(params = {}) ⇒ Object
15 16 17 18 19 |
# File 'lib/vendor/core/ey-core/requests/get_cluster_update.rb', line 15 def get_cluster_update(params={}) response( :body => {"cluster_update" => self.find(:cluster_updates, resource_identity(params))}, ) end |
#get_cluster_updates(params = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/vendor/core/ey-core/requests/get_cluster_updates.rb', line 14 def get_cluster_updates(params={}) extract_url_params!(params) headers, cluster_updates_page = search_and_page(params, :cluster_updates, search_keys: %w[cluster]) response( :body => {"cluster_updates" => cluster_updates_page}, :status => 200, :headers => headers ) end |
#get_clusters(params = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/vendor/core/ey-core/requests/get_clusters.rb', line 16 def get_clusters(params={}) extract_url_params!(params) if firewall_id = resource_identity(params.delete("firewall")) self.find(:firewalls, firewall_id) cluster_ids = self.data[:cluster_firewalls].select { |_, fid| firewall_id == fid }.map { |cid, _| cid } params["id"] = cluster_ids end headers, clusters_page = search_and_page(params, :clusters, search_keys: %w[name environment id]) response( :body => {"clusters" => clusters_page}, :headers => headers ) end |
#get_component(params = {}) ⇒ Object
15 16 17 18 19 |
# File 'lib/vendor/core/ey-core/requests/get_component.rb', line 15 def get_component(params={}) response( :body => {"component" => self.find(:components, resource_identity(params))}, ) end |
#get_component_action(params = {}) ⇒ Object
15 16 17 18 19 |
# File 'lib/vendor/core/ey-core/requests/get_component_action.rb', line 15 def get_component_action(params={}) response( :body => {"component_action" => self.find(:component_actions, resource_identity(params))}, ) end |
#get_component_actions(params = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/vendor/core/ey-core/requests/get_component_actions.rb', line 17 def get_component_actions(params={}) extract_url_params!(params) headers, component_actions_page = search_and_page(params, :component_actions, search_keys: %w[task]) response( :body => {"component_actions" => component_actions_page}, :status => 200, :headers => headers ) end |
#get_components(params = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/vendor/core/ey-core/requests/get_components.rb', line 17 def get_components(params={}) extract_url_params!(params) headers, components_page = search_and_page(params, :components, search_keys: %w[name id uri]) response( :body => {"components" => components_page}, :status => 200, :headers => headers ) end |
#get_connector(params = {}) ⇒ Object
15 16 17 18 19 |
# File 'lib/vendor/core/ey-core/requests/get_connector.rb', line 15 def get_connector(params={}) response( :body => {"connector" => self.find(:connectors, resource_identity(params))}, ) end |
#get_connectors(params = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/vendor/core/ey-core/requests/get_connectors.rb', line 16 def get_connectors(params={}) extract_url_params!(params) resources = if cluster_component = params.delete("cluster_component") self.data[:connectors].select { |_, v| v["source"].match(cluster_component) || v["destination"].match(cluster_component) } else self.data[:connectors] end if environment_id = resource_identity(params.delete("environment")) params["environment"] = url_for("/environments/#{environment_id}") end headers, connectors_page = search_and_page(params, :connectors, resources: resources, search_keys: %w[environment]) response( :body => {"connectors" => connectors_page}, :status => 200, :headers => headers ) end |
#get_contacts(params = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/vendor/core/ey-core/requests/get_contacts.rb', line 14 def get_contacts(params={}) extract_url_params!(params) resources = if database_service_url = params.delete("database_service") database_service_id = resource_identity(database_service_url) contact_ids = self.data[:contact_assignments].inject([]) { |r, (contact_id, resource_id)| (resource_id == database_service_id) ? r << contact_id : r } self.data[:contacts].select { |id, _| contact_ids.include?(id) } else self.data[:contacts] end headers, contacts_page = search_and_page(params, :contacts, search_keys: %w[name email], resources: resources) response( :body => {"contacts" => contacts_page}, :status => 200, :headers => headers ) end |
#get_costs(params = {}) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/vendor/core/ey-core/requests/get_costs.rb', line 16 def get_costs(params={}) extract_url_params!(params) response( body: {"costs" => self.data[:costs]}, status: 200 ) end |
#get_current_user(params = {}) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/vendor/core/ey-core/requests/get_current_user.rb', line 11 def get_current_user(params={}) if current_user get_user("id" => current_user["id"]) else response(status: 404) end end |
#get_database_plan_usages(params = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/vendor/core/ey-core/requests/get_database_plan_usages.rb', line 14 def get_database_plan_usages(params={}) account_id = params["account_id"] billing_month = params.fetch("billing_month", Date.today.strftime("%Y-%m")) response( :body => { "database_plan_usages" => self.find(:database_plan_usages, account_id)[billing_month] || [] }, :status => 200, ) end |
#get_database_server(params = {}) ⇒ Object
15 16 17 18 19 |
# File 'lib/vendor/core/ey-core/requests/get_database_server.rb', line 15 def get_database_server(params={}) response( :body => { "database_server" => self.find(:database_servers, resource_identity(params)) }, ) end |
#get_database_server_revisions(params = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/vendor/core/ey-core/requests/get_database_server_revisions.rb', line 16 def get_database_server_revisions(params={}) extract_url_params!(params) headers, page = search_and_page(params, :database_server_revisions, search_keys: %w[database_server]) response( :body => {"database_server_revisions" => page}, :headers => headers, ) end |
#get_database_server_snapshot(params = {}) ⇒ Object
14 15 16 17 18 |
# File 'lib/vendor/core/ey-core/requests/get_database_server_snapshot.rb', line 14 def get_database_server_snapshot(params={}) response( :body => {"database_server_snapshot" => self.find(:database_server_snapshots, resource_identity(params))}, ) end |
#get_database_server_snapshots(params = {}) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/vendor/core/ey-core/requests/get_database_server_snapshots.rb', line 23 def get_database_server_snapshots(params={}) extract_url_params!(params) headers, database_server_snapshots_page = search_and_page(params, :database_server_snapshots, search_keys: %w[database_server provider provisioned_id]) response( :body => {"database_server_snapshots" => database_server_snapshots_page}, :headers => headers, ) end |
#get_database_server_usages(params = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/vendor/core/ey-core/requests/get_database_server_usages.rb', line 14 def get_database_server_usages(params={}) account_id = params["account_id"] billing_month = params.fetch("billing_month", Date.today.strftime("%Y-%m")) response( :body => { "database_server_usages" => self.find(:database_server_usages, account_id)[billing_month] || [] }, :status => 200, ) end |
#get_database_servers(params = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/vendor/core/ey-core/requests/get_database_servers.rb', line 17 def get_database_servers(params={}) extract_url_params!(params) extract_url_params!(params) headers, database_servers_page = search_and_page(params, :database_servers, search_keys: %w[provisioned_id provider database_service flavor location]) response( :body => {"database_servers" => database_servers_page}, :status => 200, :headers => headers ) end |
#get_database_servers_firewalls(params = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/vendor/core/ey-core/requests/get_database_servers_firewalls.rb', line 18 def get_database_servers_firewalls(params={}) extract_url_params!(params) headers, firewalls_page = search_and_page(params, :firewalls, search_keys: %w[cluster name]) response( :body => {"firewalls" => firewalls_page}, :status => 200, :headers => headers ) end |
#get_database_service(params = {}) ⇒ Object
14 15 16 17 18 |
# File 'lib/vendor/core/ey-core/requests/get_database_service.rb', line 14 def get_database_service(params={}) response( :body => {"database_service" => self.find(:database_services, resource_identity(params))}, ) end |
#get_database_services(_params = {}) ⇒ Object
17 18 19 20 21 22 23 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 |
# File 'lib/vendor/core/ey-core/requests/get_database_services.rb', line 17 def get_database_services(_params={}) params = Cistern::Hash.stringify_keys(_params) extract_url_params!(params) if provider_id = resource_identity(params.delete("provider")) params["provider"] = url_for("/providers/#{provider_id}") end if account_id = resource_identity(params.delete("account")) if provider = self.data[:providers].values.detect{|p| p["account"].index(account_id)} params["provider"] = url_for("/providers/#{provider["id"]}") end end resources = if environment_id = resource_identity(params.delete("environment") || params.delete("environment_id")) self.data[:connectors]. select { |_,c| c["_environment"] == url_for("/environments/#{environment_id}") }. select { |_,c| c["source"].match("logical-databases") }. inject({}) { |r, (_, connector)| logical_database = self.find(:logical_databases, resource_identity(connector["source"])) source_id = resource_identity(logical_database["service"]) database_service = self.find(:database_services, source_id) r.merge(source_id => database_service) } end headers, database_services_page = search_and_page(params, :database_services, search_keys: %w[provider name], resources: resources) response( :body => {"database_services" => database_services_page}, :status => 200, :headers => headers ) end |
#get_environment(params = {}) ⇒ Object
15 16 17 18 19 |
# File 'lib/vendor/core/ey-core/requests/get_environment.rb', line 15 def get_environment(params={}) response( :body => {"environment" => self.find(:environments, resource_identity(params))}, ) end |
#get_environment_database_services(params = {}) ⇒ Object
15 16 17 18 19 |
# File 'lib/vendor/core/ey-core/requests/get_environment_database_services.rb', line 15 def get_environment_database_services(params={}) require_parameters(params, "environment_id") get_database_services(params) end |
#get_environment_logical_databases(params = {}) ⇒ Object
14 15 16 17 18 |
# File 'lib/vendor/core/ey-core/requests/get_environment_logical_databases.rb', line 14 def get_environment_logical_databases(params={}) require_parameters(params, "environment_id") get_logical_databases(params) end |
#get_environment_plan_usages(params = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/vendor/core/ey-core/requests/get_environment_plan_usages.rb', line 14 def get_environment_plan_usages(params={}) account_id = params["account_id"] billing_month = params.fetch("billing_month", Date.today.strftime("%Y-%m")) response( :body => { "environment_plan_usages" => self.find(:environment_plan_usages, account_id)[billing_month] || [] }, :status => 200, ) end |
#get_environments(params = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/vendor/core/ey-core/requests/get_environments.rb', line 17 def get_environments(params={}) extract_url_params!(params) headers, environments_page = search_and_page(params, :environments, search_keys: %w[account project name]) response( :body => {"environments" => environments_page}, :status => 200, :headers => headers ) end |
#get_feature(params = {}) ⇒ Object
15 16 17 18 19 |
# File 'lib/vendor/core/ey-core/requests/get_feature.rb', line 15 def get_feature(params={}) response( :body => {"feature" => self.find(:features, resource_identity(params))}, ) end |
#get_features(params = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/vendor/core/ey-core/requests/get_features.rb', line 17 def get_features(params={}) extract_url_params!(params) headers, features_page = search_and_page(params, :features, search_keys: %w[account id privacy]) response( :body => {"features" => features_page}, :headers => headers ) end |
#get_firewall(params = {}) ⇒ Object
15 16 17 18 19 |
# File 'lib/vendor/core/ey-core/requests/get_firewall.rb', line 15 def get_firewall(params={}) response( :body => {"firewall" => self.find(:firewalls, resource_identity(params))}, ) end |
#get_firewall_rule(params = {}) ⇒ Object
15 16 17 18 19 |
# File 'lib/vendor/core/ey-core/requests/get_firewall_rule.rb', line 15 def get_firewall_rule(params={}) response( :body => {"firewall_rule" => self.find(:firewall_rules, resource_identity(params))}, ) end |
#get_firewall_rules(params = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/vendor/core/ey-core/requests/get_firewall_rules.rb', line 17 def get_firewall_rules(params={}) extract_url_params!(params) headers, firewall_rules_page = search_and_page(params, :firewall_rules, search_keys: %w[firewall port_range source]) response( :body => {"firewall_rules" => firewall_rules_page}, :status => 200, :headers => headers ) end |
#get_firewalls(params = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/vendor/core/ey-core/requests/get_firewalls.rb', line 17 def get_firewalls(params={}) extract_url_params!(params) if server_url = params.delete("server") params.merge!("cluster" => resource_identity(self.find(:servers, server_url)["cluster"])) end resources = if database_server_url = params.delete("database_server") database_server_id = resource_identity(database_server_url) firewall_ids = self.data[:database_server_firewalls].inject([]) { |r, (ds, f)| (ds == database_server_id) ? r << f : r } firewall_ids.inject({}) { |r, id| r.merge(id => self.data[:firewalls][id]) } elsif cluster_url = params.delete("cluster") cluster_id = resource_identity(cluster_url) firewall_ids = self.data[:cluster_firewalls].inject([]) { |r, (c, f)| (c == cluster_id) ? r << f : r } firewall_ids.inject({}) { |r, id| r.merge(id => self.data[:firewalls][id]) } else self.data[:firewalls] end headers, firewalls_page = search_and_page(params, :firewalls, search_keys: %w[provisioned_id name], resources: resources) response( :body => {"firewalls" => firewalls_page}, :status => 200, :headers => headers ) end |
#get_gem(params = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/vendor/core/ey-core/requests/get_gem.rb', line 13 def get_gem(params={}) response( :body => { "gem" => { "name" => params["id"], "current_version" => Ey::Core::VERSION, } } ) end |
#get_keypair(params = {}) ⇒ Object
15 16 17 18 19 |
# File 'lib/vendor/core/ey-core/requests/get_keypair.rb', line 15 def get_keypair(params={}) response( :body => {"keypair" => self.find(:keypairs, resource_identity(params))}, ) end |
#get_keypair_deployment(params = {}) ⇒ Object
15 16 17 18 19 |
# File 'lib/vendor/core/ey-core/requests/get_keypair_deployment.rb', line 15 def get_keypair_deployment(params={}) response( :body => {"keypair_deployment" => self.find(:keypair_deployments, resource_identity(params))}, ) end |
#get_keypair_deployments(params = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/vendor/core/ey-core/requests/get_keypair_deployments.rb', line 17 def get_keypair_deployments(params={}) extract_url_params!(params) headers, keypair_deployments_page = search_and_page(params, :keypair_deployments, search_keys: %w[keypair name fingerprint target]) response( :body => {"keypair_deployments" => keypair_deployments_page}, :status => 200, :headers => headers ) end |
#get_keypairs(params = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/vendor/core/ey-core/requests/get_keypairs.rb', line 17 def get_keypairs(params={}) extract_url_params!(params) if environment = params.delete("environment") deployments = get_keypair_deployments("target" => environment).body["keypair_deployments"] params["id"] = deployments.map {|d| resource_identity(d["keypair"]) } end headers, keypairs_page = search_and_page(params, :keypairs, search_keys: %w[application user name fingerprint id]) response( :body => {"keypairs" => keypairs_page}, :status => 200, :headers => headers ) end |
#get_legacy_alert(params = {}) ⇒ Object
15 16 17 18 19 |
# File 'lib/vendor/core/ey-core/requests/get_legacy_alert.rb', line 15 def get_legacy_alert(params={}) response( :body => {"legacy_alert" => self.find(:legacy_alerts, resource_identity(params))}, ) end |
#get_legacy_alerts(params = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/vendor/core/ey-core/requests/get_legacy_alerts.rb', line 17 def get_legacy_alerts(params={}) extract_url_params!(params) headers, alerts_page = search_and_page(params, :legacy_alerts, search_keys: %w[environment server severity assigned acknowledged]) response( :body => {"legacy_alerts" => alerts_page}, :status => 200, :headers => headers ) end |
#get_load_balancer(params = {}) ⇒ Object
15 16 17 18 19 |
# File 'lib/vendor/core/ey-core/requests/get_load_balancer.rb', line 15 def get_load_balancer(params={}) response( :body => {"load_balancer" => self.find(:load_balancers, resource_identity(params))}, ) end |
#get_load_balancer_nodes(params = {}) ⇒ Object
15 16 17 18 19 |
# File 'lib/vendor/core/ey-core/requests/get_load_balancer_node.rb', line 15 def get_load_balancer_nodes(params={}) response( :body => {"load_balancer_node" => self.find(:load_balancer_nodes, resource_identity(params))}, ) end |
#get_load_balancer_service(params = {}) ⇒ Object
15 16 17 18 19 |
# File 'lib/vendor/core/ey-core/requests/get_load_balancer_service.rb', line 15 def get_load_balancer_service(params={}) response( :body => {"load_balancer_service" => self.find(:load_balancer_services, resource_identity(params))}, ) end |
#get_load_balancer_services(params = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/vendor/core/ey-core/requests/get_load_balancer_services.rb', line 18 def get_load_balancer_services(params={}) extract_url_params!(params) headers, page = search_and_page(params, :load_balancer_services, search_keys: %w[load_balancer provider_ssl_certificate protocol external_port internal_port]) response( :body => {"load_balancer_services" => page}, :status => 200, :headers => headers ) end |
#get_load_balancers(params = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/vendor/core/ey-core/requests/get_load_balancers.rb', line 17 def get_load_balancers(params={}) extract_url_params!(params) headers, load_balancers_page = search_and_page(params, :load_balancers, search_keys: %w[name]) response( :body => {"load_balancers" => load_balancers_page}, :status => 200, :headers => headers ) end |
#get_log(params = {}) ⇒ Object
15 16 17 18 19 |
# File 'lib/vendor/core/ey-core/requests/get_log.rb', line 15 def get_log(params={}) response( :body => {"log" => self.find(:logs, resource_identity(params))}, ) end |
#get_logical_database(params = {}) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/vendor/core/ey-core/requests/get_logical_database.rb', line 14 def get_logical_database(params={}) logical_database = self.find(:logical_databases, resource_identity(params)) response( :body => {"logical_database" => logical_database}, :status => 200, ) end |
#get_logical_databases(_params = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/vendor/core/ey-core/requests/get_logical_databases.rb', line 17 def get_logical_databases(_params={}) params = Cistern::Hash.stringify_keys(_params) extract_url_params!(params) params["service"] = params.delete("database_service") if params["database_service"] resources = if environment_id = resource_identity(params.delete("environment") || params.delete("environment_id")) self.data[:connectors]. select { |_,c| c["_environment"] == url_for("/environments/#{environment_id}") }. select { |_,c| c["source"].match("logical-databases") }. inject({}) { |r, (_, connector)| source_id = resource_identity(connector["source"]) r.merge(source_id => self.find(:logical_databases, source_id)) } end headers, logical_databases_page = search_and_page(params, :logical_databases, resources: resources, search_keys: %w[name username service ]) response( :body => {"logical_databases" => logical_databases_page}, :status => 200, :headers => headers ) end |
#get_logs(params = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/vendor/core/ey-core/requests/get_logs.rb', line 17 def get_logs(params={}) extract_url_params!(params) if cluster = params.delete("cluster") params["_cluster"] = cluster end if cluster_update = params.delete("cluster_update") params["_cluster_update"] = cluster_update end headers, logs_page = search_and_page(params, :logs, search_keys: %w[component_action _cluster _cluster_update]) response( :body => {"logs" => logs_page}, :status => 200, :headers => headers ) end |
#get_membership(params = {}) ⇒ Object
15 16 17 18 19 |
# File 'lib/vendor/core/ey-core/requests/get_membership.rb', line 15 def get_membership(params={}) response( :body => {"membership" => self.find(:memberships, resource_identity(params))}, ) end |
#get_message(params = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/vendor/core/ey-core/requests/get_message.rb', line 15 def (params={}) identity = resource_identity(params) if = self.data[:messages].values.detect { |m| m["id"] == identity } response( :body => {"message" => }, :status => 200, ) else response(status: 404) end end |
#get_messages(params = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/vendor/core/ey-core/requests/get_messages.rb', line 15 def (params={}) extract_url_params!(params) headers, = search_and_page(params, :messages, search_keys: %w[cluster slot database_server database_service request]) response( :body => {"messages" => }, :status => 200, :headers => headers ) end |
#get_metadata(params = {}) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/vendor/core/ey-core/requests/get_metadata.rb', line 9 def (params={}) response( :body => { "core" => { "environment" => "mock", "revision" => "mock", "version" => "mock", "now" => Time.now, } }, ) end |
#get_operational_contact(params = {}) ⇒ Object
15 16 17 18 19 |
# File 'lib/vendor/core/ey-core/requests/get_operational_contact.rb', line 15 def get_operational_contact(params={}) #response( #:body => { "contact" => self.find(:operational_contacts, resource_identity(params)) }, #) end |
#get_operational_contacts(params = {}) ⇒ Object
17 18 |
# File 'lib/vendor/core/ey-core/requests/get_operational_contacts.rb', line 17 def get_operational_contacts(params={}) end |
#get_plan_usages(params = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/vendor/core/ey-core/requests/get_plan_usages.rb', line 14 def get_plan_usages(params={}) account_id = params["account_id"] billing_month = params.fetch("billing_month", Date.today.strftime("%Y-%m")) response( :body => { "plan_usages" => self.find(:plan_usages, account_id)[billing_month] || [] }, :status => 200, ) end |
#get_possible_provider_locations(type) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/vendor/core/ey-core/requests/get_possible_provider_locations.rb', line 11 def get_possible_provider_locations(type) response( :body => {"locations" => self.data[:possible_provider_locations][type]}, :status => 200, :headers => {}, ) end |
#get_provider(params = {}) ⇒ Object
15 16 17 18 19 |
# File 'lib/vendor/core/ey-core/requests/get_provider.rb', line 15 def get_provider(params={}) response( :body => {"provider" => self.find(:providers, resource_identity(params))}, ) end |
#get_provider_location(params = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/vendor/core/ey-core/requests/get_provider_location.rb', line 15 def get_provider_location(params={}) extract_url_params!(params) identity = params["id"] || params["provider_location"] provider_location = self.find(:provider_locations, identity) body = provider_location.dup body.delete("name") response( :body => {"provider_location" => body}, ) end |
#get_provider_locations(params = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/vendor/core/ey-core/requests/get_provider_locations.rb', line 16 def get_provider_locations(params={}) extract_url_params!(params) headers, provider_locations_page = search_and_page(params, :provider_locations, search_keys: %w[provider name location_id]) response( :body => {"provider_locations" => provider_locations_page}, :status => 200, :headers => headers ) end |
#get_providers(params = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/vendor/core/ey-core/requests/get_providers.rb', line 16 def get_providers(params={}) extract_url_params!(params) headers, providers_page = search_and_page(params, :providers, search_keys: %w[name account provisioned_id type]) response( :body => {"providers" => providers_page}, :status => 200, :headers => headers ) end |
#get_request(params = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 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 |
# File 'lib/vendor/core/ey-core/requests/get_request.rb', line 15 def get_request(params={}) id = params["id"] request = self.find(:requests, id) request["callback_url"] = "#{self.url}/requests/#{id}/callback" request["poll_count"] ||= 0 request["poll_count"] += 1 response_hash = if request["finished_at"].nil? if request["poll_count"] >= delay # finish a previously unfinished request resource_key, key, resource, resource_url = request.delete("resource") if resource # provisioning if resource.is_a?(Array) resource.each { |res| self.data[resource_key][res["id"]] = res } else resource_url ||= if resource.respond_to?(:call) resource.call(request) else self.data[resource_key][key] = resource resource.delete("resource_url") end end request["finished_at"] = Time.now request["resource"] = resource_url else resource = self.data[resource_key].delete(key) # deprovisioning self.data[:deleted][resource_key][key] ||= resource end request else request end elsif request["finished_at"] # already finished request else request.dup.tap do |r| collection, id, resource = r.delete("resource") r["progress"] = resource["progress"] if resource && resource.key?("progress") if resource && self.data[collection] && self.data[collection][id] r["resource_url"] = resource["resource_url"] end end end response_hash = response_hash.dup response_hash.delete("poll_count") response( :body => {"request" => response_hash}, :status => 200, ) end |
#get_requests(params = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/vendor/core/ey-core/requests/get_requests.rb', line 17 def get_requests(params={}) extract_url_params!(params) headers, requests_page = search_and_page(params, :requests, search_keys: %w[type finished_at requester_id]) response( :body => {"requests" => requests_page}, :status => 200, :headers => headers ) end |
#get_server(params = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/vendor/core/ey-core/requests/get_server.rb', line 15 def get_server(params={}) url = params.delete("url") id = params["id"] && Integer(params["id"]) identity = if slot_id = url && path_params(url)["slots"] find(:slots, slot_id) server = self.data[:servers].values.find {|s| s["slot"] == url_for("/slots/#{slot_id}") } server && server["id"] else id || path_params(url)["servers"].to_i end response( :body => {"server" => self.find(:servers, identity)}, :status => 200, ) end |
#get_server_event(params = {}) ⇒ Object
14 15 16 17 18 |
# File 'lib/vendor/core/ey-core/requests/get_server_event.rb', line 14 def get_server_event(params={}) response( :body => {"server_event" => self.find(:server_events, resource_identity(params))}, ) end |
#get_server_events(params = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/vendor/core/ey-core/requests/get_server_events.rb', line 16 def get_server_events(params={}) extract_url_params!(params) headers, server_events_page = search_and_page(params, :server_events, search_keys: %w[slot server environment]) response( :body => {"server_events" => server_events_page}, :status => 200, :headers => headers ) end |
#get_server_usages(params = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/vendor/core/ey-core/requests/get_server_usages.rb', line 14 def get_server_usages(params={}) account_id = params["account_id"] billing_month = params.fetch("billing_month", Date.today.strftime("%Y-%m")) response( :body => { "server_usages" => self.find(:server_usages, account_id)[billing_month] || [] }, :status => 200, ) end |
#get_servers(params = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/vendor/core/ey-core/requests/get_servers.rb', line 14 def get_servers(params={}) extract_url_params!(params) headers, servers_page = search_and_page(params, :servers, search_keys: %w[cluster environment provider state private_hostname public_hostname provisioned_id]) response( :body => {"servers" => servers_page}, :headers => headers ) end |
#get_slot(params = {}) ⇒ Object
15 16 17 18 19 |
# File 'lib/vendor/core/ey-core/requests/get_slot.rb', line 15 def get_slot(params={}) response( :body => {"slot" => self.find(:slots, resource_identity(params))}, ) end |
#get_slot_component(params = {}) ⇒ Object
15 16 17 18 19 |
# File 'lib/vendor/core/ey-core/requests/get_slot_component.rb', line 15 def get_slot_component(params={}) response( :body => {"slot_component" => self.find(:slot_components, resource_identity(params))}, ) end |
#get_slot_components(params = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/vendor/core/ey-core/requests/get_slot_components.rb', line 16 def get_slot_components(params={}) extract_url_params!(params) if cluster_id = resource_identity(params.delete("cluster")) params["cluster"] = url_for("/clusters/#{cluster_id}") end if environment_id = resource_identity(params.delete("environment")) params["environment"] = url_for("/environments/#{environment_id}") end headers, slot_components_page = search_and_page(params, :slot_components, search_keys: %w[slot cluster environment]) response( :body => {"slot_components" => slot_components_page}, :status => 200, :headers => headers ) end |
#get_slots(params = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/vendor/core/ey-core/requests/get_slots.rb', line 16 def get_slots(params={}) extract_url_params!(params) headers, slots_page = search_and_page(params, :slots, search_keys: %w[cluster name disabled]) response( :body => {"slots" => slots_page}, :status => 200, :headers => headers ) end |
#get_ssl_certificate(params = {}) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/vendor/core/ey-core/requests/get_ssl_certificate.rb', line 15 def get_ssl_certificate(params={}) identity = resource_identity(params) response( :body => {"ssl_certificate" => self.find(:ssl_certificates, identity)}, ) end |
#get_ssl_certificates(params = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/vendor/core/ey-core/requests/get_ssl_certificates.rb', line 16 def get_ssl_certificates(params={}) extract_url_params!(params) headers, ssl_certificates_page = search_and_page(params, :ssl_certificates, search_keys: %w[account name]) response( :body => {"ssl_certificates" => ssl_certificates_page}, :status => 200, :headers => headers ) end |
#get_storage(params = {}) ⇒ Object
15 16 17 18 19 |
# File 'lib/vendor/core/ey-core/requests/get_storage.rb', line 15 def get_storage(params={}) response( :body => {"storage" => self.find(:storages, resource_identity(params))}, ) end |
#get_storage_user(params = {}) ⇒ Object
15 16 17 18 19 |
# File 'lib/vendor/core/ey-core/requests/get_storage_user.rb', line 15 def get_storage_user(params={}) response( :body => {"storage_user" => self.find(:storage_users, resource_identity(params))}, ) end |
#get_storage_users(params = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/vendor/core/ey-core/requests/get_storage_users.rb', line 16 def get_storage_users(params={}) extract_url_params!(params) headers, storage_users_page = search_and_page(params, :storage_users, search_keys: %w[username storage]) response( :body => {"storage_users" => storage_users_page}, :status => 200, :headers => headers ) end |
#get_storages(params = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/vendor/core/ey-core/requests/get_storages.rb', line 16 def get_storages(params={}) extract_url_params!(params) headers, storages_page = search_and_page(params, :storages, search_keys: %w[name id provider]) response( :body => {"storages" => storages_page}, :status => 200, :headers => headers ) end |
#get_task(params = {}) ⇒ Object
15 16 17 18 19 |
# File 'lib/vendor/core/ey-core/requests/get_task.rb', line 15 def get_task(params={}) response( :body => {"task" => self.find(:tasks, resource_identity(params))}, ) end |
#get_tasks(params = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/vendor/core/ey-core/requests/get_tasks.rb', line 16 def get_tasks(params={}) extract_url_params!(params) headers, tasks_page = search_and_page(params, :tasks, search_keys: %w[cluster_component]) response( :body => {"tasks" => tasks_page}, :status => 200, :headers => headers ) end |
#get_untracked_server(params = {}) ⇒ Object
12 13 14 15 16 |
# File 'lib/vendor/core/ey-core/requests/get_untracked_server.rb', line 12 def get_untracked_server(params={}) response( :body => {"untracked_server" => self.find(:untracked_servers, resource_identity(params))}, ) end |
#get_untracked_servers(params = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/vendor/core/ey-core/requests/get_untracked_servers.rb', line 13 def get_untracked_servers(params={}) extract_url_params!(params) headers, servers_page = search_and_page(params, :untracked_servers, search_keys: %w[provider provisioned_id provisioner_id location]) response( :body => {"untracked_servers" => servers_page}, :headers => headers ) end |
#get_user(params = {}) ⇒ Object
15 16 17 18 19 |
# File 'lib/vendor/core/ey-core/requests/get_user.rb', line 15 def get_user(params={}) response( :body => {"user" => self.find(:users, resource_identity(params))}, ) end |
#get_users(params = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/vendor/core/ey-core/requests/get_users.rb', line 16 def get_users(params={}) resources = if url = params.delete("url") if account_id = path_params(url)["accounts"] account = self.find(:accounts, account_id) if url.index("/owners") account[:account_owners].inject({}){|r,id| r.merge(id => self.data[:users][id])} elsif url.index("/users") account[:account_users].inject({}){|r,id| r.merge(id => self.data[:users][id])} else raise "Mock doesn't know how to handle url: #{url}" end else [] end else self.data[:users] end headers, users_page = search_and_page(params, :users, search_keys: %w[name email first_name last_name], resources: resources) response( :body => {"users" => users_page}, :headers => headers ) end |
#get_volume(params = {}) ⇒ Object
15 16 17 18 19 |
# File 'lib/vendor/core/ey-core/requests/get_volume.rb', line 15 def get_volume(params={}) response( :body => {"volume" => self.find(:volumes, resource_identity(params))}, ) end |
#get_volumes(params = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/vendor/core/ey-core/requests/get_volumes.rb', line 16 def get_volumes(params={}) extract_url_params!(params) headers, volumes_page = search_and_page(params, :volumes, search_keys: %w[server name size iops mount device]) response( :body => {"volumes" => volumes_page}, :status => 200, :headers => headers ) end |
#reboot_server(params = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/vendor/core/ey-core/requests/reboot_server.rb', line 16 def reboot_server(params={}) request_id = self.uuid identity = resource_identity(params) find(:servers, identity) reboot_request = { "finished_at" => Time.now, "id" => request_id, "started_at" => Time.now, "successful" => "true", "server" => url_for("/servers/#{identity}"), "type" => "reboot_server_request", } self.data[:requests][request_id] = reboot_request response( :body => {"request" => reboot_request}, :status => 201, ) end |
#request_callback(id) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/vendor/core/ey-core/requests/request_callback.rb', line 12 def request_callback(id) request_id = self.uuid request = find(:requests, id).dup request.delete("resource") response( :body => {"request" => request}, :status => 200, ) end |
#response(options = {}) ⇒ Object
772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 |
# File 'lib/vendor/core/ey-core/client.rb', line 772 def response(={}) status = [:status] || 200 body = [:body] headers = { "Content-Type" => "application/json; charset=utf-8" }.merge([:headers] || {}) @logger.debug "MOCKED RESPONSE: #{status}" @logger.debug('response') { headers.map { |k, v| "#{k}: #{v.inspect}" }.join("\n") } @logger.debug caller[0] @logger.debug('response.body') { body } @logger.debug '' Ey::Core::Response.new( :status => status, :headers => headers, :body => body, :request => { :method => :mocked, :url => caller[1], } ).raise! end |
#run_cluster_application_action(params = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/vendor/core/ey-core/requests/run_cluster_application_action.rb', line 17 def run_cluster_application_action(params={}) cluster_id = params.delete("cluster") application_id = params.delete("application") cluster_component = self.data[:cluster_components].values.find { |cc| cc["cluster"] == url_for("/clusters/#{cluster_id}") && cc["configuration"]["application"] == application_id } response(status: 404) unless cluster_component return run_cluster_component_action(params.merge("cluster_component" => cluster_component["id"])) end |
#run_cluster_component_action(params = {}) ⇒ Object
18 19 20 21 22 23 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 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 |
# File 'lib/vendor/core/ey-core/requests/run_cluster_component_action.rb', line 18 def run_cluster_component_action(params={}) cluster_component_id = params.delete("cluster_component") action = params.delete("action") request_id = self.uuid cluster_component = find(:cluster_components, cluster_component_id) task = { "action" => action, "application_deployment" => nil, "cluster_component" => url_for("/cluster-components/#{cluster_component_id}"), "configuration" => normalize_hash(params["task"] || {}), "created_at" => Time.now, "finished_at" => nil, "id" => request_id, "resource_url" => url_for("/tasks/#{request_id}"), "started_at" => Time.now, "successful" => true, "updated_at" => Time.now, "component_actions" => url_for("/tasks/#{request_id}/component-actions") } if action == "backup" create_backup( "backup" => {}, "url" => cluster_component["cluster"], ) end # application component default_deployer = self.data[:components].values.find {|c| c["name"] == "default_deployer" } if cluster_component["component"] == url_for("/components/#{default_deployer["id"]}") application_id = cluster_component["configuration"]["application"] application_deployment_id = self.uuid archive_id = task["configuration"]["archive_id"] find(:applications, application_id) if action == "deploy" unless cluster_component["configuration"].has_key?("enabled") cluster_component["configuration"]["enabled"] = true end application_deployment = { "application" => url_for("/applications/#{application_id}"), "archive" => archive_id && url_for("/applications/#{application_id}/archives/#{archive_id}"), "commit" => task["configuration"]["commit"] || "123456789abcdefghijklmnopqrstuvwxyz12345", "created_at" => Time.now, "finished_at" => nil, "id" => application_deployment_id, "migrate" => !! task["configuration"]["migrate"] || true, "migrate_command" => task["configuration"]["migrate_command"] || "bundle exec rake db:migrate", "ref" => task["configuration"]["ref"] || "HEAD", "serverside_version" => "2.2.0", "started_at" => Time.now, "successful" => task["successful"], "task" => url_for("/tasks/#{request_id}"), } task.merge!("application_deployment" => url_for("/application_deployments/#{application_deployment_id}")) self.data[:application_deployments][application_deployment_id] = application_deployment end if action == "enable" cluster_component["configuration"]["enabled"] = true end if action == "disable" cluster_component["configuration"]["enabled"] = false end serverside_command = case action when "deploy" "echo 'I am a fake engineyard-serverside deploy command'" when "enable" "echo 'I am a fake engineyard-serverside disable_maintenance command'" when "disable" "echo 'I am a fake engineyard-serverside enable_maintenance command'" when "restart" "echo 'I am a fake engineyard-serverside restart command'" else raise "Application components do not respond to action '#{action}'" end create_component_action(task, serverside_command) create_component_action(task, "echo 'I am a fake engineyard-serverside maintenance_status command'") end task.merge!("read_channel" => "https://messages.engineyard.com/stream?subscription=/tasks/#{request_id[0..7]}&token=#{SecureRandom.hex(6)}") request = task.merge( "type" => "task", "started_at" => Time.now, "finished_at" => nil, "successful" => true, "id" => request_id, "resource" => [:tasks, request_id, lambda do |r| application_deployment["finished_at"] = Time.now if application_deployment r.delete("resource_url") end], ) self.data[:requests][request_id] = request self.data[:tasks][request_id] = task response_hash = request.dup response_hash.delete("resource") response( :body => {"request" => response_hash}, :status => 201, :headers => { "Content-Type" => "application/json; charset=utf8" } ) end |
#run_environment_application_action(params = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/vendor/core/ey-core/requests/run_environment_application_action.rb', line 17 def run_environment_application_action(params={}) environment_id = params.delete('environment') application_id = params.delete('application') clusters = self.data[:clusters].select { |k,c| c['environment'] == url_for("/environments/#{environment_id}") } cluster_urls = clusters.keys.map { |k| url_for("/clusters/#{k}") } cluster_components = self.data[:cluster_components].values.select { |cc| cluster_urls.include?(cc["cluster"]) && cc["configuration"]["application"] == application_id } response(status: 404) unless cluster_components cluster_components.map { |cc| run_cluster_component_action(params.merge("cluster_component" => cc["id"])) }.first end |
#serial_id ⇒ Object
797 798 799 800 |
# File 'lib/vendor/core/ey-core/client.rb', line 797 def serial_id @@serial_id ||= 0 @@serial_id += 1 end |
#signup(_params) ⇒ Object
15 16 17 18 19 20 21 22 23 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 |
# File 'lib/vendor/core/ey-core/requests/signup.rb', line 15 def signup(_params) if self.authentication != :hmac response(status: 403) end params = Cistern::Hash.stringify_keys(_params) user_id = self.uuid user = params["user"].dup user.merge!({ "id" => user_id, "accounts" => url_for("/users/#{user_id}/accounts"), "memberships" => url_for("/users/#{user_id}/memberships"), "keypairs" => url_for("/users/#{user_id}/keypairs"), "token" => SecureRandom.hex(20) }) self.data[:users][user_id] = user account_id = self.uuid account = mock_account_setup(account_id, params["account"].dup) self.data[:accounts][account_id] = account.merge(:account_users => [user_id], :account_owners => [user_id]) (params["features"] || []).each do |resource_id| feature = self.data[:features][resource_id] account_url = url_for("/accounts/#{account_id}") feature["account"] = account_url end response( :body => { "signup" => { "user_id" => user_id, "account_id" => account_id, "upgrade_url" => "http://login.localdev.engineyard.com:9292/session-tokens/#{self.uuid}/upgrade", }, }, :status => 201, ) end |
#update_addon(params = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/vendor/core/ey-core/requests/update_addon.rb', line 14 def update_addon(params={}) addon = params["addon"] extract_url_params!(params) find(:accounts, params["account"]) resource = self.find(:addons, params["addon"]) response( :body => {"addon" => resource.merge!(addon) }, ) end |
#update_addon_attachment(params = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 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 |
# File 'lib/vendor/core/ey-core/requests/update_addon_attachment.rb', line 14 def (params={}) updated = params["attachment"] extract_url_params!(params) account = find(:accounts, params["account"]) addon = find(:addons, params["addon"]) = resource_identity(params["attachment"]) key = updated["key"] = (account["id"], addon["name"]) = .detect{|| ['id'] == } cluster_component_id = ["id"].match(/\AClusterComponent:(.+)\Z/)[1] cluster_component = find(:cluster_components, cluster_component_id) cluster_component["configuration"]["vars"] ||= {} old_key,_ = cluster_component["configuration"]["vars"].detect{|k,v| v == "Addon:#{addon['name']}"} if old_key if deleted = cluster_component["configuration"]["vars"].delete(old_key) connector_id,_ = self.data[:connectors].detect do |key, c| (c["source"] == url_for("/accounts/#{account["id"]}/addons/#{addon["id"]}")) && (c["configuration"]["key"] == old_key) end self.data[:connectors].delete(connector_id) end end if key cluster_component["configuration"]["vars"][key] = "Addon:#{addon['name']}" new_connector_id = self.uuid self.data[:connectors][new_connector_id] = { "destination" => url_for("/cluster-components/#{cluster_component["id"]}"), "source" => url_for("/accounts/#{account["id"]}/addons/#{addon["id"]}"), "id" => new_connector_id, "configuration" => {"key" => key}, } end response( :body => {"addon_attachment" => }, :status => 200, :headers => { "Content-Type" => "application/json; charset=utf8" } ) end |
#update_alert(_params = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/vendor/core/ey-core/requests/update_alert.rb', line 17 def update_alert(_params={}) params = Cistern::Hash.stringify_keys(_params) identity = params["id"] alert = find(:alerts, identity) update_params = Cistern::Hash.slice(params["alert"], "acknowledged", "ignored", "severity", "finished_at", "external_id", "started_at", "message") alert.merge!(update_params.merge!("updated_at" => Time.now)) response( :body => { "alert" => alert }, ) end |
#update_application_archive(params = {}) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/vendor/core/ey-core/requests/update_application_archive.rb', line 15 def update_application_archive(params={}) archive = self.find(:application_archives, resource_identity(params)) response( :body => {"application_archive" => archive.merge(params["application_archive"])}, ) end |
#update_billing(params = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/vendor/core/ey-core/requests/update_billing.rb', line 14 def update_billing(params={}) id = params["id"] state = params["state"] self.find(:accounts, id) self.data[:billing][id] = state response( :body => {"billing" => {"id" => id, "state" => state}}, ) end |
#update_cluster(params = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/vendor/core/ey-core/requests/update_cluster.rb', line 14 def update_cluster(params={}) identity = resource_identity(params) cluster = find(:clusters, identity) update_params = Cistern::Hash.slice(params["cluster"], "release_label", "configuration") # core api doesn't actually do this yet if config = update_params.delete("configuration") update_params["configuration"] = normalize_hash(config) end cluster.merge!(update_params) response( :body => { "cluster" => cluster }, :status => 200 ) end |
#update_cluster_component(params = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/vendor/core/ey-core/requests/update_cluster_component.rb', line 14 def update_cluster_component(params={}) cluster_component = find(:cluster_components, resource_identity(params)) resource = params["cluster_component"] resource["configuration"] = normalize_hash(resource["configuration"] || {}) cluster_component.merge!(resource) response( :body => {"cluster_component" => cluster_component}, :status => 200 ) end |
#update_connector(params = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/vendor/core/ey-core/requests/update_connector.rb', line 13 def update_connector(params={}) identity = resource_identity(params) connector = find(:connectors, identity) update_params = Cistern::Hash.slice(params["connector"], "configuration") # core api doesn't actually do this yet if config = update_params.delete("configuration") update_params["configuration"] = normalize_hash(config) end connector.merge!(update_params) response( :body => { "connector" => connector }, :status => 200 ) end |
#update_membership(params = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/vendor/core/ey-core/requests/update_membership.rb', line 14 def update_membership(params={}) resource_id = resource_identity(params) membership = self.find(:memberships, resource_id) if params["membership"] && params["membership"]["accepted"] self.find(:accounts, resource_identity(membership["account"]))[:account_users] << resource_identity(membership["user"]) end #NOTE: doesn't currently support updating role response( :body => {"membership" => membership}, :status => 200, ) end |
#update_server(params = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/vendor/core/ey-core/requests/update_server.rb', line 13 def update_server(params={}) server = find(:servers, params.fetch("id")) server_params = Cistern::Hash.slice( Cistern::Hash.stringify_keys(params["server"]), "provisioned_at", "deprovisioned_at", "disappeared_at" ) server.merge!("state" => params["server"]["status"]) if params["server"]["status"] server.merge!(server_params.merge("updated_at" => Time.now)) response( :body => { "server" => server }, ) end |
#update_slot(params = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/vendor/core/ey-core/requests/update_slot.rb', line 14 def update_slot(params={}) identity = resource_identity(params) slot = find(:slots, identity) slot_params = Cistern::Hash.slice(params["slot"], "name", "retired", "disabled", "flavor", "location", "volumes", "activation") if slot_params["retired"] slot_params["retired_at"] = Time.now slot_params["retired"] = true end if slot_params.delete("disabled") slot_params["disable_requested_at"] = Time.now end slot.merge! slot_params response( :body => { "slot" => slot }, :status => 200 ) end |
#update_slot_component(params = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/vendor/core/ey-core/requests/update_slot_component.rb', line 14 def update_slot_component(params={}) slot_component = find(:slot_components, resource_identity(params)) resource = params["slot_component"] resource["configuration"] = normalize_hash(resource["configuration"] || {}) slot_component.merge!(resource) response( :body => {"slot_component" => slot_component}, :status => 200 ) end |
#update_ssl_certificate(params = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/vendor/core/ey-core/requests/update_ssl_certificate.rb', line 15 def update_ssl_certificate(params={}) ssl_certificate = self.find(:ssl_certificates, resource_identity(params)) ssl_certificate.merge!(params["ssl_certificate"]) response( :body => {"ssl_certificate" => ssl_certificate} ) end |
#update_untracked_server(params = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/vendor/core/ey-core/requests/update_untracked_server.rb', line 13 def update_untracked_server(params={}) identity = resource_identity(params) || require_parameters(params["untracked_server"], "id") server = find(:untracked_servers, identity) update_params = Cistern::Hash.slice(params["untracked_server"], "provisioner_id", "location", "state") response( :body => { "untracked_server" => server.merge!(update_params) }, ) end |
#upload_file(_params = {}) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/vendor/core/ey-core/requests/upload_file.rb', line 28 def upload_file(_params={}) params = Cistern::Hash.stringify_keys(_params) upload_url = params["upload_url"] temp_file = Tempfile.new("ey-core") temp_file.write(params["body"] || File.read(params.fetch("file"))) temp_file.close self.data[:temp_files][upload_url] = temp_file.path response( :body => "", :status => 200, ) end |