offline_session.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package ansiblev2
  15. import (
  16. "context"
  17. "io"
  18. )
  19. type OfflineSession struct {
  20. PlaybookSessionBase
  21. playbookPath string
  22. proxy string
  23. user string
  24. hostIp string
  25. hostName string
  26. configs map[string]interface{}
  27. configYaml string
  28. }
  29. func NewOfflineSession() *OfflineSession {
  30. sess := &OfflineSession{
  31. PlaybookSessionBase: NewPlaybookSessionBase(),
  32. }
  33. return sess
  34. }
  35. func (sess *OfflineSession) PrivateKey(s string) *OfflineSession {
  36. sess.privateKey = s
  37. return sess
  38. }
  39. func (sess *OfflineSession) PlaybookPath(s string) *OfflineSession {
  40. sess.playbookPath = s
  41. return sess
  42. }
  43. func (sess *OfflineSession) Inventory(s string) *OfflineSession {
  44. sess.inventory = s
  45. return sess
  46. }
  47. func (sess *OfflineSession) OutputWriter(w io.Writer) *OfflineSession {
  48. sess.outputWriter = w
  49. return sess
  50. }
  51. func (sess *OfflineSession) KeepTmpdir(keep bool) *OfflineSession {
  52. sess.keepTmpdir = keep
  53. return sess
  54. }
  55. func (sess *OfflineSession) Configs(configs map[string]interface{}) *OfflineSession {
  56. sess.configs = configs
  57. return sess
  58. }
  59. func (sess *OfflineSession) ConfigYaml(yaml string) *OfflineSession {
  60. sess.configYaml = yaml
  61. return sess
  62. }
  63. func (sess *OfflineSession) GetPlaybookPath() string {
  64. return sess.playbookPath
  65. }
  66. func (sess *OfflineSession) GetConfigs() map[string]interface{} {
  67. return sess.configs
  68. }
  69. func (sess *OfflineSession) GetConfigYaml() string {
  70. return sess.configYaml
  71. }
  72. func (sess *OfflineSession) Run(ctx context.Context) (err error) {
  73. return runnable{sess}.Run(ctx)
  74. }