Skip to content

Commit

Permalink
Merged in phstsai/VX-86 (pull request #6)
Browse files Browse the repository at this point in the history
DEV VX-86: RESTful API for Creating Network

Approved-by: Hung-Wei Chiu <[email protected]>
Approved-by: Yo-An Lin <[email protected]>
  • Loading branch information
WakeupTsai authored and c9s committed Jun 14, 2018
2 parents 32dad22 + d08571e commit 28d4459
Show file tree
Hide file tree
Showing 20 changed files with 1,148 additions and 60 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

# log
**/*.log
**/logs

# vagrant
vagrant/credentials
Expand All @@ -16,3 +17,7 @@ vagrant/credentials

# mac
**/.DS_Store

# vendors
vendor/*
!vendor/vendor.json
30 changes: 11 additions & 19 deletions config/k8s.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,32 @@
"port": 32199
}
},
"gearman": {
"host": "gearman-job-server.default",
"port": 4730,
"public": {
"host": "gearman-job-server.default",
"port": 4730
}
},
"mongo": {
"url": "mongodb://mongo-0.mongo:27017/aurora",
"url": "mongodb://mongo-0.mongo:27017/vortex",
"public": {
"url": "mongodb://35.189.177.37:31717/aurora"
"url": "mongodb://35.189.177.37:31717/votex"
}
},
"influxdb": {
"url": "http://influxdb.default:8086",
"database": "lisa"
},
"logger":{
"dir": "./logs",
"level": "debug",
"maxAge": "720h",
"suffixPattern": ".%Y%m%d",
"linkName": "access_log"
"logger": {
"dir": "./logs",
"level": "debug",
"maxAge": "720h",
"suffixPattern": ".%Y%m%d",
"linkName": "access_log"
},
"app": {
"brand": {
"name": "Aurora",
"identifier": "aurora",
"name": "Vortex",
"identifier": "vortex",
"companyName": "Linker Networks Inc."
},
"enableAuthentication": false,
"dbVersion": "v1.0.0",
"version": "<GIT_COMMIT>",
"logFileName": "access_log"
}
}
}
27 changes: 10 additions & 17 deletions config/local.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,28 @@
"host": "localhost"
}
},
"gearman": {
"host": "localhost",
"port": 4730,
"public": {
"host": "localhost"
}
},
"mongo": {
"url": "mongodb://localhost:27017/aurora"
"url": "mongodb://localhost:31717/vortex_test"
},
"influxdb": {
"url": "http://localhost:8086",
"database": "lisa"
},
"logger":{
"dir": "./logs",
"level": "debug",
"maxAge": "720h",
"suffixPattern": ".%Y%m%d",
"linkName": "access_log"
"logger": {
"dir": "./logs",
"level": "debug",
"maxAge": "720h",
"suffixPattern": ".%Y%m%d",
"linkName": "access_log"
},
"app": {
"brand": {
"name": "Aurora",
"identifier": "aurora",
"name": "Vortex",
"identifier": "vortex",
"companyName": "Linker Networks Inc."
},
"dbVersion": "v1.0.0",
"version": "local",
"logFileName": "access_log"
}
}
}
33 changes: 33 additions & 0 deletions config/testing.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"redis": {
"host": "localhost",
"port": 6379,
"public": {
"host": "localhost"
}
},
"mongo": {
"url": "mongodb://localhost:31717/vortex_test"
},
"influxdb": {
"url": "http://localhost:8086",
"database": "lisa"
},
"logger": {
"dir": "./logs",
"level": "debug",
"maxAge": "720h",
"suffixPattern": ".%Y%m%d",
"linkName": "access_log"
},
"app": {
"brand": {
"name": "Vortex",
"identifier": "vortex",
"companyName": "Linker Networks Inc."
},
"dbVersion": "v1.0.0",
"version": "local",
"logFileName": "access_log"
}
}
35 changes: 29 additions & 6 deletions installer/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
# Main

clean:
rm -rf *.log **/*.vmdk **/*.retry

submodule:
git submodule init && git submodule update

.PHONY: ansible
UNAME := $(shell uname)
ifeq ($(UNAME), Linux)

ansible: submodule
sudo apt-get upgrade && apt-get update
sudo apt-get install -y python3 python3-pip jq
sudo pip3 install yq ansible netaddr
sudo pip3 install -r kubespray/requirements.txt

else ifeq ($(UNAME), Darwin)

ansible: submodule
sudo port install jq # sudo brew install jq
sudo pip3 install yq ansible
sudo pip3 install -r kubespray/requirements.txt

endif

deploy-%: submodule
ANSIBLE_HOST_KEY_CHECKING=false ansible-playbook \
--inventory=inventory/$*/hosts.ini \
Expand All @@ -16,11 +41,10 @@ scale-%: submodule
--inventory=inventory/$*/hosts.ini \
kubespray/scale.yml 2>&1 | tee aurora-$(shell date +%F-%H%M%S)-scale.log

clean:
rm -rf *.log **/*.vmdk **/*.retry

submodule:
git submodule init && git submodule update
upgrade-%: submodule
ANSIBLE_HOST_KEY_CHECKING=false ansible-playbook \
--inventory=inventory/$*/hosts.ini \
kubespray/upgrade-cluster.yml 2>&1 | tee aurora-$(shell date +%F-%H%M%S)-upgrade.log

# Vagrant

Expand All @@ -40,4 +64,3 @@ gce-up: submodule
gce-up.yml 2>&1 | tee aurora-$(shell date +%F-%H%M%S)-gce-up.log

gce: gce-up deploy-gce

18 changes: 8 additions & 10 deletions installer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Vortex Installer is an ansible playbook to install Vortex platform to server(s).

# Install Life Cycle

0. Obtain GCR key
0. Obtain GCR key for Aurora
1. Bring up VMs / prepare bare metal servers
2. Create ssh key for VMs/servers
3. Edit config files `inventory/*/host.ini`
Expand All @@ -16,18 +16,16 @@ Vortex Installer is an ansible playbook to install Vortex platform to server(s).

### Prerequsites

ubuntu
```
apt-get upgrade && apt-get update
Install packages:

apt-get install -y python3 python-pip
pip install ansible netaddr
# Don't use apt ansible package
```
- python
- pip
- ansible: executor to run ansible-playbook
- jq: json processor
- yq: yaml processor

Mac
```
pip install ansible netaddr
make ansible
```

### Obtain a GCR key (needed by Aurora)
Expand Down
12 changes: 5 additions & 7 deletions installer/inventory/5g/hosts.ini
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
# ## Configure 'ip' variable to bind kubernetes services on a
# ## different ip than the default iface
master ansible_ssh_host=192.168.26.10 ip=192.168.26.10
node-1 ansible_ssh_host=192.168.26.11 ip=192.168.26.11
node-2 ansible_ssh_host=192.168.26.12 ip=192.168.26.12
vortex-master ansible_ssh_host=10.1.14.14 ip=10.1.14.14
vortex-node-1 ansible_ssh_host=10.1.14.86 ip=10.1.14.86

# ## configure a bastion host if your nodes are not directly reachable
# bastion ansible_host=x.x.x.x ansible_user=some_user

[kube-master]
master
vortex-master

[etcd]
master
vortex-master

[kube-node]
node-1
node-2
vortex-node-1

[k8s-cluster:children]
kube-master
Expand Down
2 changes: 1 addition & 1 deletion installer/inventory/vagrant/group_vars/k8s-cluster.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ kube_users_dir: "{{ kube_config_dir }}/users"
kube_api_anonymous_auth: true

## Change this to use another Kubernetes version, e.g. a current beta release
kube_version: v1.9.8
kube_version: v1.10.4

# Where the binaries will be downloaded.
# Note: ensure that you've enough disk space (about 1G)
Expand Down
32 changes: 32 additions & 0 deletions src/entity/network.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package entity

import (
"time"

"gopkg.in/mgo.v2/bson"
)

const (
NetworkCollectionName string = "networks"
)

type PhysicalPort struct {
Name string `bson:"name" json:"name"`
MTU int `bson:"maximumTransmissionUnit" MTC:"maximumTransmissionUnit"`
VlanTags []int `bson:"vlanTag" MTC:"vlanTag"`
}

type Network struct {
ID bson.ObjectId `bson:"_id,omitempty" json:"id"`
DisplayName string `bson:"displayName" json:"displayName"`
BridgeName string `bson:"bridgeName" json:"bridgeName"`
BridgeType string `bson:"bridgeType" json:"bridgeType"`
Node string `bson:"node" json:"node"`
PhysicalPorts []PhysicalPort `bson:"physicalPorts" json:"physicalPorts"`
CreatedAt *time.Time `bson:"createdAt,omitempty" json:"createdAt,omitempty"`
}

//GetCollection - get model mongo collection name.
func (m Network) GetCollection() string {
return NetworkCollectionName
}
30 changes: 30 additions & 0 deletions src/net/http/handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package http

import (
"net/http"

"bitbucket.org/linkernetworks/vortex/src/serviceprovider"
"bitbucket.org/linkernetworks/vortex/src/web"
"github.com/emicklei/go-restful"
"github.com/linkernetworks/logger"
)

type NativeContextHandler func(*web.NativeContext)

// CompositeServiceProvider apply mongo client to HandlerFunc
func CompositeServiceHandler(sp *serviceprovider.Container, handler NativeContextHandler) http.HandlerFunc {
return func(resp http.ResponseWriter, req *http.Request) {
logger.Infoln(req.Method, req.URL)
ctx := web.NativeContext{sp, req, resp}
handler(&ctx)
}
}

type RESTfulContextHandler func(*web.Context)

func RESTfulServiceHandler(sp *serviceprovider.Container, handler RESTfulContextHandler) restful.RouteFunction {
return func(req *restful.Request, resp *restful.Response) {
ctx := web.Context{sp, req, resp}
handler(&ctx)
}
}
Loading

0 comments on commit 28d4459

Please sign in to comment.