def configure(): cleanup() os.makedirs(CALICO_UPGRADE_DIR) # Extract calico-upgrade resource architecture = arch() if architecture == 'amd64': resource_name = 'calico-upgrade' else: resource_name = 'calico-upgrade-' + architecture archive = resource_get(resource_name) if not archive: message = 'Missing calico-upgrade resource' status_set('blocked', message) raise ResourceMissing(message) check_call(['tar', '-xvf', archive, '-C', CALICO_UPGRADE_DIR]) # Configure calico-upgrade, etcd2 (data source) etcd = endpoint_from_flag('etcd.available') etcd_endpoints = etcd.get_connection_string() etcd2_data = { 'apiVersion': 'v1', 'kind': 'calicoApiConfig', 'metadata': None, 'spec': { 'datastoreType': 'etcdv2', 'etcdEndpoints': etcd_endpoints, 'etcdKeyFile': ETCD_KEY_PATH, 'etcdCertFile': ETCD_CERT_PATH, 'etcdCACertFile': ETCD_CA_PATH } } with open(ETCD2_DATA_PATH, 'w') as f: yaml.dump(etcd2_data, f) # Configure calico-upgrade, etcd3 (data destination) etcd3_data = { 'apiVersion': 'projectcalico.org/v3', 'kind': 'CalicoAPIConfig', 'metadata': None, 'spec': { 'datastoreType': 'etcdv3', 'etcdEndpoints': etcd_endpoints, 'etcdKeyFile': ETCD_KEY_PATH, 'etcdCertFile': ETCD_CERT_PATH, 'etcdCACertFile': ETCD_CA_PATH } } with open(ETCD3_DATA_PATH, 'w') as f: yaml.dump(etcd3_data, f)
def install_calico_binaries(): ''' Unpack the Calico binaries. ''' # on intel, the resource is called 'calico'; other arches have a suffix architecture = arch() if architecture == 'amd64': resource_name = 'calico' else: resource_name = 'calico-{}'.format(architecture) try: archive = resource_get(resource_name) except Exception: message = 'Error fetching the calico resource.' log(message) status_set('blocked', message) return if not archive: message = 'Missing calico resource.' log(message) status_set('blocked', message) return filesize = os.stat(archive).st_size if filesize < 1000000: message = 'Incomplete calico resource' log(message) status_set('blocked', message) return status_set('maintenance', 'Unpacking calico resource.') charm_dir = os.getenv('CHARM_DIR') unpack_path = os.path.join(charm_dir, 'files', 'calico') os.makedirs(unpack_path, exist_ok=True) cmd = ['tar', 'xfz', archive, '-C', unpack_path] log(cmd) check_call(cmd) apps = [ {'name': 'calicoctl', 'path': CALICOCTL_PATH}, {'name': 'calico', 'path': '/opt/cni/bin'}, {'name': 'calico-ipam', 'path': '/opt/cni/bin'}, ] for app in apps: unpacked = os.path.join(unpack_path, app['name']) app_path = os.path.join(app['path'], app['name']) install = ['install', '-v', '-D', unpacked, app_path] check_call(install) set_state('calico.binaries.installed')
def install_flannel_binaries(): ''' Unpack the Flannel binaries. ''' # on intel, the resource is called 'flannel'; other arches have a suffix architecture = arch() if architecture == 'amd64': resource_name = 'flannel' else: resource_name = 'flannel-{}'.format(architecture) try: archive = resource_get(resource_name) except Exception: message = 'Error fetching the flannel resource.' log(message) status.blocked(message) return if not archive: message = 'Missing flannel resource.' log(message) status.blocked(message) return filesize = os.stat(archive).st_size if filesize < 1000000: message = 'Incomplete flannel resource' log(message) status.blocked(message) return status.maintenance('Unpacking flannel resource.') charm_dir = os.getenv('CHARM_DIR') unpack_path = os.path.join(charm_dir, 'files', 'flannel') os.makedirs(unpack_path, exist_ok=True) cmd = ['tar', 'xfz', archive, '-C', unpack_path] log(cmd) check_call(cmd) apps = [{ 'name': 'flanneld', 'path': '/usr/local/bin' }, { 'name': 'etcdctl', 'path': '/usr/local/bin' }] for app in apps: unpacked = os.path.join(unpack_path, app['name']) app_path = os.path.join(app['path'], app['name']) install = ['install', '-v', '-D', unpacked, app_path] check_call(install) set_state('flannel.binaries.installed')