本文整理汇总了Golang中github.com/tsuru/tsuru/app/bind.App.GetIp方法的典型用法代码示例。如果您正苦于以下问题:Golang App.GetIp方法的具体用法?Golang App.GetIp怎么用?Golang App.GetIp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/tsuru/tsuru/app/bind.App
的用法示例。
在下文中一共展示了App.GetIp方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: BindUnit
func (c *Client) BindUnit(instance *ServiceInstance, app bind.App, unit bind.Unit) error {
log.Debugf("Calling bind of instance %q and %q unit at %q API",
instance.Name, unit.GetIp(), instance.ServiceName)
var resp *http.Response
params := map[string][]string{
"app-host": {app.GetIp()},
"unit-host": {unit.GetIp()},
}
resp, err := c.issueRequest("/resources/"+instance.GetIdentifier()+"/bind", "POST", params)
if err != nil {
if m, _ := regexp.MatchString("", err.Error()); m {
return fmt.Errorf("%s api is down.", instance.Name)
}
return err
}
if resp.StatusCode == http.StatusPreconditionFailed {
return &errors.HTTP{Code: resp.StatusCode, Message: "You cannot bind any app to this service instance because it is not ready yet."}
}
if resp.StatusCode > 299 {
msg := fmt.Sprintf("Failed to bind the instance %q to the unit %q: %s", instance.Name, unit.GetIp(), c.buildErrorMessage(err, resp))
log.Error(msg)
return &errors.HTTP{Code: http.StatusInternalServerError, Message: msg}
}
return nil
}
示例2: BindUnit
func (c *Client) BindUnit(instance *ServiceInstance, app bind.App, unit bind.Unit) error {
log.Debugf("Calling bind of instance %q and %q unit at %q API",
instance.Name, unit.GetIp(), instance.ServiceName)
var resp *http.Response
params := map[string][]string{
"app-host": {app.GetIp()},
"unit-host": {unit.GetIp()},
}
resp, err := c.issueRequest("/resources/"+instance.GetIdentifier()+"/bind", "POST", params)
if err != nil {
return log.WrapError(errors.Wrapf(err, `Failed to bind the instance "%s/%s" to the unit %q`, instance.ServiceName, instance.Name, unit.GetIp()))
}
defer resp.Body.Close()
switch resp.StatusCode {
case http.StatusPreconditionFailed:
return ErrInstanceNotReady
case http.StatusNotFound:
return ErrInstanceNotFoundInAPI
}
if resp.StatusCode > 299 {
err = errors.Wrapf(c.buildErrorMessage(err, resp), `Failed to bind the instance "%s/%s" to the unit %q`, instance.ServiceName, instance.Name, unit.GetIp())
return log.WrapError(err)
}
return nil
}
示例3: BindApp
func (c *Client) BindApp(instance *ServiceInstance, app bind.App) (map[string]string, error) {
log.Debugf("Calling bind of instance %q and %q app at %q API",
instance.Name, app.GetName(), instance.ServiceName)
var resp *http.Response
params := map[string][]string{
"app-host": {app.GetIp()},
}
resp, err := c.issueRequest("/resources/"+instance.GetIdentifier()+"/bind-app", "POST", params)
if resp != nil && resp.StatusCode == http.StatusNotFound {
resp, err = c.issueRequest("/resources/"+instance.GetIdentifier()+"/bind", "POST", params)
}
if err != nil {
if m, _ := regexp.MatchString("", err.Error()); m {
return nil, fmt.Errorf("%s api is down.", instance.Name)
}
return nil, err
}
if err == nil && resp.StatusCode < 300 {
var result map[string]string
err = c.jsonFromResponse(resp, &result)
if err != nil {
return nil, err
}
return result, nil
}
if resp.StatusCode == http.StatusPreconditionFailed {
return nil, &errors.HTTP{Code: resp.StatusCode, Message: "You cannot bind any app to this service instance because it is not ready yet."}
}
msg := fmt.Sprintf("Failed to bind the instance %q to the app %q: %s", instance.Name, app.GetName(), c.buildErrorMessage(err, resp))
log.Error(msg)
return nil, &errors.HTTP{Code: http.StatusInternalServerError, Message: msg}
}
示例4: BindUnit
func (c *Client) BindUnit(instance *ServiceInstance, app bind.App, unit bind.Unit) error {
log.Debugf("Calling bind of instance %q and %q unit at %q API",
instance.Name, unit.GetIp(), instance.ServiceName)
var resp *http.Response
params := map[string][]string{
"app-host": {app.GetIp()},
"unit-host": {unit.GetIp()},
}
resp, err := c.issueRequest("/resources/"+instance.GetIdentifier()+"/bind", "POST", params)
if err != nil {
if m, _ := regexp.MatchString("", err.Error()); m {
return fmt.Errorf("%s api is down.", instance.Name)
}
return err
}
switch resp.StatusCode {
case http.StatusPreconditionFailed:
return ErrInstanceNotReady
case http.StatusNotFound:
return ErrInstanceNotFoundInAPI
}
if resp.StatusCode > 299 {
msg := fmt.Sprintf(`Failed to bind the instance "%s/%s" to the unit %q: %s`, instance.ServiceName, instance.Name, unit.GetIp(), c.buildErrorMessage(err, resp))
log.Error(msg)
return errors.New(msg)
}
return nil
}
示例5: BindApp
func (c *Client) BindApp(instance *ServiceInstance, app bind.App) (map[string]string, error) {
log.Debugf("Calling bind of instance %q and %q app at %q API",
instance.Name, app.GetName(), instance.ServiceName)
var resp *http.Response
params := map[string][]string{
"app-host": {app.GetIp()},
}
resp, err := c.issueRequest("/resources/"+instance.GetIdentifier()+"/bind-app", "POST", params)
if resp != nil && resp.StatusCode == http.StatusNotFound {
resp, err = c.issueRequest("/resources/"+instance.GetIdentifier()+"/bind", "POST", params)
}
if err != nil {
log.Errorf(`Failed to bind app %q to service instance "%s/%s": %s`, app.GetName(), instance.ServiceName, instance.Name, err)
return nil, fmt.Errorf("%s api is down.", instance.Name)
}
if err == nil && resp.StatusCode < 300 {
var result map[string]string
err = c.jsonFromResponse(resp, &result)
if err != nil {
return nil, err
}
return result, nil
}
switch resp.StatusCode {
case http.StatusPreconditionFailed:
return nil, ErrInstanceNotReady
case http.StatusNotFound:
return nil, ErrInstanceNotFoundInAPI
}
msg := fmt.Sprintf(`Failed to bind the instance "%s/%s" to the app %q: %s`, instance.ServiceName, instance.Name, app.GetName(), c.buildErrorMessage(err, resp))
log.Error(msg)
return nil, errors.New(msg)
}
示例6: UnbindApp
func (c *Client) UnbindApp(instance *ServiceInstance, app bind.App) error {
log.Debugf("Calling unbind of service instance %q and app %q at %q", instance.Name, app.GetName(), instance.ServiceName)
var resp *http.Response
url := "/resources/" + instance.GetIdentifier() + "/bind-app"
params := map[string][]string{
"app-host": {app.GetIp()},
}
resp, err := c.issueRequest(url, "DELETE", params)
if err == nil && resp.StatusCode > 299 {
msg := fmt.Sprintf("Failed to unbind (%q): %s", url, c.buildErrorMessage(err, resp))
log.Error(msg)
return &errors.HTTP{Code: http.StatusInternalServerError, Message: msg}
}
return err
}
示例7: UnbindUnit
func (c *Client) UnbindUnit(instance *ServiceInstance, app bind.App, unit bind.Unit) error {
log.Debugf("Calling unbind of service instance %q and unit %q at %q", instance.Name, unit.GetIp(), instance.ServiceName)
var resp *http.Response
url := "/resources/" + instance.GetIdentifier() + "/bind"
params := map[string][]string{
"app-host": {app.GetIp()},
"unit-host": {unit.GetIp()},
}
resp, err := c.issueRequest(url, "DELETE", params)
if err == nil && resp.StatusCode > 299 {
if resp.StatusCode == http.StatusNotFound {
return ErrInstanceNotFoundInAPI
}
msg := fmt.Sprintf("Failed to unbind (%q): %s", url, c.buildErrorMessage(err, resp))
log.Error(msg)
return errors.New(msg)
}
return err
}
示例8: UnbindApp
func (c *Client) UnbindApp(instance *ServiceInstance, app bind.App) error {
log.Debugf("Calling unbind of service instance %q and app %q at %q", instance.Name, app.GetName(), instance.ServiceName)
var resp *http.Response
url := "/resources/" + instance.GetIdentifier() + "/bind-app"
params := map[string][]string{
"app-host": {app.GetIp()},
}
resp, err := c.issueRequest(url, "DELETE", params)
if err == nil {
defer resp.Body.Close()
if resp.StatusCode > 299 {
if resp.StatusCode == http.StatusNotFound {
return ErrInstanceNotFoundInAPI
}
err = errors.Wrapf(c.buildErrorMessage(err, resp), "Failed to unbind (%q)", url)
return log.WrapError(err)
}
}
return err
}
示例9: BindApp
func (c *Client) BindApp(instance *ServiceInstance, app bind.App) (map[string]string, error) {
log.Debugf("Calling bind of instance %q and %q app at %q API",
instance.Name, app.GetName(), instance.ServiceName)
var resp *http.Response
params := map[string][]string{
"app-host": {app.GetIp()},
}
resp, err := c.issueRequest("/resources/"+instance.GetIdentifier()+"/bind-app", "POST", params)
if err != nil {
return nil, log.WrapError(errors.Wrapf(err, `Failed to bind app %q to service instance "%s/%s"`, app.GetName(), instance.ServiceName, instance.Name))
}
defer resp.Body.Close()
if resp.StatusCode == http.StatusNotFound {
resp, err = c.issueRequest("/resources/"+instance.GetIdentifier()+"/bind", "POST", params)
}
if err != nil {
return nil, log.WrapError(errors.Wrapf(err, `Failed to bind app %q to service instance "%s/%s"`, app.GetName(), instance.ServiceName, instance.Name))
}
defer resp.Body.Close()
if resp.StatusCode < 300 {
var result map[string]string
err = c.jsonFromResponse(resp, &result)
if err != nil {
return nil, err
}
return result, nil
}
switch resp.StatusCode {
case http.StatusPreconditionFailed:
return nil, ErrInstanceNotReady
case http.StatusNotFound:
return nil, ErrInstanceNotFoundInAPI
}
err = errors.Wrapf(c.buildErrorMessage(err, resp), `Failed to bind the instance "%s/%s" to the app %q`, instance.ServiceName, instance.Name, app.GetName())
return nil, log.WrapError(err)
}