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

Basic Structure #5

Open
wants to merge 69 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
63590c4
Initial structure
thenakliman Mar 14, 2016
a0a4a1a
Removed .pyc file
thenakliman Mar 14, 2016
7a1ce10
Removed pyc files
thenakliman Mar 14, 2016
f5733a4
correction in files
thenakliman Mar 14, 2016
0d3cf5b
Added basic structure
thenakliman Mar 15, 2016
76e47a7
Changed code structure
thenakliman Mar 16, 2016
33b69b6
Added base module for curl request
karelyatin Mar 17, 2016
4129a5e
Merge pull request #1 from karelyatin/feature_scheduler
karelyatin Mar 17, 2016
6103cd3
Change in structure
thenakliman Mar 17, 2016
0d56ca3
Added structure for Scheduler
thenakliman Mar 21, 2016
b576615
Image create
thenakliman Mar 22, 2016
5c1b300
updated image create
karelyatin Mar 23, 2016
ef6f987
Merge pull request #2 from karelyatin/feature_scheduler
karelyatin Mar 23, 2016
ca1a0f5
Code merged
thenakliman Mar 24, 2016
6614c12
Merge branch 'feature_scheduler' of https://github.com/thenakliman/do…
thenakliman Mar 24, 2016
95642c8
Network and volume
thenakliman Mar 27, 2016
ed966e8
used urllib for post
karelyatin Mar 29, 2016
ee11d02
Merge pull request #3 from karelyatin/feature_scheduler
karelyatin Mar 29, 2016
a578983
Container with post requests
thenakliman Mar 29, 2016
e632caa
added methods network and volume
karelyatin Mar 29, 2016
bd88e15
Merge pull request #4 from karelyatin/feature_scheduler
karelyatin Mar 29, 2016
09b44bd
Changed permission and added some API
thenakliman Apr 2, 2016
26297a8
added methods to images
karelyatin Apr 2, 2016
215a1a5
Changes for the latest api
thenakliman Apr 4, 2016
839f52c
Changes in containers, images, networks, no changes in volumes
thenakliman Apr 23, 2016
1510445
Changes for volumes
thenakliman Apr 24, 2016
3156873
Added functionality for driver of scheduler
thenakliman Apr 24, 2016
ba00f2f
Removed base.py
thenakliman Apr 24, 2016
8959150
Changes for membership
thenakliman Apr 25, 2016
0eff03a
Changes for consul
thenakliman Apr 25, 2016
aa26361
Consul Changes
thenakliman Apr 27, 2016
a8bdcb8
Consul driver added
thenakliman Apr 28, 2016
b2f4425
Added Consul exceptions
thenakliman Apr 28, 2016
562efac
Added dockyard-engine for processing
thenakliman May 8, 2016
cd1e570
Changes in Linux bridge drivers
thenakliman May 13, 2016
6dac2c3
corrections ..
thenakliman May 13, 2016
819b715
Corrections
May 14, 2016
f317a7c
Corrections in implementation
thenakliman May 14, 2016
2e5099c
Modifications
thenakliman May 17, 2016
d7268cb
Corrections in bridge driver
thenakliman May 18, 2016
8faeee7
Added suport for adding routes for the new network
thenakliman May 20, 2016
6efb915
Fixed for issues 20, 24, 25, 27, 28, 29, 31
May 21, 2016
4081893
Patch for Issue 22
May 21, 2016
f5b6a8b
Work on Controller for docker engine
thenakliman May 23, 2016
94ddbe9
API for interface
thenakliman May 25, 2016
b6fe20e
APIs for interface
thenakliman May 26, 2016
d6db3c4
included oslo logging against issue #6
karelyatin May 28, 2016
8fcdf5f
Merge pull request #45 from karelyatin/feature_scheduler
karelyatin May 28, 2016
d53e546
Additing API's for addition of IP address.
May 28, 2016
8b1bcff
Adding preprocessor and post processor for requests
thenakliman May 29, 2016
d206f34
Resolved merge conflicts
thenakliman May 29, 2016
6a2260c
Added controllers for dockyard engine.
thenakliman May 30, 2016
1e8a311
updated for dockyard engine APIs
thenakliman May 31, 2016
adb61a3
Corrections for attaching floating ip API
thenakliman Jun 1, 2016
b1159c2
restructure of the code.
thenakliman Jun 5, 2016
b25a26c
Added check for consul servics
thenakliman Jun 10, 2016
3e31fb6
Changes in consul driver
thenakliman Jun 14, 2016
e14fcfb
Changes for consul to return only up nodes
thenakliman Jun 14, 2016
36fc8a3
Fixed issue #10
thenakliman Jun 18, 2016
e72898f
Fixes for Providing storage capablity
thenakliman Jun 19, 2016
bdb4806
Changes for consul as database
thenakliman Jun 22, 2016
c56e01d
Problem removed for wait time
Jun 28, 2016
407fc4b
Added code again
thenakliman Jun 28, 2016
99af59d
Scheduling on more than on node
thenakliman Jun 29, 2016
883fe7f
Adding logic for preprocessing and post processing
thenakliman Jul 2, 2016
92ea031
Added support for synchronization
thenakliman Jul 5, 2016
800e5d9
Added synchronization for all objects
thenakliman Jul 5, 2016
9dfb7f1
added change for storing only IDs of resources
thenakliman Jul 6, 2016
cc1a0f9
To optimize speed of earch converted list to dict
thenakliman Jul 6, 2016
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pyc
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
recursive-include public *
3 changes: 3 additions & 0 deletions bugs/fixed_bugs.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
=================================================================
Add fixed bugs in this file. Select a format to add bugs.
=================================================================
3 changes: 3 additions & 0 deletions bugs/implemented_blueprints.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
========================================================================
Add already implemented.
========================================================================
15 changes: 15 additions & 0 deletions bugs/known_bugs.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
=================================================================
Add known bugs in this file. Select a format to add bugs.
=================================================================
1) Add support for different communication mechnism between api server
and engine.
--> Message queue
--> API server itself

