def install_vcloud_proxy(): #TODO(lrx):modify the proxy params vdc_info = _read_vdc_info() vcloud_url = vdc_info['vcloud_url'] vcloud_org = vdc_info['vcloud_org'] vcloud_vdc = vdc_info['vcloud_vdc'] username = vdc_info['username'] passwd = vdc_info['passwd'] az = vdc_info['az'] # tunnel_subnet_id = vpc_info["tunnel_subnet_id"] # base_subnet_id = vpc_info["base_subnet_id"] installer = vcloudair.VCA(host=vcloud_url, username=username, service_type='vcd', version='5.5', verify=True) # tunnel_en = aws_util.AWSInterface(tunnel_subnet_id) # base_en = aws_util.AWSInterface(base_subnet_id) proxy_install_conf = _read_install_conf() installer.login(password=passwd, org=vcloud_org) proxy_vm = installer.create_vapp( vcloud_vdc, vapp_name=az, template_name=proxy_install_conf["proxy_image"], catalog_name='share_dir', poweron='true') vcloud_proxy_data_handler.add_new_proxy(proxy_vm.id)
def _subscription_login(self, url, username, password, token, service, org_name): """ login to subscription service """ logined = False vdc_logined = False vca = vcloudair.VCA( url, username, service_type=SUBSCRIPTION_SERVICE_TYPE, version='5.6') # login with token if token: for _ in range(self.LOGIN_RETRY_NUM): logined = vca.login(token=token) if logined is False: ctx.logger.info("Login using token failed.") time.sleep(RELOGIN_TIMEOUT) continue else: ctx.logger.info("Login using token successful.") break # outdated token, try login by password if logined is False and password: for _ in range(self.LOGIN_RETRY_NUM): logined = vca.login(password) if logined is False: ctx.logger.info("Login using password failed. Retrying...") time.sleep(RELOGIN_TIMEOUT) continue else: ctx.logger.info("Login using password successful.") break # can't login to system at all if logined is False: raise cfy_exc.NonRecoverableError("Invalid login credentials") for _ in range(self.LOGIN_RETRY_NUM): vdc_logined = vca.login_to_org(service, org_name) if vdc_logined is False: ctx.logger.info("Login to VDC failed. Retrying...") time.sleep(RELOGIN_TIMEOUT) continue else: ctx.logger.info("Login to VDC successful.") break # we can login to system, # but have some troubles with login to organization, # lets retry later if vdc_logined is False: raise cfy_exc.RecoverableError(message="Could not login to VDC", retry_after=RELOGIN_TIMEOUT) atexit.register(vca.logout) return vca
def __init__(self, cloud_params=None): self.init_params(cloud_params) self._read_env() self._read_install_info() self.installer = vcloudair.VCA(host=self.vcloud_url, username=self.username, service_type='vcd', version='5.5', verify=False)
def _subscription_login(self, url, username, password, token, service, org_name, session_token=None, org_url=None): """ login to subscription service """ version = '5.6' logined = False vdc_logined = False vca = vcloudair.VCA( url, username, service_type=SUBSCRIPTION_SERVICE_TYPE, version=version) if session_token: vca = login_to_vca_with_token(vca, org_url, session_token, version) if vca: return vca else: raise cfy_exc.NonRecoverableError("Invalid session credentials") global local_org_url global local_session_token if local_session_token: vca = login_to_vca_with_token(vca, local_org_url, local_session_token, version) if vca: return vca # login with token if token: logined = login_with_retry(vca.login, [None, token], "Login using token") # outdated token, try login by password if logined is False and password: logined = login_with_retry(vca.login, [password, None], "Login using token") # can't login to system at all if logined is False: raise cfy_exc.NonRecoverableError("Invalid login credentials") vdc_logined = login_with_retry(vca.login_to_org, [service, org_name], "Login to org") # we can login to system, # but have some troubles with login to organization, # lets retry later if vdc_logined: local_session_token = vca.vcloud_session.token local_org_url = vca.vcloud_session.org_url else: raise cfy_exc.RecoverableError(message="Could not login to VDC", retry_after=RELOGIN_TIMEOUT) atexit.register(vca.logout) return vca
def _private_login(self, url, username, password, token, org_name, org_url=None, api_version='5.6'): """ login to private instance """ logined = False vca = vcloudair.VCA(host=url, username=username, service_type=PRIVATE_SERVICE_TYPE, version=api_version) if logined is False and password: for _ in range(LOGIN_RETRY_NUM): logined = vca.login(password, org=org_name) if logined is False: ctx.logger.info("Login using password failed. Retrying...") time.sleep(RELOGIN_TIMEOUT) continue else: token = vca.token # Set org_url based on the session, no matter what was # passed in to the application, as this is guaranteed to # be correct org_url = vca.vcloud_session.org_url ctx.logger.info("Login using password successful.") break # Private mode requires being logged in with a token otherwise you # don't seem to be able to retrieve any VDCs if token: for _ in range(LOGIN_RETRY_NUM): logined = vca.login(token=token, org_url=org_url) if logined is False: ctx.logger.info("Login using token failed.") time.sleep(RELOGIN_TIMEOUT) continue else: ctx.logger.info("Login using token successful.") break if logined is False: raise cfy_exc.NonRecoverableError("Invalid login credentials") atexit.register(vca.logout) return vca
def login(env): vca = vcloudair.VCA(host=env['vcloud_url'], username=env['vcloud_username'], service_type=env['vcloud_service_type'], version="5.7", verify=False) logined = (vca.login(env['vcloud_password']) and vca.login_to_instance( env['vcloud_instance'], env['vcloud_password']) and vca.login_to_instance(env['vcloud_instance'], None, vca.vcloud_session.token, vca.vcloud_session.org_url)) if logined: return vca else: return None
def remove_all_proxys(): #TODO(lrx):get vapp list vdc_info = _read_vdc_info() vcloud_url = vdc_info['vcloud_url'] vcloud_org = vdc_info['vcloud_org'] vcloud_vdc = vdc_info['vcloud_vdc'] username = vdc_info['username'] passwd = vdc_info['passwd'] az = vdc_info['az'] installer = vcloudair.VCA(host=vcloud_url, username=username, service_type='vcd', version='5.5', verify=True) installer.login(password=passwd, org=vcloud_org) #TODO(lrx):change the vapp name proxy_vm_id = installer.get_vapp(vdc=vcloud_vdc, vapp_name='OPenStack-AZ11') proxy_vm_ids = vcloud_proxy_data_handler.get_vcloud_proxy_list() for proxy_vm_id in proxy_vm_ids: installer.terminate_instance(proxy_vm_id)
def __init__(self, cloud_id=None, cloud_params=None, vcloud_url=None, vcloud_org=None, vcloud_vdc=None, vcloud_edgegw=None, username=None, passwd=None, region=None, localmode=True, vcloud_publicip=None): self.cloud_id = cloud_id self.vcloud_url = vcloud_url self.vcloud_org = vcloud_org self.vcloud_vdc = vcloud_vdc self.vcloud_edgegw = vcloud_edgegw self.username = username self.passwd = passwd self.region = region self.cloud_type = None self.localmode = localmode self.vcloud_publicip = vcloud_publicip self.init_params(cloud_params) self._read_env() cloud_subnet = distribute_subnet() self.api_cidr = cloud_subnet["cloud_api"] self.tunnel_cidr = cloud_subnet["cloud_tunnel"] self.local_api_cidr = self.local_api_subnet self.local_tunnel_cidr = self.local_tunnel_subnet self.debug_cidr = None self.base_cidr = None if self.local_vpn_public_gw == self.cascading_eip: self.green_ips = [self.local_vpn_public_gw] else: self.green_ips = [self.local_vpn_public_gw, self.cascading_eip] self.installer = vcloudair.VCA(host=self.vcloud_url, username=self.username, service_type='vcd', version='5.5', verify=False) install_conf = _read_install_conf() #install_conf = {} self.cascaded_image = install_conf["cascaded_image"] self.vpn_image = install_conf["vpn_image"] #vdc network self.api_gw = None, self.api_subnet_cidr = None self.tunnel_gw = None self.tunnel_subnet_cidr = None #cascaded self.public_ip_api_reverse = None self.public_ip_api_forward = None self.public_ip_ntp_server = None self.public_ip_ntp_client = None self.public_ip_cps_web = None self.cascaded_base_ip = None self.cascaded_api_ip = None self.cascaded_tunnel_ip = None #vpn self.public_ip_vpn = None self.vpn_api_ip = None self.vpn_tunnel_ip = None self.ext_net_eips = {} self.all_public_ip = [] self.free_public_ip = [] self._read_vcloud_access_cloud()
def _ondemand_login(self, url, username, password, token, instance_id, session_token=None, org_url=None): """ login to ondemand service """ def get_instance(vca, instance_id): instances = vca.get_instances() or [] for instance in instances: if instance['id'] == instance_id: return instance version = '5.7' if instance_id is None: raise cfy_exc.NonRecoverableError( "Instance ID should be specified for OnDemand login") logined = False instance_logined = False vca = vcloudair.VCA(url, username, service_type=ONDEMAND_SERVICE_TYPE, version=version) if session_token: if session_login(vca, org_url, session_token, version): return vca else: raise cfy_exc.NonRecoverableError( "Invalid session credentials") # login with token if token: for _ in range(LOGIN_RETRY_NUM): logined = vca.login(token=token) if logined is False: ctx.logger.info("Login using token failed.") time.sleep(RELOGIN_TIMEOUT) continue else: ctx.logger.info("Login using token successful.") break # outdated token, try login by password if logined is False and password: for _ in range(LOGIN_RETRY_NUM): logined = vca.login(password) if logined is False: ctx.logger.info("Login using password failed. Retrying...") time.sleep(RELOGIN_TIMEOUT) continue else: ctx.logger.info("Login using password successful.") break # can't login to system at all if logined is False: raise cfy_exc.NonRecoverableError("Invalid login credentials") instance = get_instance(vca, instance_id) if instance is None: raise cfy_exc.NonRecoverableError( "Instance {0} could not be found.".format(instance_id)) for _ in range(LOGIN_RETRY_NUM): instance_logined = vca.login_to_instance(instance_id, password, token, None) if instance_logined is False: ctx.logger.info("Login to instance failed. Retrying...") time.sleep(RELOGIN_TIMEOUT) continue else: ctx.logger.info("Login to instance successful.") break for _ in range(LOGIN_RETRY_NUM): instance_logined = vca.login_to_instance( instance_id, None, vca.vcloud_session.token, vca.vcloud_session.org_url) if instance_logined is False: ctx.logger.info("Login to instance failed. Retrying...") time.sleep(RELOGIN_TIMEOUT) continue else: ctx.logger.info("Login to instance successful.") break # we can login to system, # but have some troubles with login to instance, # lets retry later if instance_logined is False: raise cfy_exc.RecoverableError( message="Could not login to instance", retry_after=RELOGIN_TIMEOUT) atexit.register(vca.logout) return vca
def _ondemand_login(self, url, username, password, token, instance_id, session_token=None, org_url=None): """ login to ondemand service """ def get_instance(vca, instance_id): instances = vca.get_instances() or [] for instance in instances: if instance['id'] == instance_id: return instance version = '5.7' if instance_id is None: raise cfy_exc.NonRecoverableError( "Instance ID should be specified for OnDemand login") logined = False instance_logined = False vca = vcloudair.VCA( url, username, service_type=ONDEMAND_SERVICE_TYPE, version=version) if session_token: vca = login_to_vca_with_token(vca, org_url, session_token, version) if vca: return vca else: raise cfy_exc.NonRecoverableError("Invalid session credentials") global local_org_url global local_session_token if local_session_token: vca = login_to_vca_with_token(vca, local_org_url, local_session_token, version) if vca: return vca # login with token if token: logined = login_with_retry(vca.login, [None, token], "Login using token") # outdated token, try login by password if logined is False and password: logined = login_with_retry(vca.login, [password, None], "Login using password") # can't login to system at all if logined is False: raise cfy_exc.NonRecoverableError("Invalid login credentials") instance = get_instance(vca, instance_id) if instance is None: raise cfy_exc.NonRecoverableError( "Instance {0} could not be found.".format(instance_id)) instance_logined = login_with_retry(vca.login_to_instance, [instance_id, password], "Login to instance with password") if instance_logined: instance_logined = login_with_retry(vca.login_to_instance, [instance_id, None, vca.vcloud_session.token, vca.vcloud_session.org_url], "Login to instance with token") # we can login to system, # but have some troubles with login to instance, # lets retry later if instance_logined: local_session_token = vca.vcloud_session.token local_org_url = vca.vcloud_session.org_url else: raise cfy_exc.RecoverableError( message="Could not login to instance", retry_after=RELOGIN_TIMEOUT) atexit.register(vca.logout) return vca