Skip to content

Commit

Permalink
[CE-161] Auto pull fabric images for vSphere host
Browse files Browse the repository at this point in the history
1> Auto pull the images when after worker node
vm power on

2> Auto tag the images to latest after all the
images has been pulled

Change-Id: I4f80ffe28528ff375bb7d71f2397743691db2d47
Signed-off-by: hainingzhang <haininghenryzh@vmware.com>
  • Loading branch information
hainingzhang committed Oct 31, 2017
1 parent f5b818b commit bc08be0
Show file tree
Hide file tree
Showing 5 changed files with 400 additions and 315 deletions.
3 changes: 1 addition & 2 deletions src/agent/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
compose_up, compose_clean, compose_start, compose_stop, compose_restart, \
setup_container_host, cleanup_host, reset_container_host

from .vsphere.host_operations import create_vm, delete_vm, \
check_vc_resource, initializesi
from .vsphere.host_operations import VsphereOperation

from .docker.host import DockerHost
from .docker.cluster import ClusterOnDocker
Expand Down
60 changes: 30 additions & 30 deletions src/agent/vsphere/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
VC_DATASTORE, VC_DATACENTER, NETWORK, TEMPLATE, VC_CLUSTER

from agent import reset_container_host, check_daemon, \
create_vm, delete_vm, check_vc_resource, \
initializesi
VsphereOperation

from ..host_base import HostBase

logger = logging.getLogger(__name__)
logger.setLevel(LOG_LEVEL)
logger.addHandler(log_handler)
operation = VsphereOperation()


class VsphereHost(HostBase):
Expand All @@ -40,25 +40,25 @@ def create(self, vcip, username, pwd, port, params):
"""
# Init connection
try:
si = initializesi(vcip, username, pwd, port)
si = operation.initializesi(vcip, username, pwd, port)
connection = si.RetrieveContent()
vc_resources = params.get(VCENTER)

except Exception as e:
error_msg = (
"Cannot complete login due to"
" an incorrect user name or password."
"Cannot complete login due"
"to an incorrect user name or password."
)
raise Exception(error_msg)

# Check cluster
cluster = check_vc_resource(connection,
[vim.ClusterComputeResource],
vc_resources[VC_CLUSTER])
cluster = operation.check_vc_resource(connection,
[vim.ClusterComputeResource],
vc_resources[VC_CLUSTER])
if cluster is None:
error_msg = (
"The Cluster: {} does not exist"
" or exception is raised."
"or exception is raised."
).format(vc_resources[VC_CLUSTER])

logger.error(error_msg)
Expand All @@ -68,13 +68,13 @@ def create(self, vcip, username, pwd, port, params):
vc_resources[VC_CLUSTER] = cluster

# Check datacenter
datacenter = check_vc_resource(connection,
[vim.Datacenter],
vc_resources[VC_DATACENTER])
datacenter = operation.check_vc_resource(connection,
[vim.Datacenter],
vc_resources[VC_DATACENTER])
if datacenter is None:
error_msg = (
"The DataCenter: {} does not exist"
" or exception is raised."
"The DataCenter: {} does not exist,"
"or exception is raised."
).format(vc_resources[VC_DATACENTER])

logger.error(error_msg)
Expand All @@ -84,13 +84,13 @@ def create(self, vcip, username, pwd, port, params):
vc_resources[VC_DATACENTER] = datacenter

# Check datastore
datastore = check_vc_resource(connection,
[vim.Datastore],
vc_resources[VC_DATASTORE])
datastore = operation.check_vc_resource(connection,
[vim.Datastore],
vc_resources[VC_DATASTORE])
if datastore is None:
error_msg = (
"The Datastore: {} does not exist"
" or exception is raised."
"The Datastore: {} does not exist,"
"or exception is raised."
).format(vc_resources[VC_DATASTORE])

logger.error(error_msg)
Expand All @@ -100,13 +100,13 @@ def create(self, vcip, username, pwd, port, params):
vc_resources[VC_DATASTORE] = datastore

# Check template
template = check_vc_resource(connection,
[vim.VirtualMachine],
vc_resources[TEMPLATE])
template = operation.check_vc_resource(connection,
[vim.VirtualMachine],
vc_resources[TEMPLATE])
if template is None:
error_msg = (
"The template: {} does not exist"
" or exception is raised."
"or exception is raised."
).format(vc_resources[TEMPLATE])

logger.error(error_msg)
Expand All @@ -116,13 +116,13 @@ def create(self, vcip, username, pwd, port, params):
vc_resources[TEMPLATE] = template

# Check network
network = check_vc_resource(connection,
[vim.Network],
vc_resources[NETWORK])
network = operation.check_vc_resource(connection,
[vim.Network],
vc_resources[NETWORK])
if network is None:
error_msg = (
"The network: {} does not exist"
" or exception is raised."
"The network: {} does not exist,"
"or exception is raised."
).format(vc_resources[NETWORK])

logger.error(error_msg)
Expand All @@ -131,7 +131,7 @@ def create(self, vcip, username, pwd, port, params):
else:
vc_resources[NETWORK] = network

create_vm(connection, params)
operation.create_vm(connection, params)
return True

def delete(self, vmuuid, vcip, username, pwd, port=443):
Expand All @@ -144,7 +144,7 @@ def delete(self, vmuuid, vcip, username, pwd, port=443):
:param port vCenter port
:return:
"""
return delete_vm(vcip, username, pwd, port, vmuuid)
return operation.delete_vm(vcip, username, pwd, port, vmuuid)

def reset(self, worker_api, host_type='docker'):
"""
Expand Down
Loading

0 comments on commit bc08be0

Please sign in to comment.