2) Create /var/run/netns at the start of the dockyard.
3) Add database feature to keep data even after reboot.
4) Add feature to create resource as dockyard start.
5) Write a single function, which will load modules dynmically by taking
information from the configuration file. It is being done many times in
the project which will lead to resuability of the code.
6) Create an API for attaching external network to the docker container
4 changes: 4 additions & 0 deletions bugs/new_blueprints.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
========================================================================
Add blueprints that needs to implmented.
========================================================================
1. Monitoring of containers. User can specify which container to monitor. The monitoring module would monitor the containers and start the stopped container.
Empty file added dockyard/__init__.py
Empty file.
Empty file added dockyard/api/__init__.py
Empty file.
44 changes: 44 additions & 0 deletions dockyard/api/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from oslo_config import cfg
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think some requirement file also need to be created which specify the dependency modules(ex. oslo_config) for running dockyard.

import pecan
from pecan import make_app

from dockyard.api import config as api_config
# To be used later for initialization of database
#from dockyard import model


API_SERVICE_OPT = [
cfg.PortOpt('port',
default=5869,
help='Port for the dockyard service.'),
cfg.IPOpt('host',
default='0.0.0.0',
help='Listening address for dockyard service'),
]

CONF = cfg.CONF
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure but there must be a way to define values of these parameters through configuration file. So that these default values can be overridden. 💯

opt_group = cfg.OptGroup(name='default',
title='Group for the default values of dockyard api')
CONF.register_group(opt_group)
CONF.register_opts(API_SERVICE_OPT, opt_group)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Provide a sample file also for the reference, so that it can be used for development purpose.



def get_pecan_config():
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of this function, we have to identify and then remove if not required.

# Set up the pecan configuration
filename = api_config.__file__.replace('.pyc', '.py')
return pecan.configuration.conf_from_file(filename)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think specific import can be done here, from pecan import configuration, need to check any guideline, use better and consistent.



Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Write documentation for the each class and method of the class or function.

def setup_app(config=None):
if not config:
config = get_pecan_config()

# To be used later for initialization of database
# model.init_model()
app_conf = dict(config.app)

return make_app(
app_conf.pop('root'),
logging=getattr(config, 'logging', {}),
**app_conf
)
6 changes: 6 additions & 0 deletions dockyard/api/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Pecan Application Configurations
app = {
'root': 'dockyard.controllers.root.RootController',
'modules': ['dockyard', 'dockyard.api'],
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per documentation, for modules key values should be one. You can have two values but recommended is one.
It's should be in the same directory, where your app.py file is located.

Therefor correct it and put only one required value.

'debug': True
}
Empty file added dockyard/cmd/__init__.py
Empty file.
31 changes: 31 additions & 0 deletions dockyard/cmd/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import os
import sys

from oslo_config import cfg
from oslo_log import log as logging
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logging not used in this module

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently application is running in foreground, we need to make it run as a service.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

from wsgiref import simple_server

from dockyard.api import app as api_app
from dockyard.common import utils


LOG = logging.getLogger(__name__)

def main():
utils.prepare_logging(sys.argv)

app = api_app.setup_app()

# create the wsgi server and start it
host, port = cfg.CONF.default.host, cfg.CONF.default.port
srv = simple_server.make_server(host, port, app)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to decide about loggin polices, As logging is not being done now.


LOG.info('Starting dockyard in PID %s', os.getpid())
LOG.debug("Configuration:")
cfg.CONF.log_opt_values(LOG, logging.DEBUG)

LOG.info('serving at http://%s:%s' % (host, port))
srv.serve_forever()


main()
106 changes: 106 additions & 0 deletions dockyard/common/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import ast
import importlib
from oslo_config import cfg
from threading import Thread
import time
from dockyard.common.container.container import Container
from dockyard.common.image.image import Image
from dockyard.common.network.network import Network
from dockyard.common.volume.volume import Volume
from dockyard.common.utils import get_localhost_ip
from dockyard.engine_client.synchronizer.synchronizer import (
ContainerSynchronizer)

CONF = cfg.CONF


