Skip to content

Commit

Permalink
ses: Add ses upload subcommand
Browse files Browse the repository at this point in the history
The `ses upload` subcommand can be used to upload yaml file with
SES configuration to crowbar.
  • Loading branch information
skazi0 committed Mar 18, 2019
1 parent 9d49d84 commit 6a3465f
Show file tree
Hide file tree
Showing 9 changed files with 253 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/crowbar/client/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ module App
autoload :Role,
File.expand_path("../app/role", __FILE__)

autoload :Ses,
File.expand_path("../app/ses", __FILE__)

autoload :Server,
File.expand_path("../app/server", __FILE__)

Expand Down
7 changes: 7 additions & 0 deletions lib/crowbar/client/app/entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,13 @@ def version
desc "services [COMMANDS]",
"Services specific commands, call without params for help"
subcommand "services", Crowbar::Client::App::Services

desc "ses [COMMANDS]",
"SES (Ceph) specific commands, call without params for help"
subcommand "ses", Crowbar::Client::App::Ses

# hide SES command in older versions
remove_command :ses unless Config.defaults[:cloud_version].to_i >= 9
end
end
end
Expand Down
54 changes: 54 additions & 0 deletions lib/crowbar/client/app/ses.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#
# Copyright 2019, SUSE
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

module Crowbar
module Client
module App
#
# A Thor based CLI wrapper for SES commands
#
class Ses < Base
desc "upload FILE",
"Upload SES configuration file"

long_desc <<-LONGDESC
`upload FILE` will upload yaml file with SES configuration to the
server. Data inside this file could be used later for integrating
SES cluster with other services.
LONGDESC

#
# SES config upload command
#
# It will upload yaml file with SES configuration to the server.
# Data inside this file could be used later for integrating SES
# cluster with other services.
#
# @param file [String] the path to the file
#
def upload(file)
Command::Ses::Upload.new(
*command_params(
file: file
)
).execute
rescue => e
catch_errors(e)
end
end
end
end
end
3 changes: 3 additions & 0 deletions lib/crowbar/client/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ module Command
autoload :Role,
File.expand_path("../command/role", __FILE__)

autoload :Ses,
File.expand_path("../command/ses", __FILE__)

autoload :Server,
File.expand_path("../command/server", __FILE__)

Expand Down
29 changes: 29 additions & 0 deletions lib/crowbar/client/command/ses.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#
# Copyright 2019, SUSE
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

module Crowbar
module Client
module Command
#
# Module for the SES command implementations
#
module Ses
autoload :Upload,
File.expand_path("../ses/upload", __FILE__)
end
end
end
end
60 changes: 60 additions & 0 deletions lib/crowbar/client/command/ses/upload.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Copyright 2019, SUSE
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

module Crowbar
module Client
module Command
module Ses
#
# Implementation for the SES config upload command
#
class Upload < Base
def request
args.file =
case args.file
when "-"
stdin.to_io
when File
args.file
else
unless File.exist?(args.file)
err "File #{args.file} does not exist."
end
File.new(
args.file,
File::RDONLY
)
end

@request ||= Request::Ses::Upload.new(
args
)
end

def execute
request.process do |request|
case request.code
when 200
say "Successfully uploaded SES configuration"
else
err request.parsed_response["error"]
end
end
end
end
end
end
end
end
3 changes: 3 additions & 0 deletions lib/crowbar/client/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ module Request
autoload :Role,
File.expand_path("../request/role", __FILE__)

autoload :Ses,
File.expand_path("../request/ses", __FILE__)

autoload :Server,
File.expand_path("../request/server", __FILE__)

Expand Down
29 changes: 29 additions & 0 deletions lib/crowbar/client/request/ses.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#
# Copyright 2019, SUSE
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

module Crowbar
module Client
module Request
#
# Module for the SES request implementations
#
module Ses
autoload :Upload,
File.expand_path("../ses/upload", __FILE__)
end
end
end
end
65 changes: 65 additions & 0 deletions lib/crowbar/client/request/ses/upload.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#
# Copyright 2019, SUSE
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

require "easy_diff"

module Crowbar
module Client
module Request
module Ses
#
# Implementation for the SES config upload request
#
class Upload < Base
#
# Override the request content
#
# @return [Hash] the content for the request
#
def content
super.easy_merge!(
sesconfig: {
file: attrs.file
}
)
end

#
# HTTP method that gets used by the request
#
# @return [Symbol] the method for the request
#
def method
:post
end

#
# Path to the API endpoint for the request
#
# @return [String] path to the API endpoint
#
def url
[
"ses",
"settings",
"upload"
].join("/")
end
end
end
end
end
end

0 comments on commit 6a3465f

Please sign in to comment.