summaryrefslogtreecommitdiff
path: root/setup.py
diff options
context:
space:
mode:
authorBen Howard <ben.howard@ubuntu.com>2015-08-14 16:40:41 -0600
committerusd-importer <ubuntu-server@lists.ubuntu.com>2015-08-15 14:33:21 +0000
commitf78b9650d0e7b008d430673a075aad95dda863be (patch)
treea6749619e78483d45a66d4bad4d6e922391541fc /setup.py
parent0afc048f2a6ff3638ecfa33e7ded5dc8dddf041a (diff)
downloadvyos-walinuxagent-f78b9650d0e7b008d430673a075aad95dda863be.tar.gz
vyos-walinuxagent-f78b9650d0e7b008d430673a075aad95dda863be.zip
Import patches-unapplied version 2.1.1-0ubuntu1 to ubuntu/wily-proposed
Imported using git-ubuntu import. Changelog parent: 0afc048f2a6ff3638ecfa33e7ded5dc8dddf041a New changelog entries: * New upstream release for Ubuntu. - Switch to Python3 - Applies Ubuntu specific patches
Diffstat (limited to 'setup.py')
-rwxr-xr-xsetup.py310
1 files changed, 127 insertions, 183 deletions
diff --git a/setup.py b/setup.py
index d2a2416..8a7a7c0 100755
--- a/setup.py
+++ b/setup.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
#
# Windows Azure Linux Agent setup.py
#
@@ -16,200 +16,144 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
-import glob
+
import os
-import sys
-import platform
+from azurelinuxagent.metadata import AGENT_NAME, AGENT_VERSION, \
+ AGENT_DESCRIPTION, \
+ DISTRO_NAME, DISTRO_VERSION, DISTRO_FULL_NAME
+
+from azurelinuxagent.utils.osutil import OSUTIL
+import azurelinuxagent.agent as agent
import setuptools
-from setuptools.command.install import install
+from setuptools import find_packages
+from setuptools.command.install import install as _install
+
+root_dir = os.path.dirname(os.path.abspath(__file__))
+os.chdir(root_dir)
+
+def set_files(data_files, dest=None, src=None):
+ data_files.append((dest, src))
+
+def set_bin_files(data_files, dest="/usr/sbin",
+ src=["bin/waagent", "bin/waagent2.0"]):
+ data_files.append((dest, src))
-from distutils.errors import DistutilsArgError
+def set_conf_files(data_files, dest="/etc", src=["config/waagent.conf"]):
+ data_files.append((dest, src))
-def getDistro():
+def set_logrotate_files(data_files, dest="/etc/logrotate.d",
+ src=["config/waagent.logrotate"]):
+ data_files.append((dest, src))
+
+def set_sysv_files(data_files, dest="/etc/rc.d/init.d", src=["init/waagent"]):
+ data_files.append((dest, src))
+
+def set_systemd_files(data_files, dest="/lib/systemd/system",
+ src=["init/waagent.service"]):
+ data_files.append((dest, src))
+
+def get_data_files(name, version, fullname):
"""
- Try to figure out the distribution we are running on
+ Determine data_files according to distro name, version and init system type
"""
- distro = platform.linux_distribution()[0].lower()
- # Manipulate the distribution to meet our needs we treat
- # Fedora, RHEL, and CentOS the same
- # openSUSE and SLE the same
- if distro.find('suse') != -1:
- distro = 'suse'
- if (distro.find('fedora') != -1
- or distro.find('red hat') != -1
- or distro.find('centos') != -1):
- distro = 'redhat'
-
- return distro
-
-class InstallData(install):
- user_options = install.user_options + [
+ data_files=[]
+
+ if name == 'redhat' or name == 'centos':
+ set_bin_files(data_files)
+ set_conf_files(data_files)
+ set_logrotate_files(data_files)
+ if version >= "7.0":
+ #redhat7.0+ uses systemd
+ set_systemd_files(data_files, dest="/var/lib/systemd/system")
+ else:
+ set_sysv_files(data_files)
+
+ elif name == 'coreos':
+ set_bin_files(data_files, dest="/usr/share/oem/bin")
+ set_conf_files(data_files, dest="/usr/share/oem")
+ set_logrotate_files(data_files)
+ set_files(data_files, dest="/usr/share/oem",
+ src="init/coreos/cloud-config.yml")
+ elif name == 'ubuntu':
+ set_bin_files(data_files)
+ set_conf_files(data_files, src=["config/ubuntu/waagent.conf"])
+ set_logrotate_files(data_files)
+ if version < "15.04":
+ #Ubuntu15.04- uses upstart
+ set_files(data_files, dest="/etc/init",
+ src=["init/ubuntu/walinuxagent.conf"])
+ set_files(data_files, dest='/etc/default',
+ src=['init/ubuntu/walinuxagent'])
+ elif fullname == 'Snappy Ubuntu Core':
+ set_files(data_files, dest="<TODO>",
+ src=["init/ubuntu/snappy/walinuxagent.yml"])
+ else:
+ set_systemd_files(data_files,
+ src=["init/ubuntu/walinuxagent.service"])
+ elif name == 'suse':
+ set_bin_files(data_files)
+ set_conf_files(data_files, src=["config/suse/waagent.conf"])
+ set_logrotate_files(data_files)
+ if fullname == 'SUSE Linux Enterprise Server' and version >= '12' or \
+ fullname == 'openSUSE' and version >= '13.2':
+ set_systemd_files(data_files, dest='/var/lib/systemd/system')
+ else:
+ set_sysv_files(data_files, dest='/etc/init.d')
+ else:
+ #Use default setting
+ set_bin_files(data_files)
+ set_conf_files(data_files)
+ set_logrotate_files(data_files)
+ set_sysv_files(data_files)
+ return data_files
+
+class install(_install):
+ user_options = _install.user_options + [
# This will magically show up in member variable 'init_system'
- ('init-system=', None, 'init system to configure [default: sysV]'),
+ ('init-system=', None, 'deprecated, use --lnx-distro* instead'),
('lnx-distro=', None, 'target Linux distribution'),
+ ('lnx-distro-version=', None, 'target Linux distribution version'),
+ ('lnx-distro-fullname=', None, 'target Linux distribution full name'),
+ ('register-service', None, 'register as startup service'),
+ ('skip-data-files', None, 'skip data files installation'),
]
def initialize_options(self):
- install.initialize_options(self)
- self.init_system = 'sysV'
- self.lnx_distro = None
-
+ _install.initialize_options(self)
+ self.init_system=None
+ self.lnx_distro = DISTRO_NAME
+ self.lnx_distro_version = DISTRO_VERSION
+ self.lnx_distro_fullname = DISTRO_FULL_NAME
+ self.register_service = False
+ self.skip_data_files = False
+
def finalize_options(self):
- install.finalize_options(self)
- if not self.lnx_distro:
- self.lnx_distro = getDistro()
- if self.init_system not in ['sysV', 'systemd', 'upstart']:
- print 'Do not know how to handle %s init system' %self.init_system
- sys.exit(1)
- if self.init_system == 'sysV':
- if not os.path.exists('distro/%s' %self.lnx_distro):
- msg = 'Unknown distribution "%s"' %self.lnx_distro
- msg += ', no entry in distro directory'
- sys.exit(1)
-
- def run(self):
- """
- Install the files for the Windows Azure Linux Agent
- """
- distro = self.lnx_distro
- init = self.init_system
- prefix = self.prefix
- tgtDir = self.root
- if prefix and prefix[-1] != '/':
- prefix += '/'
- else:
- prefix = '/'
- if tgtDir and tgtDir[-1] != '/':
- tgtDir += '/'
- else:
- tgtDir = '/'
- # Handle the different init systems
- if init == 'sysV':
- initdir = 'etc/init.d'
- if self.lnx_distro == 'redhat':
- initdir = 'etc/rc.d/init.d'
- if not os.path.exists(tgtDir + initdir):
- try:
- self.mkpath(tgtDir + initdir, 0755)
- except:
- msg = 'Could not create init script directory '
- msg += tgtDir
- msg += initdir
- print msg
- print sys.exc_info()[0]
- sys.exit(1)
- initScripts = glob.glob('distro/%s/*.sysV' %distro)
- try:
- for f in initScripts:
- newName = f.split('/')[-1].split('.')[0]
- self.copy_file(f, tgtDir + initdir + '/' + newName)
- except:
- print 'Could not install systemV init script',
- sys.exit(1)
- elif init == 'systemd':
- if not os.path.exists(tgtDir + prefix +'lib/systemd/system'):
- try:
- self.mkpath(tgtDir + prefix + 'lib/systemd/system', 0755)
- except:
- msg = 'Could not create systemd service directory '
- msg += tgtDir + prefix
- msg += 'lib/systemd/system'
- print msg
- sys.exit(1)
- services = glob.glob('distro/systemd/*')
- for f in services:
- try:
- baseName = f.split('/')[-1]
- self.copy_file(f,
- tgtDir + prefix +'lib/systemd/system/' + baseName)
- except:
- print 'Could not install systemd service files'
- sys.exit(1)
- elif init == 'upstart':
- print 'Upstart init files installation not supported at this time.'
- print 'Need an implementation, please submit a patch ;)'
- print 'See WALinuxAgent/debian directory for Debian/Ubuntu packaging'
-
- # Configuration file
- if not os.path.exists(tgtDir + 'etc'):
- try:
- self.mkpath(tgtDir + 'etc', 0755)
- except:
- msg = 'Could not create config dir '
- msg += tgtDir
- msg += 'etc'
- print msg
- sys.exit(1)
- try:
- self.copy_file('config/waagent.conf', tgtDir + 'etc/waagent.conf')
- except:
- print 'Could not install configuration file %setc' %tgtDir
- sys.exit(1)
-
- if not os.path.exists(tgtDir + 'etc/udev/rules.d'):
- try:
- self.mkpath(tgtDir + 'etc/udev/rules.d', 0755)
- except Exception as e:
- print e
-
- try:
- self.copy_file('config/99-azure-product-uuid.rules', tgtDir + 'etc/udev/rules.d/99-azure-product-uuid.rules')
- except Exception as e:
- print e
- print 'Could not install product uuid rules file %setc' %tgtDir
- sys.exit(1)
-
- if not os.path.exists(tgtDir + 'etc/logrotate.d'):
- try:
- self.mkpath(tgtDir + 'etc/logrotate.d', 0755)
- except:
- msg = 'Could not create ' + tgtDir + 'etc/logrotate.d'
- print msg
- sys.exit(1)
- try:
- self.copy_file('config/waagent.logrotate',
- tgtDir + 'etc/logrotate.d/waagent')
- except:
- msg = 'Could not install logrotate file in '
- msg += tgtDir + 'etc/logrotate.d'
- print msg
- sys.exit(1)
-
- # Daemon
- if not os.path.exists(tgtDir + prefix + 'sbin'):
- try:
- self.mkpath(tgtDir + prefix + 'sbin', 0755)
- except:
- msg = 'Could not create target daemon dir '
- msg+= tgtDir + prefix + 'sbin'
- print msg
- sys.exit(1)
- try:
- self.copy_file('waagent', tgtDir + prefix + 'sbin/waagent')
- except:
- print 'Could not install daemon %s%ssbin/waagent' %(tgtDir,prefix)
- sys.exit(1)
- os.chmod('%s%ssbin/waagent' %(tgtDir,prefix), 0755)
-
-def readme():
- with open('README') as f:
- return f.read()
-
-setuptools.setup(name = 'waagent',
- version = '1.4.0',
- description = 'Windows Azure Linux Agent',
- long_description = readme(),
- author = 'Stephen Zarkos, Eric Gable',
- author_email = 'walinuxagent@microsoft.com',
- platforms = 'Linux',
- url = 'https://github.com/Windows-Azure/',
- license = 'Apache License Version 2.0',
- cmdclass = {
- # Use a subclass for install that handles
- # install, we do not have a "true" python package
- 'install': InstallData,
- },
-)
+ _install.finalize_options(self)
+ if self.skip_data_files:
+ return
+ if self.init_system is not None:
+ print("WARNING: --init-system is deprecated,"
+ "use --lnx-distro* instead")
+ data_files = get_data_files(self.lnx_distro, self.lnx_distro_version,
+ self.lnx_distro_fullname)
+ self.distribution.data_files = data_files
+ self.distribution.reinitialize_command('install_data', True)
+ def run(self):
+ _install.run(self)
+ if self.register_service:
+ agent.register_service()
+setuptools.setup(name=AGENT_NAME,
+ version=AGENT_VERSION,
+ long_description=AGENT_DESCRIPTION,
+ author= 'Yue Zhang, Stephen Zarkos, Eric Gable',
+ author_email = 'walinuxagent@microsoft.com',
+ platforms = 'Linux',
+ url='https://github.com/Azure/WALinuxAgent',
+ license = 'Apache License Version 2.0',
+ packages=find_packages(exclude=["tests"]),
+ cmdclass = {
+ 'install': install
+ })