class Synchronizer(Thread):
def __init__(self):
if CONF.docker.docker_host == "0.0.0.0":
for ip in get_localhost_ip():
host = ip
break
else:
host = CONF.docker.docker_host

port = CONF.docker.docker_port
self.host = { 'host': host, 'port': port }
Thread.__init__(self)
self.container = Container()
self.image = Image()
self.network = Network()
self.volume = Volume()
self.synchronizer = ContainerSynchronizer()
self.sleep_time = CONF.database.synchronization_time


def run(self):
"""This thread is responsible for synchronizations of containers,
and other docker resources.
"""
while True:
self._synchronize()
time.sleep(self.sleep_time)

def _get_format(self, value, type_):
"""This method converts a container information into the required format
for the container.
"""
f_val = dict()
for v in value:
f_val[v] = "OK"

value = {type_: f_val}
key = (self.host["host"], type_)
return (key, value)

def _synchronize_container(self):
containers = self.container.list(host=self.host)
return self._sync(containers, type_="container")

def _synchronize_image(self):
images = self.image.list(host=self.host)
return self._sync(images, type_="image")

def _synchronize_network(self):
networks = self.network.list(host=self.host)
return self._sync(networks, type_="network")

def _synchronize_volume(self):
volumes = self.container.list(host=self.host)
return self._sync(volumes, type_="volume")

def _get_ids(self, info_s):
"""This method returns all the values ids from the list of
dictionary received.
"""
ids = [x["Id"] for x in info_s]
return ids

def _sync(self, info_s, type_=None):
info_s = info_s.replace("null", "None")
info_s = info_s.replace("true", "True")
info_s = info_s.replace("false", "False")
info_s = ast.literal_eval(info_s)
info_s = self._get_ids(info_s)
info_s = self._get_format(value=info_s, type_=type_)
self.synchronizer.synchronize([info_s])

def _synchronize(self):
"""This method fetch all the containers running on local machines.
"""
self._synchronize_container()
self._synchronize_volume()
self._synchronize_image()
self._synchronize_network()


def run_synchronizer():
"""This method is responsible for synchronizing containers information
with the consul databse.
"""
sync = Synchronizer()
sync.setName("Synchronizer")
sync.start()

run_synchronizer()
77 changes: 77 additions & 0 deletions dockyard/common/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import abc
import importlib
from oslo_config import cfg
from pecan import request
from urllib3 import PoolManager

ENGINE_CLIENT_OPT = [
cfg.StrOpt('engine_client',
default='api_server.api_server.APIServerEngineClient',
help='Client to be used for sending request to engine')
]

CONF = cfg.CONF
CONF.register_opts(ENGINE_CLIENT_OPT, group='default')

# Fetch scheduler defined in the configuration file and load it.
engine_client_info = CONF.default.engine_client
# May be this path can be specified in the configuration file.
engine_client_loc = 'dockyard.engine_client'
engine_client_info = (('%s.%s') % (engine_client_loc, engine_client_info))
module_name, class_name = engine_client_info.rsplit(".", 1)
engine_client = getattr(importlib.import_module(module_name), class_name)

class URL(object):
def __init__(self):
pass

@abc.abstractmethod
def send(self, method, url, headers=None, post_params=None,
body=None, **kwargs):
"""This methos is responsible for sending the request.
:method: Method to be used for sending request.
:url: URL to be send.
:headers: headers in the requests.
:post_params: post parameters.
:body: Request body.
"""

class DockyardURL(URL):
def __init__(self):
self.engine_client = engine_client()
self.pool = PoolManager()

def _is_local_request(self):
"""This method checks whether this is request for docker engine.
"""
try:
request.headers.environ['Request-Status']
except KeyError:
status = False
except:
status = True

return status

def send(self, method, url, headers=None, post_params=None,
body=None, **kwargs):
"""This methos is responsible for sending the request.
:method: Method to be used for sending request.
:url: URL to be send.
:headers: headers in the requests.
:post_params: post parameters.
:body: Request body.
"""
req_type = self._is_local_request()
# Pre processing needs to be done for dockyard feature before
# performing some actions
if req_type:
self.engine_client.process(method=method, url=url, r_type="pre",
body=body, headers=headers)

data = self.pool.urlopen(method, url, headers=headers, body=body).data
# Post processing needs to be done for some of the dockyard operations
if req_type:
self.engine_client.process(method=method, url=url, r_type="post",
body=body, headers=headers)
return data
Empty file.
17 changes: 17 additions & 0 deletions dockyard/common/cluster/cluster.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from oslo_config import cfg
from oslo_log import log as logging


class Cluster(object):
def __init__(self):
pass

def register(self, cluster_id, host_ip, port):
pass

def unregister(self, cluster_id, host_ip):
pass

def get_hosts(self):
LOG.debug("Registered hosts: %s" % cfg.CONF.membership.hosts)
return cfg.CONF.membership.hosts
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Write a better membership algorithm because this one always adds its own host only.

We have to decide about membership protocol to be used in this product.

Empty file.
Empty file.
Loading