Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ses: Add ses upload subcommand (SCRD-8432) #185

Merged
merged 4 commits into from
Apr 2, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
32 changes: 25 additions & 7 deletions lib/crowbar/client/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def defaults
apiversion: default_apiversion,
experimental: default_experimental,
upgrade_versions: default_upgrade_versions,
cloud_version: default_cloud_version,
debug: default_debug
)
end
Expand Down Expand Up @@ -108,18 +109,35 @@ def default_upgrade_versions
return "7-to-8" if File.exist?("/var/lib/crowbar/upgrade/7-to-8-upgrade-running")

# if upgrade has not been started, check the system version
os_release_file = "/etc/os-release"
os_release = Crowbar::Client::Util::OsRelease.fields

if File.exist?(os_release_file)
os_release = Hash[
File.open(os_release_file).read.scan(/(\S+)\s*=\s*"([^"]+)/)
]
return "6-to-7" if os_release["VERSION_ID"] == "12.1"
end
return "6-to-7" if os_release["VERSION_ID"] == "12.1"

"7-to-8"
end

#
# Define a default cloud version value
# It is detected based on OS release for local machine or set by user via ENV variable.
#
# @return [String] the default cloud version value
#
def default_cloud_version
return ENV["CROWBAR_CLOUD_VERSION"] if ENV["CROWBAR_CLOUD_VERSION"].present?

os_release = Crowbar::Client::Util::OsRelease.fields
case os_release["VERSION_ID"]
when "12.1"
"6"
when "12.2"
"7"
when "12.3"
"8"
else
"9"
end
end

#
# Define a default alias value
#
Expand Down
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
3 changes: 3 additions & 0 deletions lib/crowbar/client/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ module Util

autoload :ApiVersion,
File.expand_path("../util/apiversion", __FILE__)

autoload :OsRelease,
File.expand_path("../util/osrelease", __FILE__)
end
end
end
10 changes: 2 additions & 8 deletions lib/crowbar/client/util/apiversion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,9 @@ def headers

class << self
def default
os_release_file = "/etc/os-release"
os_release = OsRelease.fields

if File.exist?(os_release_file)
os_release = Hash[
File.open(os_release_file).read.scan(/(\S+)\s*=\s*"([^"]+)/)
]

return 1.0 if os_release["VERSION_ID"] == "12.1" && os_release["ID"] == "sles"
end
return 1.0 if os_release["VERSION_ID"] == "12.1" && os_release["ID"] == "sles"

2.0
end
Expand Down
Loading