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

VPCルータ: ping #1009

Merged
merged 1 commit into from
Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ require (
github.com/rhysd/go-github-selfupdate v1.2.3
github.com/sacloud/api-client-go v0.2.4
github.com/sacloud/go-http v0.1.3
github.com/sacloud/iaas-api-go v1.8.0
github.com/sacloud/iaas-api-go v1.8.1
github.com/sacloud/iaas-service-go v1.6.0
github.com/sacloud/packages-go v0.0.7
github.com/sacloud/webaccel-api-go v1.1.4
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ github.com/sacloud/go-http v0.1.3 h1:t+RADgwS5QgnMKlbggjwbXv01UEuXp0/9fV0xulYEeY
github.com/sacloud/go-http v0.1.3/go.mod h1:4LwFHG5N/599baV0JSuAQO5e3atHXx0Jb9322PrIoHo=
github.com/sacloud/iaas-api-go v1.8.0 h1:xjSyCeiAmsn7DsTqsthGS8b7RruPGj3nE1tteZ07O5U=
github.com/sacloud/iaas-api-go v1.8.0/go.mod h1:OQTd66RoiiGKrLbyXYBvYZmQCOJUTeArjkOADIGZB4M=
github.com/sacloud/iaas-api-go v1.8.1 h1:ot9qppeGLI0PFj+KStT4te8mo89HUCXgWbaINIzyw8Y=
github.com/sacloud/iaas-api-go v1.8.1/go.mod h1:OQTd66RoiiGKrLbyXYBvYZmQCOJUTeArjkOADIGZB4M=
github.com/sacloud/iaas-service-go v1.6.0 h1:UF+5N5skVvQU5N/2V+2qQI2pF6/LMuADc2lvErJv0Es=
github.com/sacloud/iaas-service-go v1.6.0/go.mod h1:KxcO97XiIohgfPMI+rSgo5igSWfmfupBwt6tiQrqQUk=
github.com/sacloud/packages-go v0.0.7 h1:Py6nksUuyoRBaHtPfpA9sTIxSKnQfce/xm7XkiCLZmQ=
Expand Down
74 changes: 74 additions & 0 deletions pkg/commands/iaas/vpcrouter/ping.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Copyright 2017-2023 The sacloud/usacloud Authors
//
// 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.

package vpcrouter

import (
"fmt"

"github.com/sacloud/iaas-api-go"
"github.com/sacloud/iaas-api-go/types"
"github.com/sacloud/usacloud/pkg/cflag"
"github.com/sacloud/usacloud/pkg/cli"
"github.com/sacloud/usacloud/pkg/core"
)

var pingCommand = &core.Command{
Name: "ping",
Category: "other",
Order: 30,

SelectorType: core.SelectorTypeRequireSingle,
NoProgress: true,

ParameterInitializer: func() interface{} {
return newPingParameter()
},

Func: pingFunc,
}

type pingParameter struct {
cflag.ZoneParameter `cli:",squash" mapconv:",squash"`
cflag.IDParameter `cli:",squash" mapconv:",squash"`
cflag.CommonParameter `cli:",squash" mapconv:"-"`

Destination string `cli:",aliases=dest,short=d,desc=destination address(IPv4)" validate:"required,ipv4"`
}

func newPingParameter() *pingParameter {
return &pingParameter{}
}

func init() {
Resource.AddCommand(pingCommand)
}

func pingFunc(ctx cli.Context, parameter interface{}) ([]interface{}, error) {
p, ok := parameter.(*pingParameter)
if !ok {
return nil, fmt.Errorf("invalid parameter: %v", parameter)
}

vpcRouterOp := iaas.NewVPCRouterOp(ctx.Client().(iaas.APICaller))
results, err := vpcRouterOp.Ping(ctx, p.Zone, types.StringID(p.ID), p.Destination)
if err != nil {
return nil, err
}

for _, result := range results.Result {
fmt.Fprintln(ctx.IO().Out(), result) // nolint
}
return nil, nil
}
104 changes: 104 additions & 0 deletions pkg/commands/iaas/vpcrouter/zz_ping_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions pkg/services/iaas/vpc_router_services_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.