本文整理汇总了Golang中github.com/cloudfoundry/cli/cf/models.ServiceInstance类的典型用法代码示例。如果您正苦于以下问题:Golang ServiceInstance类的具体用法?Golang ServiceInstance怎么用?Golang ServiceInstance使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ServiceInstance类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: ToModels
func (resource ServiceInstancesSummaries) ToModels() (instances []models.ServiceInstance) {
for _, instanceSummary := range resource.ServiceInstances {
applicationNames := resource.findApplicationNamesForInstance(instanceSummary.Name)
planSummary := instanceSummary.ServicePlan
servicePlan := models.ServicePlanFields{}
servicePlan.Name = planSummary.Name
servicePlan.GUID = planSummary.GUID
offeringSummary := planSummary.ServiceOffering
serviceOffering := models.ServiceOfferingFields{}
serviceOffering.Label = offeringSummary.Label
serviceOffering.Provider = offeringSummary.Provider
serviceOffering.Version = offeringSummary.Version
instance := models.ServiceInstance{}
instance.Name = instanceSummary.Name
instance.LastOperation.Type = instanceSummary.LastOperation.Type
instance.LastOperation.State = instanceSummary.LastOperation.State
instance.LastOperation.Description = instanceSummary.LastOperation.Description
instance.ApplicationNames = applicationNames
instance.ServicePlan = servicePlan
instance.ServiceOffering = serviceOffering
instances = append(instances, instance)
}
return
}
开发者ID:yingkitw,项目名称:cli,代码行数:29,代码来源:service_summary.go
示例2: RenameService
func (repo CloudControllerServiceRepository) RenameService(instance models.ServiceInstance, newName string) (apiErr error) {
body := fmt.Sprintf(`{"name":"%s"}`, newName)
path := fmt.Sprintf("/v2/service_instances/%s?accepts_incomplete=true", instance.GUID)
if instance.IsUserProvided() {
path = fmt.Sprintf("/v2/user_provided_service_instances/%s", instance.GUID)
}
return repo.gateway.UpdateResource(repo.config.APIEndpoint(), path, strings.NewReader(body))
}
开发者ID:Reejoshi,项目名称:cli,代码行数:9,代码来源:services.go
示例3: populatePluginModel
func (cmd *ShowService) populatePluginModel(serviceInstance models.ServiceInstance) {
cmd.pluginModel.Name = serviceInstance.Name
cmd.pluginModel.Guid = serviceInstance.Guid
cmd.pluginModel.DashboardUrl = serviceInstance.DashboardUrl
cmd.pluginModel.IsUserProvided = serviceInstance.IsUserProvided()
cmd.pluginModel.LastOperation.Type = serviceInstance.LastOperation.Type
cmd.pluginModel.LastOperation.State = serviceInstance.LastOperation.State
cmd.pluginModel.LastOperation.Description = serviceInstance.LastOperation.Description
cmd.pluginModel.LastOperation.CreatedAt = serviceInstance.LastOperation.CreatedAt
cmd.pluginModel.LastOperation.UpdatedAt = serviceInstance.LastOperation.UpdatedAt
cmd.pluginModel.ServicePlan.Name = serviceInstance.ServicePlan.Name
cmd.pluginModel.ServicePlan.Guid = serviceInstance.ServicePlan.Guid
cmd.pluginModel.ServiceOffering.DocumentationUrl = serviceInstance.ServiceOffering.DocumentationUrl
cmd.pluginModel.ServiceOffering.Name = serviceInstance.ServiceOffering.Label
}
开发者ID:vframbach,项目名称:cli,代码行数:15,代码来源:service.go
示例4:
"github.com/cloudfoundry/cli/cf/models"
testcmd "github.com/cloudfoundry/cli/testhelpers/commands"
testconfig "github.com/cloudfoundry/cli/testhelpers/configuration"
testreq "github.com/cloudfoundry/cli/testhelpers/requirements"
testterm "github.com/cloudfoundry/cli/testhelpers/terminal"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/cloudfoundry/cli/testhelpers/matchers"
)
var _ = Describe("delete-service command", func() {
var (
ui *testterm.FakeUI
requirementsFactory *testreq.FakeReqFactory
serviceRepo *apifakes.FakeServiceRepository
serviceInstance models.ServiceInstance
configRepo coreconfig.Repository
deps commandregistry.Dependency
)
updateCommandDependency := func(pluginCall bool) {
deps.UI = ui
deps.RepoLocator = deps.RepoLocator.SetServiceRepository(serviceRepo)
deps.Config = configRepo
commandregistry.Commands.SetCommand(commandregistry.Commands.FindCommand("delete-service").SetDependency(deps, pluginCall))
}
BeforeEach(func() {
ui = &testterm.FakeUI{
Inputs: []string{"yes"},
}
开发者ID:yingkitw,项目名称:cli,代码行数:32,代码来源:delete_service_test.go
示例5:
Expect(runCommand("come-ON")).To(BeFalse())
})
It("fails when a space is not targeted", func() {
requirementsFactory.LoginSuccess = true
Expect(runCommand("okay-this-time-please??")).To(BeFalse())
})
})
Describe("After Requirement", func() {
createServiceInstanceWithState := func(state string) {
offering := models.ServiceOfferingFields{Label: "mysql", DocumentationUrl: "http://documentation.url", Description: "the-description"}
plan := models.ServicePlanFields{Guid: "plan-guid", Name: "plan-name"}
serviceInstance := models.ServiceInstance{}
serviceInstance.Name = "service1"
serviceInstance.Guid = "service1-guid"
serviceInstance.LastOperation.Type = "create"
serviceInstance.LastOperation.State = "in progress"
serviceInstance.LastOperation.Description = "creating resource - step 1"
serviceInstance.ServicePlan = plan
serviceInstance.ServiceOffering = offering
serviceInstance.DashboardUrl = "some-url"
serviceInstance.LastOperation.State = state
serviceInstance.LastOperation.CreatedAt = "created-date"
serviceInstance.LastOperation.UpdatedAt = "updated-date"
requirementsFactory.ServiceInstance = serviceInstance
}
createServiceInstance := func() {
开发者ID:xinpingluo,项目名称:cli,代码行数:31,代码来源:service_test.go
示例6:
"github.com/cloudfoundry/cli/cf/models"
. "github.com/cloudfoundry/cli/cf/requirements"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("ServiceInstanceRequirement", func() {
var repo *apifakes.FakeServiceRepository
BeforeEach(func() {
repo = new(apifakes.FakeServiceRepository)
})
Context("when a service instance with the given name can be found", func() {
It("succeeds", func() {
instance := models.ServiceInstance{}
instance.Name = "my-service"
instance.GUID = "my-service-guid"
repo.FindInstanceByNameReturns(instance, nil)
req := NewServiceInstanceRequirement("my-service", repo)
err := req.Execute()
Expect(err).NotTo(HaveOccurred())
Expect(repo.FindInstanceByNameArgsForCall(0)).To(Equal("my-service"))
Expect(req.GetServiceInstance()).To(Equal(instance))
})
})
Context("when a service instance with the given name can't be found", func() {
It("errors", func() {
开发者ID:Reejoshi,项目名称:cli,代码行数:31,代码来源:service_instance_test.go
示例7:
}))
})
It("TestCreateServiceBindingIfError", func() {
apiErr := repo.Create("my-service-instance-guid", "my-app-guid")
Expect(testHandler).To(testnet.HaveAllRequestsCalled())
Expect(apiErr).NotTo(BeNil())
Expect(apiErr.(errors.HttpError).ErrorCode()).To(Equal("90003"))
})
})
})
Describe("Delete", func() {
Context("when binding does exist", func() {
var serviceInstance models.ServiceInstance
BeforeEach(func() {
setupTestServer(testapi.NewCloudControllerTestRequest(testnet.TestRequest{
Method: "DELETE",
Path: "/v2/service_bindings/service-binding-2-guid",
Response: testnet.TestResponse{Status: http.StatusOK},
}))
serviceInstance.Guid = "my-service-instance-guid"
binding := models.ServiceBindingFields{}
binding.Url = "/v2/service_bindings/service-binding-1-guid"
binding.AppGuid = "app-1-guid"
binding2 := models.ServiceBindingFields{}
binding2.Url = "/v2/service_bindings/service-binding-2-guid"
开发者ID:palakmathur,项目名称:cli,代码行数:31,代码来源:service_bindings_test.go
示例8:
deps commandregistry.Dependency
)
updateCommandDependency := func(pluginCall bool) {
deps.UI = ui
deps.RepoLocator = deps.RepoLocator.SetServiceRepository(serviceRepo)
deps.RepoLocator = deps.RepoLocator.SetServiceKeyRepository(serviceKeyRepo)
deps.Config = config
commandregistry.Commands.SetCommand(commandregistry.Commands.FindCommand("delete-service-key").SetDependency(deps, pluginCall))
}
BeforeEach(func() {
ui = &testterm.FakeUI{}
config = testconfig.NewRepositoryWithDefaults()
serviceRepo = &apifakes.FakeServiceRepository{}
serviceInstance := models.ServiceInstance{}
serviceInstance.GUID = "fake-service-instance-guid"
serviceRepo.FindInstanceByNameReturns(serviceInstance, nil)
serviceKeyRepo = apifakes.NewFakeServiceKeyRepo()
requirementsFactory = new(requirementsfakes.FakeFactory)
requirementsFactory.NewLoginRequirementReturns(requirements.Passing{})
requirementsFactory.NewTargetedSpaceRequirementReturns(requirements.Passing{})
})
var callDeleteServiceKey = func(args []string) bool {
return testcmd.RunCLICommand("delete-service-key", args, requirementsFactory, updateCommandDependency, false, ui)
}
Describe("requirements are not satisfied", func() {
It("fails when not logged in", func() {
requirementsFactory.NewLoginRequirementReturns(requirements.Failing{Message: "not logged in"})
开发者ID:Reejoshi,项目名称:cli,代码行数:31,代码来源:delete_service_key_test.go
示例9:
It("fails when not logged in", func() {
requirementsFactory.TargetedSpaceSuccess = true
runCommand("banana", "fppants")
Expect(testcmd.CommandDidPassRequirements).To(BeFalse())
})
It("fails when a space is not targeted", func() {
requirementsFactory.LoginSuccess = true
runCommand("banana", "faaaaasdf")
Expect(testcmd.CommandDidPassRequirements).To(BeFalse())
})
})
Context("when logged in and a space is targeted", func() {
var serviceInstance models.ServiceInstance
BeforeEach(func() {
serviceInstance = models.ServiceInstance{}
serviceInstance.Name = "different-name"
serviceInstance.Guid = "different-name-guid"
requirementsFactory.LoginSuccess = true
requirementsFactory.TargetedSpaceSuccess = true
requirementsFactory.ServiceInstance = serviceInstance
})
It("renames the service, obviously", func() {
runCommand("my-service", "new-name")
Expect(ui.Outputs).To(ContainSubstrings(
开发者ID:GABONIA,项目名称:cli,代码行数:31,代码来源:rename_service_test.go
示例10:
. "github.com/cloudfoundry/cli/cf/commands/service"
"github.com/cloudfoundry/cli/cf/models"
testcmd "github.com/cloudfoundry/cli/testhelpers/commands"
testconfig "github.com/cloudfoundry/cli/testhelpers/configuration"
testreq "github.com/cloudfoundry/cli/testhelpers/requirements"
testterm "github.com/cloudfoundry/cli/testhelpers/terminal"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/cloudfoundry/cli/testhelpers/matchers"
)
var _ = Describe("unbind-service command", func() {
var (
app models.Application
serviceInstance models.ServiceInstance
requirementsFactory *testreq.FakeReqFactory
serviceBindingRepo *testapi.FakeServiceBindingRepo
)
BeforeEach(func() {
app.Name = "my-app"
app.Guid = "my-app-guid"
serviceInstance.Name = "my-service"
serviceInstance.Guid = "my-service-guid"
requirementsFactory = &testreq.FakeReqFactory{}
requirementsFactory.Application = app
requirementsFactory.ServiceInstance = serviceInstance
serviceBindingRepo = &testapi.FakeServiceBindingRepo{}
开发者ID:tools-alexuser01,项目名称:cli,代码行数:32,代码来源:unbind_service_test.go
示例11:
Expect(testcmd.CommandDidPassRequirements).To(BeFalse())
})
})
Context("when logged in, a space is targeted, and provided the name of a service that exists", func() {
BeforeEach(func() {
requirementsFactory.LoginSuccess = true
requirementsFactory.TargetedSpaceSuccess = true
})
Context("when the service is externally provided", func() {
BeforeEach(func() {
offering := models.ServiceOfferingFields{Label: "mysql", DocumentationUrl: "http://documentation.url", Description: "the-description"}
plan := models.ServicePlanFields{Guid: "plan-guid", Name: "plan-name"}
serviceInstance := models.ServiceInstance{}
serviceInstance.Name = "service1"
serviceInstance.Guid = "service1-guid"
serviceInstance.ServicePlan = plan
serviceInstance.ServiceOffering = offering
requirementsFactory.ServiceInstance = serviceInstance
})
It("shows the service", func() {
runCommand("service1")
Expect(ui.Outputs).To(ContainSubstrings(
[]string{"Service instance:", "service1"},
[]string{"Service: ", "mysql"},
[]string{"Plan: ", "plan-name"},
[]string{"Description: ", "the-description"},
开发者ID:BlueSpice,项目名称:cli,代码行数:31,代码来源:service_test.go
示例12: UnbindRoute
func (cmd *UnbindRouteService) UnbindRoute(route models.Route, serviceInstance models.ServiceInstance) error {
return cmd.routeServiceBindingRepo.Unbind(serviceInstance.GUID, route.GUID, serviceInstance.IsUserProvided())
}
开发者ID:Reejoshi,项目名称:cli,代码行数:3,代码来源:unbind_route_service.go
示例13: BindRoute
func (cmd *BindRouteService) BindRoute(route models.Route, serviceInstance models.ServiceInstance) error {
return cmd.routeServiceBindingRepo.Bind(serviceInstance.Guid, route.Guid, serviceInstance.IsUserProvided())
}
开发者ID:datatonic,项目名称:cli,代码行数:3,代码来源:bind_route_service.go
示例14:
Expect(routeRepo.FindCallCount()).To(Equal(1))
host, _, _, _ := routeRepo.FindArgsForCall(0)
Expect(host).To(Equal("the-hostname"))
})
})
Context("when the route can be found", func() {
BeforeEach(func() {
routeRepo.FindReturns(models.Route{GUID: "route-guid"}, nil)
})
Context("when the service instance is not user-provided and requires route forwarding", func() {
BeforeEach(func() {
serviceInstance := models.ServiceInstance{
ServiceOffering: models.ServiceOfferingFields{
Requires: []string{"route_forwarding"},
},
}
serviceInstance.ServicePlan = models.ServicePlanFields{
GUID: "service-plan-guid",
}
serviceInstanceRequirement.GetServiceInstanceReturns(serviceInstance)
})
It("asks the user to confirm", func() {
ui.Inputs = []string{"n"}
cmd.Execute(flagContext)
Expect(ui.Prompts).To(ContainSubstrings(
[]string{"Binding may cause requests for route", "Do you want to proceed?"},
))
})
开发者ID:yingkitw,项目名称:cli,代码行数:31,代码来源:bind_route_service_test.go
示例15:
"description":"The app space binding to service is taken: 7b959018-110a-4913-ac0a-d663e613cdea 346bf237-7eef-41a7-b892-68fb08068f09"
}`),
),
)
})
It("returns an error", func() {
err := repo.Create("my-service-instance-guid", "my-app-guid", nil)
Expect(err).To(HaveOccurred())
Expect(err.(errors.HTTPError).ErrorCode()).To(Equal("90003"))
})
})
})
Describe("Delete", func() {
var serviceInstance models.ServiceInstance
BeforeEach(func() {
serviceInstance.GUID = "my-service-instance-guid"
})
Context("when binding does exist", func() {
BeforeEach(func() {
server.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("DELETE", "/v2/service_bindings/service-binding-2-guid"),
ghttp.RespondWith(http.StatusOK, nil),
),
)
serviceInstance.ServiceBindings = []models.ServiceBindingFields{
开发者ID:Reejoshi,项目名称:cli,代码行数:31,代码来源:service_bindings_test.go
示例16:
Describe("Execute", func() {
BeforeEach(func() {
err := flagContext.Parse("service-instance-name")
Expect(err).NotTo(HaveOccurred())
cmd.Requirements(factory, flagContext)
})
It("finds the instance by name in the service repo", func() {
err := flagContext.Parse("service-instance-name", "-f")
Expect(err).NotTo(HaveOccurred())
cmd.Execute(flagContext)
Expect(serviceRepo.FindInstanceByNameCallCount()).To(Equal(1))
})
Context("when the instance can be found", func() {
var serviceInstance models.ServiceInstance
BeforeEach(func() {
serviceInstance = models.ServiceInstance{}
serviceInstance.Name = "service-instance-name"
serviceRepo.FindInstanceByNameReturns(serviceInstance, nil)
})
It("warns the user", func() {
ui.Inputs = []string{"n"}
cmd.Execute(flagContext)
Eventually(func() []string {
return ui.Outputs()
}).Should(ContainSubstrings(
[]string{"WARNING"},
))
开发者ID:Reejoshi,项目名称:cli,代码行数:31,代码来源:purge_service_instance_test.go
示例17:
})
It("lists available services", func() {
plan := models.ServicePlanFields{
Guid: "spark-guid",
Name: "spark",
}
plan2 := models.ServicePlanFields{
Guid: "spark-guid-2",
Name: "spark-2",
}
offering := models.ServiceOfferingFields{Label: "cleardb"}
serviceInstance := models.ServiceInstance{}
serviceInstance.Name = "my-service-1"
serviceInstance.LastOperation.Type = "create"
serviceInstance.LastOperation.State = "in progress"
serviceInstance.LastOperation.Description = "fake state description"
serviceInstance.ServicePlan = plan
serviceInstance.ApplicationNames = []string{"cli1", "cli2"}
serviceInstance.ServiceOffering = offering
serviceInstance2 := models.ServiceInstance{}
serviceInstance2.Name = "my-service-2"
serviceInstance2.LastOperation.Type = "create"
serviceInstance2.LastOperation.State = ""
serviceInstance2.LastOperation.Description = "fake state description"
serviceInstance2.ServicePlan = plan2
serviceInstance2.ApplicationNames = []string{"cli1"}
开发者ID:raghulsid,项目名称:cli,代码行数:31,代码来源:services_test.go
示例18:
deps command_registry.Dependency
)
updateCommandDependency := func(pluginCall bool) {
deps.Ui = ui
deps.RepoLocator = deps.RepoLocator.SetServiceRepository(serviceRepo)
deps.RepoLocator = deps.RepoLocator.SetServiceKeyRepository(serviceKeyRepo)
deps.Config = config
command_registry.Commands.SetCommand(command_registry.Commands.FindCommand("service-keys").SetDependency(deps, pluginCall))
}
BeforeEach(func() {
ui = &testterm.FakeUI{}
config = testconfig.NewRepositoryWithDefaults()
serviceRepo = &testapi.FakeServiceRepository{}
serviceInstance := models.ServiceInstance{}
serviceInstance.Guid = "fake-instance-guid"
serviceInstance.Name = "fake-service-instance"
serviceRepo.FindInstanceByNameReturns(serviceInstance, nil)
serviceKeyRepo = testapi.NewFakeServiceKeyRepo()
requirementsFactory = &testreq.FakeReqFactory{LoginSuccess: true, TargetedSpaceSuccess: true, ServiceInstanceNotFound: false}
requirementsFactory.ServiceInstance = serviceInstance
})
var callListServiceKeys = func(args []string) bool {
return testcmd.RunCliCommand("service-keys", args, requirementsFactory, updateCommandDependency, false)
}
Describe("requirements", func() {
It("fails when not logged in", func() {
requirementsFactory = &testreq.FakeReqFactory{LoginSuccess: false}
开发者ID:vframbach,项目名称:cli,代码行数:31,代码来源:service_keys_test.go
示例19:
runCommand()
Expect(ui.Outputs).To(ContainSubstrings(
[]string{"Incorrect Usage", "Requires", "argument"},
))
})
It("fails when not logged in", func() {
Expect(runCommand("whoops")).To(BeFalse())
})
})
Context("when logged in", func() {
BeforeEach(func() {
requirementsFactory.LoginSuccess = true
serviceInstance := models.ServiceInstance{}
serviceInstance.Name = "service-name"
requirementsFactory.ServiceInstance = serviceInstance
})
Context("when no flags are provided", func() {
It("tells the user that no changes occurred", func() {
runCommand("service-name")
Expect(ui.Outputs).To(ContainSubstrings(
[]string{"Updating user provided service", "service-name", "my-org", "my-space", "my-user"},
[]string{"OK"},
[]string{"No changes"},
))
})
})
开发者ID:sunatthegilddotcom,项目名称:cli,代码行数:31,代码来源:update_user_provided_service_test.go
示例20:
_, err := repo.FindInstanceByName("my-service")
Expect(testHandler).To(testnet.HaveAllRequestsCalled())
Expect(err).To(BeAssignableToTypeOf(&errors.ModelNotFoundError{}))
})
})
Describe("DeleteService", func() {
It("it deletes the service when no apps are bound", func() {
setupTestServer(testapi.NewCloudControllerTestRequest(testnet.TestRequest{
Method: "DELETE",
Path: "/v2/service_instances/my-service-instance-guid",
Response: testnet.TestResponse{Status: http.StatusOK},
}))
serviceInstance := models.ServiceInstance{}
serviceInstance.Guid = "my-service-instance-guid"
err := repo.DeleteService(serviceInstance)
Expect(testHandler).To(testnet.HaveAllRequestsCalled())
Expect(err).NotTo(HaveOccurred())
})
It("doesn't delete the service when apps are bound", func() {
setupTestServer()
serviceInstance := models.ServiceInstance{}
serviceInstance.Guid = "my-service-instance-guid"
serviceInstance.ServiceBindings = []models.ServiceBindingFields{
{
Url: "/v2/service_bindings/service-binding-1-guid",
开发者ID:GABONIA,项目名称:cli,代码行数:31,代码来源:services_test.go
注:本文中的github.com/cloudfoundry/cli/cf/models.ServiceInstance类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论