core: Remove old profiles and make new profiles parse flags for runtime.
MultiPart: 1/5
Change-Id: Ib69b8d1c1b6759268cbe134463f292985645f3b8
diff --git a/profiles/gce/init.go b/profiles/gce/init.go
deleted file mode 100644
index 2882a08..0000000
--- a/profiles/gce/init.go
+++ /dev/null
@@ -1,77 +0,0 @@
-// +build linux
-
-// Package gce provides a Profile for Google Compute Engine and should be
-// used by binaries that only ever expect to be run on GCE.
-package gce
-
-import (
- "fmt"
- "net"
-
- "v.io/core/veyron2"
- "v.io/core/veyron2/config"
- "v.io/core/veyron2/ipc"
-
- "v.io/core/veyron/lib/appcycle"
- "v.io/core/veyron/lib/netstate"
- "v.io/core/veyron/profiles/internal/gce"
- "v.io/core/veyron/profiles/internal/platform"
- _ "v.io/core/veyron/runtimes/google/ipc/protocols/tcp"
- _ "v.io/core/veyron/runtimes/google/ipc/protocols/ws"
- _ "v.io/core/veyron/runtimes/google/ipc/protocols/wsh"
- _ "v.io/core/veyron/runtimes/google/rt"
-)
-
-var (
- // ListenSpec is an initialized instance of ipc.ListenSpec that can
- // be used with ipc.Listen.
- ListenSpec ipc.ListenSpec
-)
-
-type profile struct {
- ac *appcycle.AppCycle
-}
-
-func (p *profile) Name() string {
- return "GCE"
-}
-
-func (p *profile) Runtime() (string, []veyron2.ROpt) {
- return "", nil
-}
-
-func (p *profile) Platform() *veyron2.Platform {
- pstr, _ := platform.Platform()
- return pstr
-}
-
-func (p *profile) String() string {
- return "net " + p.Platform().String()
-}
-
-func (p *profile) Init(veyron2.Runtime, *config.Publisher) (veyron2.AppCycle, error) {
- if !gce.RunningOnGCE() {
- return nil, fmt.Errorf("GCE profile used on a non-GCE system")
- }
-
- lf := commonFlags.ListenFlags()
- ListenSpec = ipc.ListenSpec{
- Addrs: ipc.ListenAddrs(lf.Addrs),
- Proxy: lf.ListenProxy,
- }
-
- p.ac = appcycle.New()
-
- if ip, err := gce.ExternalIPAddress(); err != nil {
- return p.ac, err
- } else {
- ListenSpec.AddressChooser = func(network string, addrs []ipc.Address) ([]ipc.Address, error) {
- return []ipc.Address{&netstate.AddrIfc{&net.IPAddr{IP: ip}, "gce-nat", nil}}, nil
- }
- }
- return p.ac, nil
-}
-
-func (p *profile) Cleanup() {
- p.ac.Shutdown()
-}
diff --git a/profiles/gce/initx.go b/profiles/gce/initx.go
index b344955..191e8cf 100644
--- a/profiles/gce/initx.go
+++ b/profiles/gce/initx.go
@@ -8,7 +8,6 @@
"flag"
"fmt"
"net"
- "os"
"v.io/core/veyron2"
"v.io/core/veyron2/context"
@@ -20,6 +19,7 @@
"v.io/core/veyron/lib/flags"
"v.io/core/veyron/lib/netstate"
"v.io/core/veyron/lib/websocket"
+ "v.io/core/veyron/profiles/internal"
"v.io/core/veyron/profiles/internal/gce"
_ "v.io/core/veyron/runtimes/google/ipc/protocols/tcp"
_ "v.io/core/veyron/runtimes/google/ipc/protocols/ws"
@@ -27,25 +27,25 @@
grt "v.io/core/veyron/runtimes/google/rt"
)
-var (
- commonFlags *flags.Flags
-)
+var commonFlags *flags.Flags
func init() {
- commonFlags = flags.CreateAndRegister(flag.CommandLine, flags.Listen)
veyron2.RegisterProfileInit(Init)
stream.RegisterUnknownProtocol("wsh", websocket.HybridDial, websocket.HybridListener)
+ commonFlags = flags.CreateAndRegister(flag.CommandLine, flags.Runtime, flags.Listen)
}
func Init(ctx *context.T) (veyron2.RuntimeX, *context.T, veyron2.Shutdown, error) {
- vlog.Log.VI(1).Infof("Initializing GCE profile.")
if !gce.RunningOnGCE() {
return nil, nil, nil, fmt.Errorf("GCE profile used on a non-GCE system")
}
+ if err := internal.ParseFlags(commonFlags); err != nil {
+ return nil, nil, nil, err
+ }
+
ac := appcycle.New()
- commonFlags.Parse(os.Args[1:], nil)
lf := commonFlags.ListenFlags()
listenSpec := ipc.ListenSpec{
Addrs: ipc.ListenAddrs(lf.Addrs),
@@ -60,11 +60,13 @@
}
}
- runtime, ctx, shutdown, err := grt.Init(ctx, ac, nil, &listenSpec, nil)
+ runtime, ctx, shutdown, err := grt.Init(ctx, ac, nil, &listenSpec, commonFlags.RuntimeFlags(), nil)
if err != nil {
return nil, nil, shutdown, err
}
+ vlog.Log.VI(1).Infof("Initializing GCE profile.")
+
profileShutdown := func() {
ac.Shutdown()
shutdown()